assertNull( "Should not have value for key [" + i + ":key" + "] in the cache." + cache.getStats(), value ); assertEquals( "myregion" + " data " + i, value ); for ( int i = max-1; i >= 0; i-- ) assertNull( "Should not have value for key [" + i + ":key" + "] in the cache." + cache.getStats(), elements.get( i + ":key" ) ); assertNotNull( "element " + i + ":key is missing", element ); assertEquals( "value " + i + ":key", "myregion" + " data " + i, element.getVal() );
/** * Verify that the mru gets used by a non-defined region when it is set as the default in the * default region. * <p> * @throws CacheException */ public void testLoadFromCCF() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testLoadFromCCF" ); String memoryCacheName = cache.getCacheAttributes().getMemoryCacheName(); assertTrue( "Cache name should have LHMLRU in it.", memoryCacheName.indexOf( "LHMLRUMemoryCache" ) != -1 ); }
assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); assertEquals( "myregion" + " data " + i, value );
/** * put the max and remove each. verify that they are all null. * <p> * @throws CacheException */ public void testPutRemoveThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testPutRemoveThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } for ( int i = 0; i < items; i++ ) { cache.remove( i + ":key" ); } // Test that first items are not in the cache for ( int i = max; i >= 0; i-- ) { String value = cache.get( i + ":key" ); assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); } }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestLHMLRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); LHMLRUMemoryCache<String, String> mru = new LHMLRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); assertEquals( "myregion" + " data " + i, value );
/** * put the max and clear. verify that no elements remain. * <p> * @throws CacheException */ public void testClearThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testClearThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } cache.clear(); // Test that first items are not in the cache for ( int i = max; i >= 0; i-- ) { String value = cache.get( i + ":key" ); assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); } }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestLHMLRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); LHMLRUMemoryCache<String, String> mru = new LHMLRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
assertNull( "Should not have value for key [" + i + ":key" + "] in the cache." + cache.getStats(), value ); assertEquals( "myregion" + " data " + i, value ); for ( int i = max-1; i >= 0; i-- ) assertNull( "Should not have value for key [" + i + ":key" + "] in the cache." + cache.getStats(), elements.get( i + ":key" ) ); assertNotNull( "element " + i + ":key is missing", element ); assertEquals( "value " + i + ":key", "myregion" + " data " + i, element.getVal() );
/** * Verify that the mru gets used by a non-defined region when it is set as the default in the * default region. * <p> * @throws CacheException */ public void testLoadFromCCF() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testLoadFromCCF" ); String memoryCacheName = cache.getCacheAttributes().getMemoryCacheName(); assertTrue( "Cache name should have LHMLRU in it.", memoryCacheName.indexOf( "LHMLRUMemoryCache" ) != -1 ); }
/** * put the max and clear. verify that no elements remain. * <p> * @throws CacheException */ public void testClearThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testClearThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } cache.clear(); // Test that first items are not in the cache for ( int i = max; i >= 0; i-- ) { String value = cache.get( i + ":key" ); assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); } }
assertEquals( "myregion" + " data " + i, value ); assertNull( "Should have been removed by partial loop.", cache.get( root + ":" + i + ":key" ) ); assertNotNull( "Other item should be in the cache.", cache.get( "test" ) );
/** * Get stats. * <p> * @throws CacheException */ public void testGetStatsThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testGetStatsThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } String stats = cache.getStats(); //System.out.println( stats ); // TODO improve stats check assertTrue( "Should have 200 puts" + stats, stats.indexOf( "200" ) != -1 ); }
/** * put the max and remove each. verify that they are all null. * <p> * @throws CacheException */ public void testPutRemoveThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testPutRemoveThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } for ( int i = 0; i < items; i++ ) { cache.remove( i + ":key" ); } // Test that first items are not in the cache for ( int i = max; i >= 0; i-- ) { String value = cache.get( i + ":key" ); assertNull( "Should not have value for key [" + i + ":key" + "] in the cache.", value ); } }
assertEquals( "myregion" + " data " + i, value ); assertNull( "Should have been removed by partial loop.", cache.get( root + ":" + i + ":key" ) ); assertNotNull( "Other item should be in the cache.", cache.get( "test" ) );
/** * Get stats. * <p> * @throws CacheException */ public void testGetStatsThroughHub() throws CacheException { CacheAccess<String, String> cache = JCS.getInstance( "testGetStatsThroughHub" ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max * 2; for ( int i = 0; i < items; i++ ) { cache.put( i + ":key", "myregion" + " data " + i ); } String stats = cache.getStats(); //System.out.println( stats ); // TODO improve stats check assertTrue( "Should have 200 puts" + stats, stats.indexOf( "200" ) != -1 ); }