@Test
public void testIndexFor() throws Exception {

    final String baseDir = getTestPath();
    assertNotNull(baseDir);
    final DateCache dateCache = new DateCache("yyyyMMddHHmmss", 1000);
    final VanillaIndexCache cache = new VanillaIndexCache(baseDir, 10 + 3, dateCache);
    try {
        int cycle = (int) (System.currentTimeMillis() / 1000);
        VanillaMappedBytes vanillaBuffer0 = cache.indexFor(cycle, 0, true);
        vanillaBuffer0.writeLong(0, 0x12345678);
        File file0 = cache.fileFor(cycle, 0, true);
        assertEquals(8 << 10, file0.length());
        assertEquals(0x12345678L, vanillaBuffer0.readLong(0));
        vanillaBuffer0.release();
        VanillaMappedBytes vanillaBuffer1 = cache.indexFor(cycle, 1, true);
        File file1 = cache.fileFor(cycle, 1, true);
        assertEquals(8 << 10, file1.length());
        vanillaBuffer1.release();
        assertNotEquals(file1, file0);
        VanillaMappedBytes vanillaBuffer2 = cache.indexFor(cycle, 2, true);
        File file2 = cache.fileFor(cycle, 2, true);
        assertEquals(8 << 10, file2.length());
        vanillaBuffer2.release();
        assertNotEquals(file2, file0);
        assertNotEquals(file2, file1);
        cache.close();
        assertEquals(0, vanillaBuffer0.refCount());
        assertEquals(0, vanillaBuffer1.refCount());
        assertEquals(0, vanillaBuffer2.refCount());
        // check you can delete after closing.
        assertTrue(file0.delete());
        assertTrue(file1.delete());
        assertTrue(file2.delete());
        assertTrue(file0.getParentFile().delete());
        cache.checkCounts(1, 1);
    } finally {
        cache.close();
        IOTools.deleteDir(baseDir);
        assertFalse(new File(baseDir).exists());
    }
}