<commit_before>package org.apache.jcs.auxiliary.disk.block;

import java.io.File;
import java.io.Serializable;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.jcs.engine.CacheElement;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.utils.serialization.StandardSerializer;

/** Unit tests for the Block Disk Cache */
public class BlockDiskCacheUnitTest
    extends TestCase
{
    /**
     * Test the basic get matching.
     * <p>
     * @throws Exception
     */
    public void testPutGetMatching_SmallWait()
        throws Exception
    {
        // SETUP
        int items = 200;

        String cacheName = "testPutGetMatching_SmallWait";
        BlockDiskCacheAttributes cattr = new BlockDiskCacheAttributes();
        cattr.setCacheName( cacheName );
        cattr.setMaxKeySize( 100 );
        cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" );
        BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr );

        // DO WORK
        for ( int i = 0; i <= items; i++ )
        {
            diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) );
        }
        Thread.sleep( 500 );

        Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" );

        // VERIFY
        assertEquals( "Wrong number returned", 10, matchingResults.size() );
        //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
        //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
    }

    /**
     * Test the basic get matching. With no wait this will all come from purgatory.
     * <p>
     * @throws Exception
     */
    public void testPutGetMatching_NoWait()
        throws Exception
    {
        // SETUP
        int items = 200;

        String cacheName = "testPutGetMatching_NoWait";
        BlockDiskCacheAttributes cattr = new BlockDiskCacheAttributes();
        cattr.setCacheName( cacheName );
        cattr.setMaxKeySize( 100 );
        cattr.setDiskPath( "target/test-sandbox/BlockDiskCache<String, String>UnitTest" );
        BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr );

        // DO WORK
        for ( int i = 0; i <= items; i++ )
        {
            diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) );
        }

        Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" );

        // VERIFY
        assertEquals( "Wrong number returned", 10, matchingResults.size() );
        //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
        //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
    }<commit_msg>Fixed remains of a search&replace orgy. Fixes JCS-98<commit_after>package org.apache.jcs.auxiliary.disk.block;

import java.io.File;
import java.io.Serializable;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.jcs.engine.CacheElement;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.utils.serialization.StandardSerializer;

/** Unit tests for the Block Disk Cache */
public class BlockDiskCacheUnitTest
    extends TestCase
{
    /**
     * Test the basic get matching.
     * <p>
     * @throws Exception
     */
    public void testPutGetMatching_SmallWait()
        throws Exception
    {
        // SETUP
        int items = 200;

        String cacheName = "testPutGetMatching_SmallWait";
        BlockDiskCacheAttributes cattr = new BlockDiskCacheAttributes();
        cattr.setCacheName( cacheName );
        cattr.setMaxKeySize( 100 );
        cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" );
        BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr );

        // DO WORK
        for ( int i = 0; i <= items; i++ )
        {
            diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) );
        }
        Thread.sleep( 500 );

        Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" );

        // VERIFY
        assertEquals( "Wrong number returned", 10, matchingResults.size() );
        //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
        //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
    }

    /**
     * Test the basic get matching. With no wait this will all come from purgatory.
     * <p>
     * @throws Exception
     */
    public void testPutGetMatching_NoWait()
        throws Exception
    {
        // SETUP
        int items = 200;

        String cacheName = "testPutGetMatching_NoWait";
        BlockDiskCacheAttributes cattr = new BlockDiskCacheAttributes();
        cattr.setCacheName( cacheName );
        cattr.setMaxKeySize( 100 );
        cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" );
        BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr );

        // DO WORK
        for ( int i = 0; i <= items; i++ )
        {
            diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) );
        }

        Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" );

        // VERIFY
        assertEquals( "Wrong number returned", 10, matchingResults.size() );
        //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
        //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
    }
{'fraction_non_alphanumeric': 0.12055370597511827, 'fraction_numerical': 0.009111617312072893, 'mean_word_length': 2.6333545512412475, 'pattern_counts': {'":': 4, '<': 32, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '680826', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1649, 'n_words': 394}