Fixed missing VC to cleanup in VC Cache

Change-Id: I6c9dc5b11ed2c141ab28ff0f7f59987873d660a5
diff --git a/Changes b/Changes
index ada7f30..6a82798 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,6 @@
-0.60.1 2021-12-13
+0.60.1 2021-12-16
     - [feature] Added vc loading from classpath (margaretha)
-
+    - [cleanup] Fixed missing VC to cleanup in VC Cache (margaretha)
 
 0.60 2021-12-10
     - [feature] Implemented a new cache with on disk
diff --git a/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java b/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
index 792e71e..14f82db 100644
--- a/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
+++ b/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
@@ -33,7 +33,7 @@
 public class VirtualCorpusCache {
 
     public static final String CACHE_LOCATION = "vc-cache";
-    public static final int CAPACITY = 5;
+    public static int CAPACITY = 5;
     public static final Map<String, Map<String, DocBits>> map = Collections
             .synchronizedMap(new LinkedHashMap<String, Map<String, DocBits>>(
                     CAPACITY, (float) 0.75, true) {
@@ -49,7 +49,7 @@
 
     private static IndexInfo indexInfo;
 
-    private static final Set<String> vcToCleanUp = Collections
+    public static final Set<String> vcToCleanUp = Collections
             .synchronizedSet(new HashSet<>());
 
 
@@ -208,7 +208,7 @@
                 .getAllLeafFingerprints();
         Map<String, DocBits> vcData;
         for (String vcId : vcToCleanUp) {
-            vcData = map.get(vcId);
+            vcData = retrieve(vcId);
             vcData.keySet()
                     .removeIf(storedFingerPrint -> currentLeafFingerprints
                             .contains(storedFingerPrint) == false);
diff --git a/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java b/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
index 95bf1c6..2235f2a 100644
--- a/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
+++ b/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
@@ -129,5 +129,22 @@
         assertFalse(VirtualCorpusCache.contains(vcId));
     }
 
-
+    @Test
+    public void testCleanUpVC () throws QueryException, IOException {
+        VirtualCorpusCache.CAPACITY = 3;
+        
+        VirtualCorpusCache.store("named-vc1", ki);
+        VirtualCorpusCache.store("named-vc2", ki);
+        VirtualCorpusCache.store("named-vc3", ki);
+        VirtualCorpusCache.store("named-vc4", ki);
+        
+        assertEquals(3, VirtualCorpusCache.map.size());
+        assertEquals(4, VirtualCorpusCache.vcToCleanUp.size());
+        
+        Krill krill = new Krill(queryRefJson);
+        Result result = krill.apply(ki);
+        assertEquals(27, result.getTotalResults());
+        
+        VirtualCorpusCache.reset();
+    }
 }