/** * This should count the size of the array. * * @throws Exception */ public void testByteArray() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); byte[] array = new byte[]{1,2,3,4,5}; out.write( array ); assertEquals( "Wrong number of bytes written.", array.length, out.getCount() ); out.close(); }
/** * @return string info on the item */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\nCacheElementInfo " ); buf.append( "\n Key [" ).append( getKey() ).append( "]" ); buf.append( "\n Eternal [" ).append( isEternal() ).append( "]" ); buf.append( "\n CreateTime [" ).append( getCreateTime() ).append( "]" ); buf.append( "\n MaxLifeSeconds [" ).append( getMaxLifeSeconds() ).append( "]" ); buf.append( "\n ExpiresInSeconds [" ).append( getExpiresInSeconds() ).append( "]" ); return buf.toString(); } }
/** * Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in * the region or an error occurs, suppresses exceptions and returns 0. * <p> * * @return int The size of the region in bytes. */ @Override public int getByteCount(String cacheName) { return getByteCount(cacheHub.getCache(cacheName)); }
/** * Remove an item via the remove method. * * @throws Exception */ public void testRemove() throws Exception { JCSAdminBean admin = new JCSAdminBean(); String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); // clear the region cache.clear(); admin.clearRegion( regionName ); String key = "myKey"; cache.put( key, "value" ); CacheElementInfo[] elements = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region.", 1, elements.length ); CacheElementInfo elementInfo = elements[0]; assertEquals( "Wrong key.", key, elementInfo.getKey() ); admin.removeItem( regionName, key ); CacheElementInfo[] elements2 = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length ); }
/** * Create a test region and then verify that we get it from the list. * * @throws Exception * */ public void testGetRegionInfo() throws Exception { String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); cache.put( "key", "value" ); JCSAdminBean admin = new JCSAdminBean(); CacheRegionInfo[] regions = admin.buildCacheInfo(); boolean foundRegion = false; for (CacheRegionInfo info : regions) { if ( info.getCacheName().equals( regionName ) ) { foundRegion = true; assertTrue( "Byte count should be greater than 5.", info.getByteCount() > 5 ); assertNotNull( "Should have stats.", info.getCacheStatistics() ); } } assertTrue( "Should have found the region we just created.", foundRegion ); }
/** * Put a value in a region and verify that it shows up. * * @throws Exception */ public void testGetElementForRegionInfo() throws Exception { String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); // clear the region cache.clear(); String key = "myKey"; cache.put( key, "value" ); JCSAdminBean admin = new JCSAdminBean(); CacheElementInfo[] elements = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region.", 1, elements.length ); CacheElementInfo elementInfo = elements[0]; assertEquals( "Wrong key." + elementInfo, key, elementInfo.getKey() ); }
/** * Add an item to a region. Call clear all and verify that it doesn't exist. * * @throws Exception */ public void testClearAll() throws Exception { JCSAdminBean admin = new JCSAdminBean(); String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); String key = "myKey"; cache.put( key, "value" ); admin.clearAllRegions(); CacheElementInfo[] elements2 = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length ); } }
/** * @return string info on the region */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\nCacheRegionInfo " ); if ( cacheName != null ) { buf.append( "\n CacheName [" + cacheName + "]" ); buf.append( "\n Status [" + cacheStatus + "]" ); } buf.append( "\n ByteCount [" + getByteCount() + "]" ); return buf.toString(); } }
/** * Write a single byte and verify the count. * * @throws Exception */ public void testSingleByte() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); out.write( 1 ); assertEquals( "Wrong number of bytes written.", 1, out.getCount() ); out.write( 1 ); assertEquals( "Wrong number of bytes written.", 2, out.getCount() ); out.close(); }
/** * Remove an item via the remove method. * * @throws Exception */ public void testRemove() throws Exception { JCSAdminBean admin = new JCSAdminBean(); String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); // clear the region cache.clear(); admin.clearRegion( regionName ); String key = "myKey"; cache.put( key, "value" ); CacheElementInfo[] elements = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region.", 1, elements.length ); CacheElementInfo elementInfo = elements[0]; assertEquals( "Wrong key.", key, elementInfo.getKey() ); admin.removeItem( regionName, key ); CacheElementInfo[] elements2 = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length ); }
/** * Create a test region and then verify that we get it from the list. * * @throws Exception * */ public void testGetRegionInfo() throws Exception { String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); cache.put( "key", "value" ); JCSAdminBean admin = new JCSAdminBean(); CacheRegionInfo[] regions = admin.buildCacheInfo(); boolean foundRegion = false; for (CacheRegionInfo info : regions) { if ( info.getCacheName().equals( regionName ) ) { foundRegion = true; assertTrue( "Byte count should be greater than 5.", info.getByteCount() > 5 ); assertNotNull( "Should have stats.", info.getCacheStatistics() ); } } assertTrue( "Should have found the region we just created.", foundRegion ); }
/** * Put a value in a region and verify that it shows up. * * @throws Exception */ public void testGetElementForRegionInfo() throws Exception { String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); // clear the region cache.clear(); String key = "myKey"; cache.put( key, "value" ); JCSAdminBean admin = new JCSAdminBean(); CacheElementInfo[] elements = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region.", 1, elements.length ); CacheElementInfo elementInfo = elements[0]; assertEquals( "Wrong key." + elementInfo, key, elementInfo.getKey() ); }
/** * Add an item to a region. Call clear all and verify that it doesn't exist. * * @throws Exception */ public void testClearAll() throws Exception { JCSAdminBean admin = new JCSAdminBean(); String regionName = "myRegion"; CacheAccess<String, String> cache = JCS.getInstance( regionName ); String key = "myKey"; cache.put( key, "value" ); admin.clearAllRegions(); CacheElementInfo[] elements2 = admin.buildElementInfo( regionName ); assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length ); } }
/** * @return string info on the item */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\nCacheElementInfo " ); buf.append( "\n Key [" ).append( getKey() ).append( "]" ); buf.append( "\n Eternal [" ).append( isEternal() ).append( "]" ); buf.append( "\n CreateTime [" ).append( getCreateTime() ).append( "]" ); buf.append( "\n MaxLifeSeconds [" ).append( getMaxLifeSeconds() ).append( "]" ); buf.append( "\n ExpiresInSeconds [" ).append( getExpiresInSeconds() ).append( "]" ); return buf.toString(); } }
/** * @return string info on the region */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\nCacheRegionInfo " ); if ( cacheName != null ) { buf.append( "\n CacheName [" + cacheName + "]" ); buf.append( "\n Status [" + cacheStatus + "]" ); } buf.append( "\n ByteCount [" + getByteCount() + "]" ); return buf.toString(); } }
/** * Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in * the region or an error occurs, suppresses exceptions and returns 0. * <p/> * * @return int The size of the region in bytes. */ @Override public int getByteCount(String cacheName) { return getByteCount(cacheHub.getCache(cacheName)); }
/** * This should count the size of the array. * * @throws Exception */ public void testByteArray() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); byte[] array = new byte[]{1,2,3,4,5}; out.write( array ); assertEquals( "Wrong number of bytes written.", array.length, out.getCount() ); out.close(); }
/** * Write a single byte and verify the count. * * @throws Exception */ public void testSingleByte() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); out.write( 1 ); assertEquals( "Wrong number of bytes written.", 1, out.getCount() ); out.write( 1 ); assertEquals( "Wrong number of bytes written.", 2, out.getCount() ); out.close(); }
/** * This should count the len -- the third arg * * @throws Exception */ public void testByteArrayLenCount() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); byte[] array = new byte[]{1,2,3,4,5}; int len = 3; out.write( array, 0, len ); assertEquals( "Wrong number of bytes written.", len, out.getCount() ); out.close(); } }
/** * This should count the len -- the third arg * * @throws Exception */ public void testByteArrayLenCount() throws Exception { CountingOnlyOutputStream out = new CountingOnlyOutputStream(); byte[] array = new byte[]{1,2,3,4,5}; int len = 3; out.write( array, 0, len ); assertEquals( "Wrong number of bytes written.", len, out.getCount() ); out.close(); } }