Implemented serializable doc bits vector for caching on disk.
Change-Id: I5ffdbe429b68b71d165c3ecf5b7504ac01a9a1ec
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
index 427451d..86c815c 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestVCCaching.java
@@ -1,5 +1,6 @@
package de.ids_mannheim.korap.collection;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -23,7 +24,6 @@
private KrillIndex getSampleIndex () throws IOException {
return new KrillIndex(new MMapDirectory(
Paths.get(getClass().getResource("/sample-index").getFile())));
-
}
private KrillIndex index;
@@ -34,27 +34,36 @@
@Test
public void testCache () throws IOException {
- testAddToCache();
+ testManualAddToCache("named-vc/named-vc1.jsonld", "named-vc1");
+ testManualAddToCache("named-vc/named-vc2.jsonld", "named-vc2");
+
+ Element element = KrillCollection.cache.get("named-vc1");
+ CachedVCData cc = (CachedVCData) element.getObjectValue();
+ assertTrue(cc.getDocIdMap().size() > 0);
+
+ element = KrillCollection.cache.get("named-vc2");
+ cc = (CachedVCData) element.getObjectValue();
+ assertTrue(cc.getDocIdMap().size() > 0);
+
+ assertFalse(KrillCollection.cache.isElementInMemory("named-vc1"));
+ assertTrue(KrillCollection.cache.isElementOnDisk("named-vc1"));
+ assertTrue(KrillCollection.cache.isElementInMemory("named-vc2"));
+ assertTrue(KrillCollection.cache.isElementOnDisk("named-vc2"));
+
testSearchCachedVC();
- testClearCache();
testAddDocToIndex();
testDelDocFromIndex();
}
- private void testAddToCache () throws IOException {
+ private void testManualAddToCache (String filename, String vcName) throws IOException {
InputStream is = getClass().getClassLoader()
- .getResourceAsStream("named-vc/named-vc-free.jsonld");
+ .getResourceAsStream(filename);
String json = IOUtils.toString(is);
is.close();
KrillCollection kc = new KrillCollection(json);
kc.setIndex(index);
- kc.storeInCache();
-
- Element element = KrillCollection.cache.get("cache-goe");
- CachedVCData cc = (CachedVCData) element.getObjectValue();
-
- assertTrue(cc.getDocIdMap().size() > 0);
+ kc.storeInCache(vcName);
}
private void testSearchCachedVC () throws IOException {
@@ -76,12 +85,12 @@
private void testClearCache () {
KrillCollection.cache.removeAll();
- Element element = KrillCollection.cache.get("cache-goe");
+ Element element = KrillCollection.cache.get("named-vc1");
assertNull(element);
}
public void testAddDocToIndex () throws IOException {
- testAddToCache();
+ testManualAddToCache("named-vc/named-vc1.jsonld", "named-vc1");
FieldDocument fd = new FieldDocument();
fd.addTV("base", "x y", "[(0-3)s:x]" + // 1
@@ -90,28 +99,23 @@
index.addDoc(fd);
index.commit();
- Element element = KrillCollection.cache.get("cache-goe");
+ Element element = KrillCollection.cache.get("named-vc1");
assertNull(element);
}
public void testDelDocFromIndex () throws IOException {
- testAddToCache();
+ testManualAddToCache("named-vc/named-vc1.jsonld", "named-vc1");
index.delDocs("textSigle", "GOE/AGF/00000");
index.commit();
- Element element = KrillCollection.cache.get("cache-goe");
+ Element element = KrillCollection.cache.get("named-vc1");
assertNull(element);
}
@Test
public void testAutoCaching () throws IOException {
- InputStream is = getClass().getClassLoader()
- .getResourceAsStream("collection/query-with-vc-ref.jsonld");
- String json = IOUtils.toString(is);
-
- String result = new Krill(json).apply(this.index).toJsonString();
- assertNotNull(result);
- assertTrue(!result.isEmpty());
+ testSearchCachedVC();
+ testClearCache();
}
}
diff --git a/src/test/resources/ehcache.xml b/src/test/resources/ehcache.xml
new file mode 100644
index 0000000..b293534
--- /dev/null
+++ b/src/test/resources/ehcache.xml
@@ -0,0 +1,22 @@
+<ehcache xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"
+ updateCheck="true" monitoring="autodetect" dynamicConfig="true">
+
+ <diskStore path="./krill_cache" />
+
+ <defaultCache
+ maxEntriesLocalHeap="0"
+ eternal="false"
+ timeToIdleSeconds="1200"
+ timeToLiveSeconds="1200">
+ </defaultCache>
+
+ <cache name="named_vc"
+ eternal="true"
+ memoryStoreEvictionPolicy="LRU"
+ maxElementsInMemory="1"
+ maxBytesLocalDisk="1G"
+ diskExpiryThreadIntervalSeconds = "120" >
+ <persistence strategy="localTempSwap"/>
+ </cache>
+
+</ehcache>
\ No newline at end of file
diff --git a/src/test/resources/named-vc/named-vc-free.jsonld b/src/test/resources/named-vc/named-vc1.jsonld
similarity index 76%
rename from src/test/resources/named-vc/named-vc-free.jsonld
rename to src/test/resources/named-vc/named-vc1.jsonld
index 65a6c52..0fddd89 100644
--- a/src/test/resources/named-vc/named-vc-free.jsonld
+++ b/src/test/resources/named-vc/named-vc1.jsonld
@@ -1,9 +1,9 @@
{"collection": {
- "name" : "cache-goe",
+ "name" : "named-vc1",
"@type": "koral:doc",
"key": "textSigle",
"match": "match:ne",
- "type" : "type:string[]",
+ "type" : "type:string",
"value": [
"GOE/AGF/00000",
"GOE/AGA/01784"
diff --git a/src/test/resources/named-vc/named-vc2.jsonld b/src/test/resources/named-vc/named-vc2.jsonld
new file mode 100644
index 0000000..be882a0
--- /dev/null
+++ b/src/test/resources/named-vc/named-vc2.jsonld
@@ -0,0 +1,13 @@
+{"collection": {
+ "name" : "named-vc2",
+ "@type": "koral:doc",
+ "key": "textSigle",
+ "match": "match:eq",
+ "type" : "type:string",
+ "value": [
+ "GOE/AGA/02232",
+ "GOE/AGA/02616",
+ "GOE/AGA/03828"
+ ],
+ "cache" : "true"
+}}