Program: 52242
Project: 52242
Buggy source:
@Test public void testIndexFor() throws IOException {
  final String baseDir=getTestPath();
  assertNotNull(baseDir);
  final ChronicleQueueBuilder.VanillaChronicleQueueBuilder builder=ChronicleQueueBuilder.vanilla(baseDir).indexCacheCapacity(32).cleanupOnClose(false);
  final VanillaDateCache dateCache=new VanillaDateCache("String_Node_Str",1000);
  final VanillaIndexCache cache=new VanillaIndexCache(builder,dateCache,10 + 3,FileLifecycleListener.FileLifecycleListeners.CONSOLE);
  try {
    int cycle=(int)(System.currentTimeMillis() / 1000);
    VanillaMappedBytes vanillaBuffer0=cache.indexFor(cycle,0,true);
    vanillaBuffer0.writeLong(0,0x12345678);
    File file0=VanillaChronicleUtils.fileFor(baseDir,cycle,0,dateCache);
    assertEquals(8 << 10,file0.length());
    assertEquals(0x12345678L,vanillaBuffer0.readLong(0));
    vanillaBuffer0.release();
    VanillaMappedBytes vanillaBuffer1=cache.indexFor(cycle,1,true);
    File file1=VanillaChronicleUtils.fileFor(baseDir,cycle,1,dateCache);
    assertEquals(8 << 10,file1.length());
    vanillaBuffer1.release();
    assertNotEquals(file1,file0);
    VanillaMappedBytes vanillaBuffer2=cache.indexFor(cycle,2,true);
    File file2=VanillaChronicleUtils.fileFor(baseDir,cycle,2,dateCache);
    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());
    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());
  }
}

Fixed version (ground truth):
@Test public void testIndexFor() throws IOException {
  final String baseDir=getTestPath();
  assertNotNull(baseDir);
  final ChronicleQueueBuilder.VanillaChronicleQueueBuilder builder=ChronicleQueueBuilder.vanilla(baseDir).indexCacheCapacity(32).cleanupOnClose(false);
  final VanillaDateCache dateCache=new VanillaDateCache("String_Node_Str",1000,GMT);
  final VanillaIndexCache cache=new VanillaIndexCache(builder,dateCache,10 + 3,FileLifecycleListener.FileLifecycleListeners.CONSOLE);
  try {
    int cycle=(int)(System.currentTimeMillis() / 1000);
    VanillaMappedBytes vanillaBuffer0=cache.indexFor(cycle,0,true);
    vanillaBuffer0.writeLong(0,0x12345678);
    File file0=VanillaChronicleUtils.fileFor(baseDir,cycle,0,dateCache);
    assertEquals(8 << 10,file0.length());
    assertEquals(0x12345678L,vanillaBuffer0.readLong(0));
    vanillaBuffer0.release();
    VanillaMappedBytes vanillaBuffer1=cache.indexFor(cycle,1,true);
    File file1=VanillaChronicleUtils.fileFor(baseDir,cycle,1,dateCache);
    assertEquals(8 << 10,file1.length());
    vanillaBuffer1.release();
    assertNotEquals(file1,file0);
    VanillaMappedBytes vanillaBuffer2=cache.indexFor(cycle,2,true);
    File file2=VanillaChronicleUtils.fileFor(baseDir,cycle,2,dateCache);
    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());
    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());
  }
}