Package org.apache.jcs.engine.memory

Examples of org.apache.jcs.engine.memory.MemoryCacheMockImpl


        }

        cache.dispose();

        // VERIFY
        MemoryCacheMockImpl memoryCache = (MemoryCacheMockImpl) cache.getMemoryCache();
        assertEquals( "Wrong number freed.", numToInsert, memoryCache.lastNumberOfFreedElements );
    }
View Full Code Here


        }

        cache.dispose();

        // VERIFY
        MemoryCacheMockImpl memoryCache = (MemoryCacheMockImpl) cache.getMemoryCache();
        assertEquals( "Wrong number freed.", 0, memoryCache.lastNumberOfFreedElements );
    }
View Full Code Here

     *
     */
    public void testSimpleShrink()
        throws Exception
    {
        MemoryCacheMockImpl memory = new MemoryCacheMockImpl();

        CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes();
        cacheAttr.setMaxMemoryIdleTimeSeconds( 1 );
        cacheAttr.setMaxSpoolPerRun( 10 );

        memory.setCacheAttributes( cacheAttr );

        String key = "key";
        String value = "value";

        ICacheElement element = new CacheElement( "testRegion", key, value );

        ElementAttributes elementAttr = new ElementAttributes();
        elementAttr.setIsEternal( false );
        element.setElementAttributes( elementAttr );
        element.getElementAttributes().setMaxLifeSeconds( 1 );
        memory.update( element );

        ICacheElement returnedElement1 = memory.get( key );
        assertNotNull( "We should have received an element", returnedElement1 );

        // set this to 2 seconds ago.
        elementAttr.lastAccessTime = System.currentTimeMillis() - 2000;

        ShrinkerThread shrinker = new ShrinkerThread( memory );
        Thread runner = new Thread( shrinker );
        runner.run();

        Thread.sleep( 500 );

        ICacheElement returnedElement2 = memory.get( key );
        assertTrue( "Waterfall should have been called.", memory.waterfallCallCount > 0 );
        assertNull( "We not should have received an element.  It should have been spooled.", returnedElement2 );
    }
View Full Code Here

     * @throws Exception
     */
    public void testSimpleShrinkMutiple()
        throws Exception
    {
        MemoryCacheMockImpl memory = new MemoryCacheMockImpl();

        CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes();
        cacheAttr.setMaxMemoryIdleTimeSeconds( 1 );
        cacheAttr.setMaxSpoolPerRun( 3 );

        memory.setCacheAttributes( cacheAttr );

        for ( int i = 0; i < 10; i++ )
        {
            String key = "key" + i;
            String value = "value";

            ICacheElement element = new CacheElement( "testRegion", key, value );

            ElementAttributes elementAttr = new ElementAttributes();
            elementAttr.setIsEternal( false );
            element.setElementAttributes( elementAttr );
            element.getElementAttributes().setMaxLifeSeconds( 1 );
            memory.update( element );

            ICacheElement returnedElement1 = memory.get( key );
            assertNotNull( "We should have received an element", returnedElement1 );

            // set this to 2 seconds ago.
            elementAttr.lastAccessTime = System.currentTimeMillis() - 2000;
        }

        ShrinkerThread shrinker = new ShrinkerThread( memory );
        Thread runner = new Thread( shrinker );
        runner.run();

        Thread.sleep( 500 );

        assertEquals( "Waterfall called the wrong number of times.", 3, memory.waterfallCallCount );

        assertEquals( "Wrong number of elements remain.", 7, memory.getSize() );
    }
View Full Code Here

     * @throws Exception
     */
    public void testSimpleShrinkMutipleWithEventHandler()
    throws Exception
{
    MemoryCacheMockImpl memory = new MemoryCacheMockImpl();

    CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes();
    cacheAttr.setMaxMemoryIdleTimeSeconds( 1 );
    cacheAttr.setMaxSpoolPerRun( 3 );

    memory.setCacheAttributes( cacheAttr );

    ElementEventHandlerMockImpl handler = new ElementEventHandlerMockImpl();

    for ( int i = 0; i < 10; i++ )
    {
        String key = "key" + i;
        String value = "value";

        ICacheElement element = new CacheElement( "testRegion", key, value );

        ElementAttributes elementAttr = new ElementAttributes();
        elementAttr.addElementEventHandler( handler );
        elementAttr.setIsEternal( false );
        element.setElementAttributes( elementAttr );
        element.getElementAttributes().setMaxLifeSeconds( 1 );
        memory.update( element );

        ICacheElement returnedElement1 = memory.get( key );
        assertNotNull( "We should have received an element", returnedElement1 );

        // set this to 2 seconds ago.
        elementAttr.lastAccessTime = System.currentTimeMillis() - 2000;
    }

    ShrinkerThread shrinker = new ShrinkerThread( memory );
    Thread runner = new Thread( shrinker );
    runner.run();

    Thread.sleep( 500 );

    assertEquals( "Waterfall called the wrong number of times.", 3, memory.waterfallCallCount );

    // the shrinker delegates the the composite cache on the memory cache to put the
    // event on the queue.  This make it hard to test.  TODO we need to change this to make it easier to verify.
    //assertEquals( "Event handler ExceededIdleTimeBackground called the wrong number of times.", 3, handler.getExceededIdleTimeBackgroundCount() );

    assertEquals( "Wrong number of elements remain.", 7, memory.getSize() );
}
View Full Code Here

TOP

Related Classes of org.apache.jcs.engine.memory.MemoryCacheMockImpl

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.