KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > aop > LocalEvictionAopTest


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

11
12 /**
13  * LocalTestCase.java that uses standalone aop package.
14  * <p/>
15  * <p/>
16  * Created: Mon May 05 17:30:11 2003
17  */

18
19 public class LocalEvictionAopTest extends TestCase
20 {
21 // Category log_ = getLog();
22
Log log=LogFactory.getLog(LocalEvictionAopTest.class);
23    TreeCacheAopTester tester;
24    int wakeupIntervalMillis_ = 0;
25
26
27    public LocalEvictionAopTest(String JavaDoc name)
28    {
29       super(name);
30    }
31
32    protected void setUp() throws Exception JavaDoc
33    {
34       super.setUp();
35       log.info("setUp() ....");
36       String JavaDoc 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 JavaDoc
45    {
46       super.tearDown();
47       tester.stop();
48       tester = null;
49    }
50
51 // public void testDummy() {}
52

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

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

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