@Test public void testPersistence() throws IOException { // can we index a record, close and reopen the database, and find // the same record again afterwards? assertTrue("database claims to be in-memory", !db.isInMemory()); Record record = TestUtils.makeRecord("ID", "1", "NAME", "AND", "EMAIL", "BBBBB"); db.index(record); db.commit(); db.close(); db = createDatabase(config); Record r = db.findRecordById("1"); assertTrue("record not found after reopening", r != null); assertEquals("wrong ID", "1", r.getValue("ID")); assertEquals("wrong NAME", "AND", r.getValue("NAME")); assertEquals("wrong EMAIL", "BBBBB", r.getValue("EMAIL")); Collection<Record> recs = db.findCandidateMatches(record); assertEquals("wrong number of records found", 1, recs.size()); r = recs.iterator().next(); assertEquals("wrong ID", "1", r.getValue("ID")); assertEquals("wrong NAME", "AND", r.getValue("NAME")); assertEquals("wrong EMAIL", "BBBBB", r.getValue("EMAIL")); }
/** * Commits all state to disk and frees up resources. */ public void close() { database.close(); }
db.index(record); db.commit(); db.close();
@Test public void testOverwrite() throws IOException { // can we index a record, close and reopen the database with overwrite // set, and not find it again? assertTrue("database claims to be in-memory", !db.isInMemory()); Record record = TestUtils.makeRecord("ID", "1", "NAME", "AND", "EMAIL", "BBBBB"); db.index(record); db.commit(); db.close(); db = createDatabase(config); db.setOverwrite(true); Record r = db.findRecordById("1"); assertTrue("record found after reopening, despite overwrite", r == null); }