VanillaChronicle implements Chronicle { public long lastIndex() { int cycle = (int) indexCache.lastCycle(); int lastIndexCount = indexCache.lastIndexFile(cycle, -1); if (lastIndexCount >= 0) { try { final VanillaMappedBytes buffer = indexCache.indexFor(cycle, lastIndexCount, false); final long indices = VanillaIndexCache.countIndices(buffer); buffer.release(); final long indexEntryNumber = (indices > 0) ? indices - 1 : 0; return (((long) cycle) << entriesForCycleBits) + (((long) lastIndexCount) << indexBlockLongsBits) + indexEntryNumber; } catch (IOException e) { throw new AssertionError(e); } } else { return -1; } } VanillaChronicle(String basePath);  VanillaChronicle(String basePath, VanillaChronicleConfig config); @Override String name(); int getEntriesForCycleBits(); long lastIndex(); @NotNull @Override ExcerptTailer createTailer(); @NotNull @Override VanillaAppender createAppender(); @NotNull @Override Excerpt createExcerpt(); @Override long lastWrittenIndex(); @Override long size(); @Override void close(); @Override void clear(); void checkCounts(int min, int max);  }
@Test public void testLastIndex() throws Exception { final String baseDir = getTestPath(); assertNotNull(baseDir); final VanillaChronicleConfig config = new VanillaChronicleConfig(); config.indexBlockSize(64); final VanillaChronicle chronicle = new VanillaChronicle(baseDir, config); chronicle.clear(); try { final ExcerptAppender appender = chronicle.createAppender(); final long index0 = chronicle.lastIndex(); assertEquals(-1, index0); appendValues(appender, 1, 3); final long index1 = chronicle.lastIndex(); assertTrue(index1 > index0); appendValues(appender, 1, 5); final long index2 = chronicle.lastIndex(); assertTrue(index2 > index1); appendValues(appender, 1, 2); final long index3 = chronicle.lastIndex(); assertTrue(index3 > index2); appendValues(appender, 1, 20); final long index4 = chronicle.lastIndex(); assertTrue(index4 > index3); appender.close(); chronicle.checkCounts(1, 1); } finally { chronicle.close(); chronicle.clear(); assertFalse(new File(baseDir).exists()); } }