1 23 24 package com.rift.coad.lib.cache; 25 26 import junit.framework.*; 27 import java.util.Date ; 28 import java.util.Map ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import org.apache.log4j.Logger; 32 import com.rift.coad.lib.configuration.ConfigurationFactory; 33 import com.rift.coad.lib.configuration.Configuration; 34 import com.rift.coad.lib.thread.ThreadStateMonitor; 35 36 40 public class KeySyncCacheTest extends TestCase { 41 42 public KeySyncCacheTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 } 48 49 protected void tearDown() throws Exception { 50 } 51 52 public static Test suite() { 53 TestSuite suite = new TestSuite(KeySyncCacheTest.class); 54 55 return suite; 56 } 57 58 61 public void testKeySyncCache() throws Exception { 62 System.out.println("KeySyncCache"); 63 64 KeySyncCache instance = new KeySyncCache(); 65 66 KeySyncCache.KeySync fred = instance.getKeySync("fred"); 67 KeySyncCache.KeySync bob = instance.getKeySync("bob"); 68 KeySyncCache.KeySync mary = instance.getKeySync("mary"); 69 assertEquals(fred, instance.getKeySync("fred")); 70 assertEquals(bob, instance.getKeySync("bob")); 71 assertEquals(mary, instance.getKeySync("mary")); 72 73 for (int count = 0; count < 4; count++) { 74 Thread.sleep(500); 75 fred.touch(); 76 mary = instance.getKeySync("mary"); 77 } 78 79 instance.garbageCollect(); 80 81 assertEquals(fred, instance.getKeySync("fred")); 82 assertEquals(mary, instance.getKeySync("mary")); 83 if (bob == instance.getKeySync("bob")) { 84 fail("The entry should not have been found"); 85 } 86 87 instance.clear(); 88 89 if (instance.contains("fred")) { 90 fail("The instance still contains fred"); 91 } 92 if (instance.contains("mary")) { 93 fail("The instance still contains mary"); 94 } 95 96 try { 97 instance.getKeySync("fred"); 98 fail("Should not have been able to retrieve a sync instance"); 99 } catch (CacheException ex) { 100 } 102 } 103 104 105 } 106 | Popular Tags |