Examples of JCS


Examples of org.apache.jcs.JCS

     *                If an error occurs
     */
    public void runTestForRegionInRange( 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 );
        }

        // Remove all the items
        for ( int i = start; i <= end; i++ )
        {
            jcs.remove( i + ":key" );
        }

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

        // Verify removal
        // another thread may have inserted since
        for ( int i = start; i <= end; i++ )
        {
            assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), 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

     */
    private static void runRealTimeOptimizationTest()
        throws Exception
    {
        JCS.setConfigFilename( "/TestDiskCacheDefragPerformance.ccf" );
        JCS jcs = JCS.getInstance( "defrag" );

        Tile tile;
        System.out.println( "Cache Defrag Test" );

        Random random = new Random( 89 );
        for ( int i = 0; i < TOTAL_ELEMENTS; i++ )
        {
            int bytes = random.nextInt( 20 );
            // 4-24 KB
            tile = new Tile( new Integer( i ), new byte[( bytes + 4 ) * 1024] );
            // images

            jcs.put( tile.id, tile );

            if ( ( i != 0 ) && ( 0 == ( i % 100 ) ) )
            {
                jcs.get( new Integer( random.nextInt( i ) ) );
            }

            if ( 0 == ( i % LOG_INCREMENT ) )
            {
                System.out.print( i + ", " );
                Thread.sleep( SLEEP_TIME_DISK );
            }
        }

        System.out.println( LOG_DIVIDER );
        System.out.println( "Total elements = " + TOTAL_ELEMENTS );
        System.out.println( "Stats prior to sleeping " + jcs.getStats() );

        // Allow system to settle down
        System.out.println( "Sleeping for a a minute." );
        Thread.sleep( 60000 );

        System.out.println( LOG_DIVIDER );
        System.out.println( "Stats prior to dispose " + jcs.getStats() );

        jcs.dispose();
        System.out.println( LOG_DIVIDER );
        System.out.println( "Stats after dispose " + jcs.getStats() );
        System.out.println( "Done testing." );
    }
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 );
            }

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

            // 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 Exception
     */
    public void testUDPDiscoveryConfig()
        throws Exception
    {
        JCS jcs = JCS.getInstance( "testCache1" );

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

        JCS jcs2 = JCS.getInstance( "testCache2" );

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

    }
View Full Code Here

Examples of org.apache.jcs.JCS

        throws Exception
    {
        log.info( "testSimpleSend" );
        System.out.println( "testSimpleSend" );

        JCS cache = JCS.getInstance( "testCache" );

        log.info( "cache = " + cache );

        for ( int i = 0; i < 1000; i++ )
        {
            System.out.println( "puttting " + i );
            cache.put( "key" + i, "data" + i );
            System.out.println( "put " + i );
            log.info( "put " + i );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

        System.out.println( "--------------------------" );
        long initialMemory = measureMemoryUse();
        System.out.println( "Before getting JCS: " + initialMemory );

        JCS jcs = JCS.getInstance( region );
        jcs.clear();

        try
        {
            ElapsedTimer timer = new ElapsedTimer();
            System.out.println( "Start: " + measureMemoryUse() );

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

            System.out.println( jcs.getStats() );
            System.out.println( "--------------------------" );
            System.out.println( "After put: " + measureMemoryUse() );

            Thread.sleep( 5000 );

            System.out.println( jcs.getStats() );
            System.out.println( "--------------------------" );
            System.out.println( "After wait: " + measureMemoryUse() );

            for ( int i = 0; i < 10; i++ )
            {
                SleepUtil.sleepAtLeast( 3000 );
                System.out.println( "--------------------------" );
                System.out.println( "After sleep. " + timer.getElapsedTimeString() + " memory used = " + measureMemoryUse() );
                System.out.println( jcs.getStats() );
            }

            // Test that all items are in cache
            System.out.println( "--------------------------" );
            System.out.println( "Retrieving all." );
            for ( int i = 0; i <= items; i++ )
            {
                //System.out.print(  "\033[s" );
                String value = (String) jcs.get( i + ":key" );
                if( i % 1000 == 0 )
                {
                    //System.out.print(  "\033[r" );
                    System.out.printlni + " ");
                }
                assertEquals( "Wrong value returned.", region + " data " + i, value );
            }
            long aftetGet = measureMemoryUse();
            System.out.println( "After get: " + aftetGet + " diff = " + (aftetGet - initialMemory));

        }
        finally
        {
            // dump the stats to the report
            System.out.println( jcs.getStats() );
            System.out.println( "--------------------------" );
            long endMemory = measureMemoryUse();
            System.out.println( "End: " + endMemory + " diff = " + (endMemory - initialMemory) );
        }
    }
View Full Code Here

Examples of org.apache.jcs.JCS

     *                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 );
        }

        // Test that all items are in cache

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

            assertEquals( 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" + "\n stats " + jcs.getStats(), jcs.get( i + ":key" ) );
        }

        // dump the stats to the report
        System.out.println( jcs.getStats() );
    }
View Full Code Here

Examples of org.apache.jcs.JCS

     * @throws CacheException
     */
    public void testLoadFromCCF()
        throws CacheException
    {
        JCS cache = JCS.getInstance( "testPutGet" );
        String memoryCacheName = cache.getCacheAttributes().getMemoryCacheName();
        assertTrue( "Cache name should have MRU in it.", memoryCacheName.indexOf( "MRUMemoryCache" ) != -1 );
    }
View Full Code Here

Examples of org.apache.jcs.JCS

        String keyPart1 = "part1";
        String keyPart2 = "part2";
        String region = "testCache1";
        String data = "adfadsfasfddsafasasd";

        JCS jcs = JCS.getInstance( region );

        // DO WORK
        jcs.put( keyPart1 + ":" + keyPart2, data );
        Thread.sleep( 1000 );

        // VERIFY
        String resultBeforeRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
        assertEquals( "Wrong result", data, resultBeforeRemove );

        jcs.remove( keyPart1 + ":" );
        String resultAfterRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
        assertNull( "Should not have a result after removal.", resultAfterRemove );

        System.out.println( jcs.getStats() );
    }
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.