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