Examples of JCS


Examples of org.apache.jcs.JCS

    public void testSpoolNotAllowedEventOnItem()
        throws Exception
    {
        MyEventHandler meh = new MyEventHandler();

        JCS jcs = JCS.getInstance( "DiskButNotAllowed" );
        // this should add the event handler to all items as they are created.
        //IElementAttributes attributes = jcs.getDefaultElementAttributes();
        //attributes.addElementEventHandler( meh );
        //jcs.setDefaultElementAttributes( attributes );

        // put them in
        for ( int i = 0; i <= items; i++ )
        {
            IElementAttributes attributes = jcs.getDefaultElementAttributes();
            attributes.addElementEventHandler( meh );
            jcs.put( i + ":key", "data" + i, attributes );
        }

        // wait a bit for it to finish
        Thread.sleep( items / 20 );
View Full Code Here

Examples of org.apache.jcs.JCS

     * @exception Exception If an error occurs
     */
    public void runTestForRegion( String region )
        throws Exception
    {
        JCS jcs = JCS.getInstance( region );

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        System.out.println( jcs.getStats() );

        // Thread.sleep( 1000 );

        // System.out.println( jcs.getStats() );

        // Test that all items are in cache

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
        }

        // Remove all the items

        for ( int i = 0; i <= items; i++ )
        {
            jcs.remove( i + ":key" );
        }

        // Verify removal

        for ( int i = 0; i <= items; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

    {
        int items = 20;

        String region = "testBasicPutRemove";

        JCS jcs = JCS.getInstance( region );

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        //SleepUtil.sleepAtLeast( 1000 );

        System.out.println( jcs.getStats() );

        // Test that all items are in cache

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
        }

        // Remove all the items

        for ( int i = 0; i <= items; i++ )
        {
            jcs.remove( i + ":key" );
        }

        // Verify removal

        for ( int i = 0; i <= items; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

     *                If an error occurs
     */
    public void runTestForRegion( String region, int start, int end )
        throws Exception
    {
        JCS jcs = JCS.getInstance( region );

        // Add items to cache

        for ( int i = start; i <= end; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        // Test that all items are in cache

        for ( int i = start; i <= end; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( region + " data " + i, value );
        }

        /*
 
View Full Code Here

Examples of org.apache.jcs.JCS

     */
    public void testRemoveAll()
        throws CacheException, InterruptedException
    {
        String region = "removeAllAllowed";
        JCS jcs = JCS.getInstance( region );

        int items = 20;

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        // a db thread could be updating when we call remove all?
        // there was a race on remove all, an element may be put to disk after it is called even
        // though the put
        // was called before clear.
        // I discovered it and removed it.
        // Thread.sleep( 500 );

        System.out.println( jcs.getStats() );

        jcs.clear();

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertNull( "value should be null key = [" + i + ":key] value = [" + value + "]", value );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

     */
    public void testRemoveAllProhibition()
        throws CacheException, InterruptedException
    {
        String region = "noRemoveAll";
        JCS jcs = JCS.getInstance( region );

        int items = 20;

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        // a db thread could be updating the disk when
        // Thread.sleep( 500 );

        System.out.println( jcs.getStats() );

        jcs.clear();

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

        long pauseBetweenRuns = 1000;
        int runCount = 0;
        int runs = 1000;
        int upperKB = 50;

        JCS jcs = JCS.getInstance( ( numPerRun / 2 ) + "aSecond" );

        ElapsedTimer timer = new ElapsedTimer();
        int numToGet = numPerRun * ( runs / 10 );
        for ( int i = 0; i < numToGet; i++ )
        {
            jcs.get( String.valueOf( i ) );
        }
        System.out.println( LOG_DIVIDER );
        System.out.println( "After getting " + numToGet );
        System.out.println( "Elapsed " + timer.getElapsedTimeString() );
        logMemoryUsage();

        jcs.clear();
        Thread.sleep( 3000 );
        System.out.println( LOG_DIVIDER );
        System.out.println( "Start putting" );

        long totalSize = 0;
        int totalPut = 0;

        Random random = new Random( 89 );
        while ( runCount < runs )
        {
            runCount++;
            for ( int i = 0; i < numPerRun; i++ )
            {
                // 1/2 upper to upperKB-4 KB
                int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
                int bytes = ( kiloBytes ) * 1024;
                totalSize += bytes;
                totalPut++;
                DiskTestObject object = new DiskTestObject( new Integer( i ), new byte[bytes] );
                jcs.put( String.valueOf( totalPut ), object );
            }

            // remove half of those inserted the previous run
            if ( runCount > 1 )
            {
                for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
                {
                    jcs.remove( String.valueOf( j ) );
                }
            }

            Thread.sleep( pauseBetweenRuns );
            if ( runCount % 1 == 0 )
            {
                System.out.println( LOG_DIVIDER );
                System.out.println( "Elapsed " + timer.getElapsedTimeString() );
                System.out.println( "Run count: " + runCount + " Average size: " + ( totalSize / totalPut ) + "\n"
                    + jcs.getStats() );
                logMemoryUsage();
            }
        }

        Thread.sleep( 3000 );
        System.out.println( jcs.getStats() );
        logMemoryUsage();

        Thread.sleep( 10000 );
        System.out.println( jcs.getStats() );
        logMemoryUsage();

        System.gc();
        Thread.sleep( 3000 );
        System.gc();
        System.out.println( jcs.getStats() );
        logMemoryUsage();
    }
View Full Code Here

Examples of org.apache.jcs.JCS

        throws CacheException, InterruptedException
    {
        String region = "eternal";
        int items = 200;

        JCS jcs = JCS.getInstance( region );

        System.out.println( "BEFORE PUT \n" + jcs.getStats() );

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        System.out.println( jcs.getStats() );

        SleepUtil.sleepAtLeast( 1000 );

        System.out.println( jcs.getStats() );

        // Test that all items are in cache

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
        }

        // Remove all the items

        for ( int i = 0; i <= items; i++ )
        {
            jcs.remove( i + ":key" );
        }

        // Verify removal

        for ( int i = 0; i <= items; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

     *                If an error occurs
     */
    public void runTestForRegion( String region, int items )
        throws Exception
    {
        JCS jcs = JCS.getInstance( region );

        System.out.println( "BEFORE PUT \n" + jcs.getStats() );

        // Add items to cache

        for ( int i = 0; i <= items; i++ )
        {
            jcs.put( i + ":key", region + " data " + i );
        }

        System.out.println( jcs.getStats() );

        Thread.sleep( 1000 );

        System.out.println( jcs.getStats() );

        // Test that all items are in cache

        for ( int i = 0; i <= items; i++ )
        {
            String value = (String) jcs.get( i + ":key" );

            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
        }

        // Remove all the items

        for ( int i = 0; i <= items; i++ )
        {
            jcs.remove( i + ":key" );
        }

        // Verify removal

        for ( int i = 0; i <= items; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

        try
        {

            JCS.setConfigFilename( "/TestMRUCache.ccf" );
            JCS cache = JCS.getInstance( "lruDefined" );
            JCS mru = JCS.getInstance( "mruDefined" );

            System.out.println( "LRU = " + cache );

            for ( int j = 0; j < loops; j++ )
            {

                System.out.println( "Beginning loop " + j );

                String name = "LRU      ";
                start = System.currentTimeMillis();
                for ( int i = 0; i < tries; i++ )
                {
                    cache.put( "key:" + i, "data" + i );
                }
                end = System.currentTimeMillis();
                time = end - start;
                putTotalLRU += time;
                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
                System.out.println( name + " put time for " + tries + " = " + time + "; millis per = " + tPer );

                start = System.currentTimeMillis();
                for ( int i = 0; i < tries; i++ )
                {
                    cache.get( "key:" + i );
                }
                end = System.currentTimeMillis();
                time = end - start;
                getTotalLRU += time;
                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
                System.out.println( name + " get time for " + tries + " = " + time + "; millis per = " + tPer );

                // /////////////////////////////////////////////////////////////
                name = "MRU";
                start = System.currentTimeMillis();
                for ( int i = 0; i < tries; i++ )
                {
                    mru.put( "key:" + i, "data" + i );
                }
                end = System.currentTimeMillis();
                time = end - start;
                putTotalMRU += time;
                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
                System.out.println( name + " put time for " + tries + " = " + time + "; millis per = " + tPer );

                start = System.currentTimeMillis();
                for ( int i = 0; i < tries; i++ )
                {
                    mru.get( "key:" + i );
                }
                end = System.currentTimeMillis();
                time = end - start;
                getTotalMRU += time;
                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.