@Test
public void testLastIndexFile() throws Exception {

    final String baseDir = getTestPath();
    assertNotNull(baseDir);
    final DateCache dateCache = new DateCache("yyyyMMddHHmmss", 1000);
    final VanillaIndexCache cache = new VanillaIndexCache(baseDir, 10 + 3, dateCache);
    final int cycle = (int) (System.currentTimeMillis() / 1000);
    try {
        // Check that the index file count starts at 0 when the data directory is empty
        assertEquals(0, cache.lastIndexFile(cycle));
        final VanillaMappedBytes vanillaBuffer0 = cache.indexFor(cycle, 0, true);
        assertEquals("index-0", cache.fileFor(cycle, 0, true).getName());
        vanillaBuffer0.release();
        assertEquals(0, cache.lastIndexFile(cycle));
        final VanillaMappedBytes vanillaBuffer1 = cache.indexFor(cycle, 1, true);
        assertEquals("index-1", cache.fileFor(cycle, 1, true).getName());
        vanillaBuffer1.release();
        assertEquals(1, cache.lastIndexFile(cycle));
        final VanillaMappedBytes vanillaBuffer3 = cache.indexFor(cycle, 3, true);
        assertEquals("index-3", cache.fileFor(cycle, 3, true).getName());
        vanillaBuffer3.release();
        assertEquals(3, cache.lastIndexFile(cycle));
        cache.checkCounts(1, 1);
    } finally {
        cache.close();
        IOTools.deleteDir(baseDir);
        assertFalse(new File(baseDir).exists());
    }
}