Test stability of leaf fingerprints
Change-Id: I77e521f577cdcb5db257b45fc51e40bc5157008e
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java b/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
index 0a07578..b6d38a6 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
@@ -4,11 +4,14 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import java.util.List;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.store.MMapDirectory;
import org.junit.Ignore;
import org.junit.Test;
@@ -128,6 +131,77 @@
ki.close();
};
+ public void testIndexRevisionLeafTempFile () throws IOException {
+
+ String x1, x2, x3;
+
+ Path tmpdir = Files.createTempDirectory("wikileaf");
+ KrillIndex ki = new KrillIndex(new MMapDirectory(tmpdir));
+
+ assertEquals("null", ki.getFingerprint());
+
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
+ ki.commit();
+
+ List<LeafReaderContext> contexts = ki.reader().leaves();
+ assertEquals(1, contexts.size());
+ x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_0(5.0.0):c1", x1);
+
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00003.json.gz"), true);
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00004.json.gz"), true);
+ ki.commit();
+
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00006.json.gz"), true);
+ ki.commit();
+
+ contexts = ki.reader().leaves();
+ assertEquals(3, contexts.size());
+ x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_0(5.0.0):c1", x1);
+ x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_1(5.0.0):c3", x2);
+ x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_2(5.0.0):c1", x3);
+
+ assertTrue(ki.delDocs("title", "A (Band)"));
+ ki.commit();
+
+ assertEquals(false, ki.isReaderOpen());
+
+ contexts = ki.reader().leaves();
+ assertEquals(3, contexts.size());
+ x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_0(5.0.0):c1", x1);
+ x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_1(5.0.0):c3/1:delGen=1", x2);
+ x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_2(5.0.0):c1", x3);
+
+ String fingerp = "241/XHj/9ZxeO5Lm3zZ+iw==";
+ assertEquals(fingerp, ki.getFingerprint());
+
+ ki.close();
+
+ // Reload index
+ ki = new KrillIndex(new MMapDirectory(tmpdir));
+
+ assertEquals(fingerp, ki.getFingerprint());
+
+ contexts = ki.reader().leaves();
+ assertEquals(3, contexts.size());
+ x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_0(5.0.0):c1", x1);
+ x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_1(5.0.0):c3/1:delGen=1", x2);
+ x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
+ assertEquals("_2(5.0.0):c1", x3);
+
+ ki.close();
+ };
+
+
@Ignore
public void testIndexRevisionSample () throws IOException {
KrillIndex ki = new KrillIndex(new MMapDirectory(