public void testSaveLoadKeysSize() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testSaveLoadKeys" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 10000 ); attributes.setBlockSizeBytes( 2000 ); testSaveLoadKeysInner(attributes); }
public void testSaveLoadKeysSize() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testSaveLoadKeys"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(10000); attributes.setBlockSizeBytes(2000); testSaveLoadKeysInner(attributes); }
public void testPutKeysSize() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testPutKeys"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(100000); attributes.setBlockSizeBytes(1024); attributes.setDiskLimitType(DiskLimitType.SIZE); innerTestPutKeys(attributes); }
public void testPutKeysSize() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testPutKeys" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 100000 ); attributes.setBlockSizeBytes( 1024 ); attributes.setDiskLimitType(DiskLimitType.SIZE); innerTestPutKeys(attributes); }
/** * Put a bunch of keys inthe key store and verify that they are present. * <p> * @throws Exception */ public void testPutKeys() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testPutKeys" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 1000 ); attributes.setBlockSizeBytes( 2000 ); innerTestPutKeys(attributes); }
/** * Put a bunch of keys in the key store and verify that they are present. * <p> * * @throws Exception */ public void testPutKeys() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testPutKeys"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(1000); attributes.setBlockSizeBytes(2000); innerTestPutKeys(attributes); }
/** * Verify that we can load keys that we saved. Add a bunch. Save them. Clear the memory keyhash. * Load the keys. Verify. * <p> * @throws Exception */ public void testSaveLoadKeys() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testSaveLoadKeys" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 10000 ); attributes.setBlockSizeBytes( 2000 ); testSaveLoadKeysInner(attributes); }
cattr.setMaxKeySize(100); cattr.setBlockSizeBytes(200); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, byte[]> diskCache = new BlockDiskCache<String, byte[]>(cattr);
public void testPutGetMatching_SmallWait() throws Exception { // SETUP int items = 200; String cacheName = "testPutGetMatching_SmallWait"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setMaxKeySize( 100 ); cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" ); BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr ); // DO WORK for ( int i = 0; i <= items; i++ ) { diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) ); } Thread.sleep( 500 ); Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" ); // VERIFY assertEquals( "Wrong number returned", 10, matchingResults.size() ); //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() ); //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() ); }
cattr.setMaxKeySize( 100 ); cattr.setBlockSizeBytes( 200 ); cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" ); BlockDiskCache<String, byte[]> diskCache = new BlockDiskCache<String, byte[]>( cattr );
public void testPutGetMatching_SmallWait() throws Exception { // SETUP int items = 200; String cacheName = "testPutGetMatching_SmallWait"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMaxKeySize(100); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>(cattr); // DO WORK for (int i = 0; i <= items; i++) { diskCache.update(new CacheElement<String, String>(cacheName, i + ":key", cacheName + " data " + i)); } Thread.sleep(500); Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching("1.8.+"); // VERIFY assertEquals("Wrong number returned", 10, matchingResults.size()); // System.out.println( "matchingResults.keySet() " + matchingResults.keySet() ); // System.out.println( "\nAFTER TEST \n" + diskCache.getStats() ); }
/** * Verify that we can load keys that we saved. Add a bunch. Save them. Clear * the memory key hash. Load the keys. Verify. * <p> * * @throws Exception */ public void testSaveLoadKeys() throws Exception { // SETUP BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testSaveLoadKeys"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(10000); attributes.setBlockSizeBytes(2000); testSaveLoadKeysInner(attributes); }
cattr.setMaxKeySize(100); cattr.setBlockSizeBytes(200); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>(cattr);
/** * Test the basic get matching. With no wait this will all come from purgatory. * <p> * * @throws Exception */ public void testPutGetMatching_NoWait() throws Exception { // SETUP int items = 200; String cacheName = "testPutGetMatching_NoWait"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMaxKeySize(100); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>(cattr); // DO WORK for (int i = 0; i <= items; i++) { diskCache.update(new CacheElement<String, String>(cacheName, i + ":key", cacheName + " data " + i)); } Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching("1.8.+"); // VERIFY assertEquals("Wrong number returned", 10, matchingResults.size()); // System.out.println( "matchingResults.keySet() " + matchingResults.keySet() ); // System.out.println( "\nAFTER TEST \n" + diskCache.getStats() ); }
/** * Test the basic get matching. With no wait this will all come from purgatory. * <p> * @throws Exception */ public void testPutGetMatching_NoWait() throws Exception { // SETUP int items = 200; String cacheName = "testPutGetMatching_NoWait"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setMaxKeySize( 100 ); cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" ); BlockDiskCache<String, String> diskCache = new BlockDiskCache<String, String>( cattr ); // DO WORK for ( int i = 0; i <= items; i++ ) { diskCache.update( new CacheElement<String, String>( cacheName, i + ":key", cacheName + " data " + i ) ); } Map<String, ICacheElement<String, String>> matchingResults = diskCache.getMatching( "1.8.+" ); // VERIFY assertEquals( "Wrong number returned", 10, matchingResults.size() ); //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() ); //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() ); }
public void testObjectLargerThanMaxSize() { BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testObjectLargerThanMaxSize"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(1000); attributes.setBlockSizeBytes(2000); attributes.setDiskLimitType(DiskLimitType.SIZE); @SuppressWarnings({ "unchecked", "rawtypes" }) BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>(attributes, new BlockDiskCache(attributes)); keyStore.put("1", new int[1000]); keyStore.put("2", new int[1000]); assertNull(keyStore.get("1")); assertNotNull(keyStore.get("2")); } }
public void testObjectLargerThanMaxSize() { BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testObjectLargerThanMaxSize" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 1000 ); attributes.setBlockSizeBytes( 2000 ); attributes.setDiskLimitType(DiskLimitType.SIZE); @SuppressWarnings({ "unchecked", "rawtypes" }) BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, new BlockDiskCache(attributes)); keyStore.put("1", new int[1000]); keyStore.put("2", new int[1000]); assertNull(keyStore.get("1")); assertNotNull(keyStore.get("2")); } }
/** * Add some items to the disk cache and then remove them one by one. * * @throws IOException */ public void testRemoveItems() throws IOException { BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName("testRemoveItems"); cattr.setMaxKeySize(100); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, String> disk = new BlockDiskCache<String, String>(cattr); disk.processRemoveAll(); int cnt = 25; for (int i = 0; i < cnt; i++) { IElementAttributes eAttr = new ElementAttributes(); eAttr.setIsSpool(true); ICacheElement<String, String> element = new CacheElement<String, String>("testRemoveItems", "key:" + i, "data:" + i); element.setElementAttributes(eAttr); disk.processUpdate(element); } // remove each for (int i = 0; i < cnt; i++) { disk.remove("key:" + i); ICacheElement<String, String> element = disk.processGet("key:" + i); assertNull("Should not have received an element.", element); } }
cattr.setCacheName("testRemove_PartialKey"); cattr.setMaxKeySize(100); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, String> disk = new BlockDiskCache<String, String>(cattr);
public void testAppendToDisk() throws Exception { String cacheName = "testAppendToDisk"; BlockDiskCacheAttributes cattr = getCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMaxKeySize(100); cattr.setBlockSizeBytes(500); cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest"); BlockDiskCache<String, X> diskCache = new BlockDiskCache<String, X>(cattr); diskCache.removeAll(); X value1 = new X(); value1.string = "1234567890"; X value2 = new X(); value2.string = "0987654321"; diskCache.update(new CacheElement<String, X>(cacheName, "1", value1)); diskCache.dispose(); diskCache = new BlockDiskCache<String, X>(cattr); diskCache.update(new CacheElement<String, X>(cacheName, "2", value2)); diskCache.dispose(); diskCache = new BlockDiskCache<String, X>(cattr); assertTrue(diskCache.verifyDisk()); assertEquals(2, diskCache.getKeySet().size()); assertEquals(value1.string, diskCache.get("1").getVal().string); assertEquals(value2.string, diskCache.get("2").getVal().string); }