    @Test
    public void testFindNextDataCount() throws Exception {

        final String baseDir = getTestPath();
        assertNotNull(baseDir);

        try {
            final DateCache dateCache = new DateCache("yyyyMMddHHmmss", 1000);
            final VanillaDataCache cache = new VanillaDataCache(baseDir, 10 + 6, dateCache);

            int cycle = (int) (System.currentTimeMillis() / 1000);
            final int threadId = AffinitySupport.getThreadId();

            // Check that the data file count starts at 0 when the data directory is empty
            assertEquals(0, cache.findNextDataCount(cycle, threadId));

            // Add some more data files into the directory - use discontinuous numbers to test reading
            VanillaMappedBytes vanillaBuffer1 = cache.dataFor(cycle, threadId, 1, true);
            vanillaBuffer1.release();

            VanillaMappedBytes vanillaBuffer2 = cache.dataFor(cycle, threadId, 2, true);
            vanillaBuffer2.release();

            VanillaMappedBytes vanillaBuffer4 = cache.dataFor(cycle, threadId, 4, true);
            vanillaBuffer4.release();

            cache.checkCounts(1, 1);
            cache.close();

            // Open a new cache and check that it reads the existing data files that were created above
            final VanillaDataCache cache2 = new VanillaDataCache(baseDir, 10 + 6, dateCache);

            assertEquals(5, cache2.findNextDataCount(cycle, threadId));

            cache.checkCounts(1, 1);
            cache2.close();
        } finally {
            IOTools.deleteDir(baseDir);
            assertFalse(new File(baseDir).exists());
        }
    }