Package org.apache.jcs.utils.struct

Examples of org.apache.jcs.utils.struct.LRUMap


    {
        // run the basic tests
        TestSuite suite = new TestSuite( LRUMapConcurrentUnitTest.class );

        // run concurrent tests
        final LRUMap map = new LRUMap( 2000 );
        suite.addTest( new LRUMapConcurrentUnitTest( "conc1" )
        {
            public void runTest()
                throws Exception
            {
                this.runConcurrentPutGetTests( map, 2000 );
            }
        } );
        suite.addTest( new LRUMapConcurrentUnitTest( "conc2" )
        {
            public void runTest()
                throws Exception
            {
                this.runConcurrentPutGetTests( map, 2000 );
            }
        } );
        suite.addTest( new LRUMapConcurrentUnitTest( "conc3" )
        {
            public void runTest()
                throws Exception
            {
                this.runConcurrentPutGetTests( map, 2000 );
            }
        } );

        // run more concurrent tests
        final int max2 = 20000;
        final LRUMap map2 = new LRUMap( max2 );
        suite.addTest( new LRUMapConcurrentUnitTest( "concB1" )
        {
            public void runTest()
                throws Exception
            {
View Full Code Here


     *                Description of the Exception
     */
    public void testSimpleLoad()
        throws Exception
    {
        LRUMap map = new LRUMap( items );

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

        for ( int i = items - 1; i >= 0; i-- )
        {
            String res = (String) map.get( i + ":key" );
            if ( res == null )
            {
                assertNotNull( "[" + i + ":key] should not be null", res );
            }
        }

        // test removal
        map.remove( "300:key" );
        assertNull( map.get( "300:key" ) );

    }
View Full Code Here

     */
    public void testLRURemoval()
        throws Exception
    {
        int total = 10;
        LRUMap map = new LRUMap( total );
        map.setChunkSize( 1 );

        // put the max in
        for ( int i = 0; i < total; i++ )
        {
            map.put( i + ":key", "data" + i );
        }

        Iterator it = map.entrySet().iterator();
        while ( it.hasNext() )
        {
            System.out.println( it.next() );
        }
        System.out.println( map.getStatistics() );

        // get the max out backwards
        for ( int i = total - 1; i >= 0; i-- )
        {
            String res = (String) map.get( i + ":key" );
            if ( res == null )
            {
                assertNotNull( "[" + i + ":key] should not be null", res );
            }
        }

        System.out.println( map.getStatistics() );

        //since we got them backwards the total should be at the end.
        // add one confirm that total is gone.
        map.put( ( total ) + ":key", "data" + ( total ) );
        assertNull( map.get( ( total - 1 ) + ":key" ) );

    }
View Full Code Here

     */
    public void testLRURemovalAgain()
        throws Exception
    {
        int total = 10000;
        LRUMap map = new LRUMap( total );
        map.setChunkSize( 1 );

        // put the max in
        for ( int i = 0; i < total * 2; i++ )
        {
            map.put( i + ":key", "data" + i );
        }

        // get the total number, these shoukld be null
        for ( int i = total - 1; i >= 0; i-- )
        {
            assertNull( map.get( i + ":key" ) );

        }

        // get the total to total *2 items out, these should be foufn.
        for ( int i = ( total * 2 ) - 1; i >= total; i-- )
        {
            String res = (String) map.get( i + ":key" );
            if ( res == null )
            {
                assertNotNull( "[" + i + ":key] should not be null", res );
            }
        }

        System.out.println( map.getStatistics() );

    }
View Full Code Here

     *
     */
    public void testPutWithSizeLimit()
    {
        int size = 10;
        Map cache = new LRUMap( size );

        for ( int i = 0; i < size; i++ )
        {
            cache.put( "key:" + i, "data:" + i );
        }

        for ( int i = 0; i < size; i++ )
        {
            String data = (String)cache.get( "key:" + i );
            assertEquals( "Data is wrong.", "data:" + i, data );
        }
    }
View Full Code Here

     *
     */
    public void testPutWithNoSizeLimit()
    {
        int size = 10;
        Map cache = new LRUMap( );

        for ( int i = 0; i < size; i++ )
        {
            cache.put( "key:" + i, "data:" + i );
        }

        for ( int i = 0; i < size; i++ )
        {
            String data = (String)cache.get( "key:" + i );
            assertEquals( "Data is wrong.", "data:" + i, data );
        }
    }
View Full Code Here

     *
     */
    public void testPutAndRemove()
    {
        int size = 10;
        Map cache = new LRUMap( size );

        cache.put( "key:" + 1, "data:" + 1 );
        String data = (String)cache.remove( "key:" + 1 );
        assertEquals( "Data is wrong.", "data:" + 1, data );
    }
View Full Code Here

     *
     */
    public void testRemoveEmpty()
    {
        int size = 10;
        Map cache = new LRUMap( size );

        Object returned = cache.remove( "key:" + 1 );
        assertNull( "Shouldn't hvae anything.", returned );
    }
View Full Code Here

     *
     */
    public void testGetEntrySet()
    {
        int size = 10;
        Map cache = new LRUMap( size );

        for ( int i = 0; i < size; i++ )
        {
            cache.put( "key:" + i, "data:" + i );
        }

        Set entries = cache.entrySet();
        assertEquals( "Set contains the wrong number of items.", size, entries.size() );

        // check minimal correctness
        Object[] entryArray = entries.toArray();
        for ( int i = 0; i < size; i++ )
View Full Code Here

        String name = "LRUMap";
        String cache2Name = "";

        try
        {
            Map cache = new LRUMap( tries );

            for ( int j = 0; j < loops; j++ )
            {
                name = "JCS      ";
                start = System.currentTimeMillis();
                for ( int i = 0; i < tries; i++ )
                {
                    cache.put( "key:" + i, "data" + i );
                }
                end = System.currentTimeMillis();
                time = end - start;
                putTotalJCS += 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;
                getTotalJCS += time;
                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
View Full Code Here

TOP

Related Classes of org.apache.jcs.utils.struct.LRUMap

Copyright © 2018 www.massapicom. 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.