KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cache > test > standAloneAop > LocalEvictionAopTest


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

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 //import org.jboss.test.JBossTestCase;
15

16
17 /**
18  * LocalTestCase.java that uses standalone aop package.
19  * <p/>
20  * <p/>
21  * Created: Mon May 05 17:30:11 2003
22  */

23
24 public class LocalEvictionAopTest extends TestCase
25 {
26 // Category log = getLog();
27
Logger log = Logger.getLogger(LocalEvictionAopTest.class);
28    TreeCacheAopTester tester;
29    int wakeupIntervalMillis_ = 0;
30
31
32    public LocalEvictionAopTest(String JavaDoc name)
33    {
34       super(name);
35    }
36
37    protected void setUp() throws Exception JavaDoc
38    {
39       super.setUp();
40       log.info("setUp() ....");
41       String JavaDoc 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 JavaDoc
50    {
51       super.tearDown();
52       tester.stop();
53       tester = null;
54    }
55
56 // public void testDummy() {}
57

58    public void testSetup()
59    {
60       log.info("testSetup() ....");
61       try {
62          tester.testSetup();
63       } catch (Exception JavaDoc ex) {
64          ex.printStackTrace();
65          fail("testSetup(): fails. " + ex.toString());
66       }
67    }
68
69    public void testSimple() throws Exception JavaDoc
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); // it really depends on the eviction thread time.
78

79       assertEquals((Object JavaDoc) tester.getName("/aop/joe4"), (Object JavaDoc) "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 JavaDoc
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); // it really depends on the eviction thread time.
94

95       assertEquals((Object JavaDoc) joe1.getName(), (Object JavaDoc) "Joe Gibbs I"); // should reconstruct the cache from im-memory
96
log.info("testCircularReference3(): cache contents " + tester.printCacheDetails());
97    }
98
99    void _sleep(long msecs) {
100       try {
101          Thread.sleep(msecs);
102       } catch (InterruptedException JavaDoc e) {
103          e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
104
}
105    }
106
107    public static Test suite() throws Exception JavaDoc
108    {
109       return new TestSuite(LocalEvictionAopTest.class);
110    }
111
112
113    public static void main(String JavaDoc[] args) throws Exception JavaDoc
114    {
115       junit.textui.TestRunner.run(suite());
116    }
117
118 }
119
120
Popular Tags