/** * Dump the cache entries from first to last for debugging. */ public void dumpCacheEntries() { dumpMap(); }
/** * Puts an item to the cache. Removes any pre-existing entries of the same key from the linked * list and adds this one first. * <p> * @param ce The cache element, or entry wrapper * @return MemoryElementDescriptor the new node * @throws IOException */ @Override protected MemoryElementDescriptor<K, V> adjustListForUpdate( ICacheElement<K, V> ce ) throws IOException { return addFirst( ce ); }
/** * Returns a synchronized LHMSpooler * <p> * @return Collections.synchronizedMap( new LHMSpooler() ) */ @Override public Map<K, MemoryElementDescriptor<K, V>> createMap() { return Collections.synchronizedMap( new LHMSpooler() ); }
/** * 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() ); }
/** * 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 ); } }
@Override public void runTest() throws Exception { this.runTestForRegion( "testRegion1" ); } } );
@Override public void runTest() throws Exception { this.runTestForRegion( "indexedRegion1" ); } } );
/** * For post reflection creation initialization * <p> * @param hub */ @Override public void initialize( CompositeCache<K, V> hub ) { super.initialize( hub ); log.info( "initialized LHMLRUMemoryCache for " + getCacheName() ); }
/** * 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() ); }
/** * 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 ); } }
@Override public void runTest() throws Exception { this.runTestForRegion( "testRegion1" ); } } );
@Override public void runTest() throws Exception { this.runTestForRegion( "indexedRegion1" ); } } );
/** * Dump the cache entries from first to last for debugging. */ public void dumpCacheEntries() { dumpMap(); }
/** * Puts an item to the cache. Removes any pre-existing entries of the same key from the linked * list and adds this one first. * <p> * @param ce The cache element, or entry wrapper * @return MemoryElementDescriptor the new node * @throws IOException */ @Override protected MemoryElementDescriptor<K, V> adjustListForUpdate( ICacheElement<K, V> ce ) throws IOException { return addFirst( ce ); }
/** * Returns a synchronized LHMSpooler * <p> * @return Collections.synchronizedMap( new LHMSpooler() ) */ @Override public Map<K, MemoryElementDescriptor<K, V>> createMap() { return Collections.synchronizedMap( new LHMSpooler() ); }
/** * 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 ); } }
/** * 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 ); }