Package org.apache.jcs.engine.behavior

Examples of org.apache.jcs.engine.behavior.ICacheElement


        int cnt = 999;
        for ( int i = 0; i < cnt; i++ )
        {
            IElementAttributes eAttr = new ElementAttributes();
            eAttr.setIsSpool( true );
            ICacheElement element = new CacheElement( "testSimplePutAndGet", "key:" + i, "data:" + i );
            element.setElementAttributes( eAttr );
            disk.doUpdate( element );
        }

        for ( int i = 0; i < cnt; i++ )
        {
            ICacheElement element = disk.doGet( "key:" + i );
            assertNotNull( "Should have recevied an element.", element );
            assertEquals( "Element is wrong.", "data:" + i, element.getVal() );
        }

        System.out.println( disk.getStats() );
    }
View Full Code Here


        int cnt = 25;
        for ( int i = 0; i < cnt; i++ )
        {
            IElementAttributes eAttr = new ElementAttributes();
            eAttr.setIsSpool( true );
            ICacheElement element = new CacheElement( "testRemoveItems", "key:" + i, "data:" + i );
            element.setElementAttributes( eAttr );
            disk.doUpdate( element );
        }

        // remove each
        for ( int i = 0; i < cnt; i++ )
        {
            disk.remove( "key:" + i );
            ICacheElement element = disk.doGet( "key:" + i );
            assertNull( "Should not have recevied an element.", element );
        }
    }
View Full Code Here

        System.out.println( "------------------------- testRecycleBin " );

        for ( int i = 0; i < 6; i++ )
        {
            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
            disk.doUpdate( element );
        }

        for ( int i = 3; i < 5; i++ )
        {
            System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
            disk.remove( "key:" + test[i] );
        }

        // there was a bug where 7 would try to be put in the empty slot left by 4's removal, but it
        // will not fit.
        for ( int i = 7; i < 9; i++ )
        {
            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
            disk.doUpdate( element );
        }

        try
        {
            for ( int i = 0; i < 9; i++ )
            {
                ICacheElement element = disk.get( "key:" + test[i] );
                if ( element != null )
                {
                    System.out.println( "element = " + element.getVal() );
                }
                else
                {
                    System.out.println( "null --" + "key:" + test[i] );
                }

                String expectedValue = expect[i];
                if ( expectedValue == null )
                {
                    assertNull( "Expected a null element", element );
                }
                else
                {
                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should not be null. i = " + i,
                                   element );
                    assertEquals( "Elements contents do not match expected", element.getVal(), expectedValue );
                }
            }
        }
        catch ( Exception e )
        {
View Full Code Here

        int cnt = 25;
        for ( int i = 0; i < cnt; i++ )
        {
            IElementAttributes eAttr = new ElementAttributes();
            eAttr.setIsSpool( true );
            ICacheElement element = new CacheElement( "testRemove_PartialKey", i + ":key", "data:" + i );
            element.setElementAttributes( eAttr );
            disk.doUpdate( element );
        }

        // verif each
        for ( int i = 0; i < cnt; i++ )
        {
            ICacheElement element = disk.doGet( i + ":key" );
            assertNotNull( "Shoulds have recevied an element.", element );
        }

        // remove each
        for ( int i = 0; i < cnt; i++ )
        {
            disk.remove( i + ":" );
            ICacheElement element = disk.doGet( i + ":key" );
            assertNull( "Should not have recevied an element.", element );
        }
    }
View Full Code Here

        String regionName = "testSinglePut";
        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );

        // DO WORK
        int numPutsPrior = server.getPutCount();
        ICacheElement element = new CacheElement( regionName, "key", "value" );
        cache.update( element );
        SleepUtil.sleepAtLeast( 50 );

        // VERIFY
        System.out.println( server.getStats() );
        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );

        // DO WORK
        ICacheElement result = cache.get( "key" );

        // VERIFY
        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
    }
View Full Code Here

        // verify each
        for ( int i = 0; i < cnt; i++ )
        {
            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
            ICacheElement element = disk.doGet( groupAttrName );
            assertNotNull( "Should have recevied an element.", element );
        }

        // DO WORK
        // remove the group
        GroupId gid = new GroupId( cacheName, groupName );
        disk.remove( gid );

        for ( int i = 0; i < cnt; i++ )
        {
            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
            ICacheElement element = disk.doGet( groupAttrName );

            // VERIFY
            assertNull( "Should not have recevied an element.", element );
        }
View Full Code Here

        String regionName = "testPutRemove";
        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );

        // DO WORK
        int numPutsPrior = server.getPutCount();
        ICacheElement element = new CacheElement( regionName, "key", "value" );
        cache.update( element );
        SleepUtil.sleepAtLeast( 50 );

        // VERIFY
        System.out.println( server.getStats() );
        assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior );

        // DO WORK
        ICacheElement result = cache.get( "key" );

        // VERIFY
        assertEquals( "Wrong element.", element.getVal(), result.getVal() );

        // DO WORK
        cache.remove( "key" );
        SleepUtil.sleepAtLeast( 50 );
        ICacheElement resultAfterRemote = cache.get( "key" );

        // VERIFY
        assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
    }
View Full Code Here

        RemoteCacheListenerMockImpl listener = new RemoteCacheListenerMockImpl();
        server.addCacheListener( regionName, listener );

        // DO WORK
        int numPutsPrior = server.getPutCount();
        ICacheElement element = new CacheElement( regionName, "key", "value" );
        cache.update( element );
        SleepUtil.sleepAtLeast( 50 );

        // VERIFY
        try
View Full Code Here

        // DO WORK
        int numPutsPrior = server.getPutCount();
        int numToPut = 100;
        for ( int i = 0; i < numToPut; i++ )
        {
            ICacheElement element = new CacheElement( regionName, "key" + 1, "value" + i );
            cache.update( element );
        }
        SleepUtil.sleepAtLeast( 500 );

        // VERIFY
View Full Code Here

     * @throws IOException
     */
    public ICacheElement get( Serializable key )
        throws IOException
    {
        ICacheElement obj = null;

        if ( this.cattr.getPutOnlyMode() )
        {
            return null;
        }
View Full Code Here

TOP

Related Classes of org.apache.jcs.engine.behavior.ICacheElement

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.