Test index fingerprint with reload

Change-Id: Ia9de13d5b9f585e471668472921640eda819949e
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 2128d4f..0a07578 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestIndexRevision.java
@@ -1,25 +1,19 @@
 package de.ids_mannheim.korap.index;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.spans.SpanQuery;
-import org.apache.lucene.search.spans.SpanTermQuery;
-import org.junit.Test;
-import org.junit.Ignore;
-
-import de.ids_mannheim.korap.Krill;
-import de.ids_mannheim.korap.KrillIndex;
-import de.ids_mannheim.korap.KrillMeta;
-import de.ids_mannheim.korap.response.Result;
-import de.ids_mannheim.korap.util.StatusCodes;
-
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
+
 import org.apache.lucene.store.MMapDirectory;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import de.ids_mannheim.korap.KrillIndex;
 
 public class TestIndexRevision {
 
@@ -33,7 +27,7 @@
         ki.commit();
 
         String x1 = ki.getFingerprint();
-        assertEquals(x1,"ibtSULzKIMrfGAtES3GXRA==");
+        assertEquals("ibtSULzKIMrfGAtES3GXRA==",x1);
 
         ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
         ki.addDoc(getClass().getResourceAsStream("/wiki/00003.json.gz"), true);
@@ -41,36 +35,36 @@
         ki.commit();
 
         String x2 = ki.getFingerprint();
-        assertEquals(x2,"0UIQZpZVfiGDD2leAq6YQA==");
+        assertEquals("0UIQZpZVfiGDD2leAq6YQA==",x2);
 
         ki.addDoc(getClass().getResourceAsStream("/wiki/00006.json.gz"), true);
         ki.commit();
 
         String x3 = ki.getFingerprint();
-        assertEquals(x3,"fS3GqnKynhPQ5wFyC9/XWw==");
+        assertEquals("fS3GqnKynhPQ5wFyC9/XWw==",x3);
 
 
         // Check if the same changes will have the same effect
         KrillIndex ki2 = new KrillIndex();
 
-        assertEquals(ki2.getFingerprint(),"null");
+        assertEquals("null",ki2.getFingerprint());
         
         ki2.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
         ki2.commit();
 
-        assertEquals(ki2.getFingerprint(), x1);
+        assertEquals(x1, ki2.getFingerprint());
 
         ki2.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
         ki2.addDoc(getClass().getResourceAsStream("/wiki/00003.json.gz"), true);
         ki2.addDoc(getClass().getResourceAsStream("/wiki/00004.json.gz"), true);
         ki2.commit();
 
-        assertEquals(ki2.getFingerprint(), x2);
+        assertEquals(x2, ki2.getFingerprint());
 
         ki2.addDoc(getClass().getResourceAsStream("/wiki/00006.json.gz"), true);
         ki2.commit();
 
-        assertEquals(ki2.getFingerprint(), x3);
+        assertEquals(x3, ki2.getFingerprint());
     };
 
     @Test
@@ -83,21 +77,62 @@
         ki.commit();
 
         String x1 = ki.getFingerprint();
-        assertEquals(x1,"ibtSULzKIMrfGAtES3GXRA==");
+        assertEquals("ibtSULzKIMrfGAtES3GXRA==",x1);
 
         assertTrue(ki.delDocs("title", "A"));
         ki.commit();
 
         String x2 = ki.getFingerprint();
         assertNotEquals(x1, x2);
-
     };
 
+    @Test
+    public void testIndexRevisionTempFile () throws IOException {
+
+        Path tmpdir = Files.createTempDirectory("wiki");
+        KrillIndex ki = new KrillIndex(new MMapDirectory(tmpdir));
+
+        assertEquals("null", ki.getFingerprint());
+        
+        ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
+        ki.commit();
+
+        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();
+
+        assertTrue(ki.delDocs("title", "A"));
+        ki.commit();
+
+        assertEquals(false, ki.isReaderOpen());
+
+        String fingerp = "aoD2zQvZKa8oQPjFJlji1g==";
+        assertEquals(fingerp, ki.getFingerprint());
+
+        assertEquals(true, ki.isReaderOpen());
+        assertEquals(4, ki.numberOf("base", "documents"));
+
+        assertEquals(fingerp, ki.getFingerprint());
+
+        ki.close();
+
+        // Reload index
+        ki = new KrillIndex(new MMapDirectory(tmpdir));
+
+        assertEquals(fingerp, ki.getFingerprint());
+
+        ki.close();
+    };
+    
     @Ignore
     public void testIndexRevisionSample () throws IOException {
         KrillIndex ki = new KrillIndex(new MMapDirectory(
                 Paths.get(getClass().getResource("/sample-index").getFile())));
 
-        assertEquals(ki.getFingerprint(),"Wes8Bd4h1OypPqbWF5njeQ==");
+        assertEquals("Wes8Bd4h1OypPqbWF5njeQ==",ki.getFingerprint());
     };
 };