1 7 package org.jboss.test.cache.test.standAloneAop; 8 9 import junit.framework.Test; 10 import junit.framework.TestCase; 11 import junit.framework.TestSuite; 12 import org.jboss.logging.Logger; 13 14 16 17 23 24 public class LocalEvictionAopTest extends TestCase 25 { 26 Logger log = Logger.getLogger(LocalEvictionAopTest.class); 28 TreeCacheAopTester tester; 29 int wakeupIntervalMillis_ = 0; 30 31 32 public LocalEvictionAopTest(String name) 33 { 34 super(name); 35 } 36 37 protected void setUp() throws Exception 38 { 39 super.setUp(); 40 log.info("setUp() ...."); 41 String configFile = "META-INF/local-aop-eviction-service.xml"; 42 tester = new TreeCacheAopTester(configFile); 43 wakeupIntervalMillis_ = tester.cache.getEvictionThreadWakeupIntervalSeconds() *1000; 44 log.info("wakeupInterval is " +wakeupIntervalMillis_); 45 if(wakeupIntervalMillis_ <=0) 46 fail("testEviction(): eviction thread wake up interval is illegal " +wakeupIntervalMillis_); 47 } 48 49 protected void tearDown() throws Exception 50 { 51 super.tearDown(); 52 tester.stop(); 53 tester = null; 54 } 55 56 58 public void testSetup() 59 { 60 log.info("testSetup() ...."); 61 try { 62 tester.testSetup(); 63 } catch (Exception ex) { 64 ex.printStackTrace(); 65 fail("testSetup(): fails. " + ex.toString()); 66 } 67 } 68 69 public void testSimple() throws Exception 70 { 71 log.info("testSimple() ...."); 72 tester.createPerson("/aop/joe1", "Joe Gibbs I", 32); 73 tester.createPerson("/aop/joe2", "Joe Gibbs II", 42); 74 tester.createPerson("/aop/joe3", "Joe Gibbs III", 52); 75 tester.createPerson("/aop/joe4", "Joe Gibbs IV", 62); 76 int period = (wakeupIntervalMillis_ +1000); 77 _sleep(period); 79 assertEquals((Object ) tester.getName("/aop/joe4"), (Object ) "Joe Gibbs IV"); 80 assertTrue(tester.getAge("/aop/joe4") == 62); 81 log.info("testCircularReference3(): cache contents " + tester.printCacheDetails()); 82 } 83 84 public void testReconstruction() throws Exception 85 { 86 log.info("testReconstruction() ...."); 87 tester.createPerson("/aop/joe1", "Joe Gibbs I", 32); 88 Person joe1 = (Person)tester.getPerson("/aop/joe1"); 89 tester.createPerson("/aop/joe2", "Joe Gibbs II", 42); 90 tester.createPerson("/aop/joe3", "Joe Gibbs III", 52); 91 tester.createPerson("/aop/joe4", "Joe Gibbs IV", 62); 92 int period = (wakeupIntervalMillis_ +1000); 93 _sleep(period); 95 assertEquals((Object ) joe1.getName(), (Object ) "Joe Gibbs I"); log.info("testCircularReference3(): cache contents " + tester.printCacheDetails()); 97 } 98 99 void _sleep(long msecs) { 100 try { 101 Thread.sleep(msecs); 102 } catch (InterruptedException e) { 103 e.printStackTrace(); } 105 } 106 107 public static Test suite() throws Exception 108 { 109 return new TestSuite(LocalEvictionAopTest.class); 110 } 111 112 113 public static void main(String [] args) throws Exception 114 { 115 junit.textui.TestRunner.run(suite()); 116 } 117 118 } 119 120 | Popular Tags |