KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > InterceptorConfigurationTest


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.cache.tests;
8
9 import junit.framework.Test;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12 import org.jboss.cache.TreeCache;
13 import org.jboss.cache.interceptors.*;
14 import org.jboss.cache.loader.LocalDelegatingCacheLoader;
15
16 import java.util.List JavaDoc;
17
18 /**
19  * Created by IntelliJ IDEA.
20  * User: bela
21  * Date: Jun 9, 2004
22  * Time: 9:05:19 AM
23  */

24 public class InterceptorConfigurationTest extends TestCase {
25    TreeCache cache=null;
26
27    protected void setUp() throws Exception JavaDoc {
28       super.setUp();
29       cache=new TreeCache();
30       cache.setCacheMode(TreeCache.LOCAL);
31    }
32
33    protected void tearDown() throws Exception JavaDoc {
34       super.tearDown();
35       if(cache != null) {
36          cache.stopService();
37          cache.destroyService();
38       }
39    }
40
41
42    public void testBareConfig() throws Exception JavaDoc {
43       cache.createService();
44       cache.startService();
45       System.out.println("interceptors are:\n" + cache.getInterceptorChain());
46       List JavaDoc list=cache.getInterceptors();
47       assertNotNull(list);
48       assertEquals(3, list.size());
49       assertEquals(list.get(0).getClass(), UnlockInterceptor.class);
50       // assertEquals(list.get(1).getClass(), CreateIfNotExistsInterceptor.class);
51
assertEquals(list.get(1).getClass(), LockInterceptor.class);
52       assertEquals(list.get(2).getClass(), CallInterceptor.class);
53    }
54
55
56    public void testTxConfig() throws Exception JavaDoc {
57       cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
58       cache.createService();
59       cache.startService();
60       System.out.println("interceptors are:\n" + cache.getInterceptorChain());
61       List JavaDoc list=cache.getInterceptors();
62       assertNotNull(list);
63       assertEquals(3, list.size());
64       assertEquals(list.get(0).getClass(), UnlockInterceptor.class);
65       // assertEquals(list.get(1).getClass(), CreateIfNotExistsInterceptor.class);
66
assertEquals(list.get(1).getClass(), LockInterceptor.class);
67       assertEquals(list.get(2).getClass(), CallInterceptor.class);
68    }
69
70    public void testSharedCacheLoaderConfig() throws Exception JavaDoc {
71       cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
72       cache.setCacheLoader(new LocalDelegatingCacheLoader(null));
73       cache.setCacheLoaderShared(true);
74       cache.setCacheMode(TreeCache.REPL_ASYNC);
75       cache.setFetchStateOnStartup(false);
76       cache.createService();
77       cache.startService();
78       System.out.println("interceptors are:\n" + cache.getInterceptorChain());
79       List JavaDoc list=cache.getInterceptors();
80       assertNotNull(list);
81
82       assertEquals(6, list.size());
83
84       assertEquals(list.get(0).getClass(), CacheStoreInterceptor.class);
85       assertEquals(list.get(1).getClass(), ReplicationInterceptor.class);
86       assertEquals(list.get(2).getClass(), UnlockInterceptor.class);
87       assertEquals(list.get(3).getClass(), CacheLoaderInterceptor.class);
88       // assertEquals(list.get(4).getClass(), CreateIfNotExistsInterceptor.class);
89
assertEquals(list.get(4).getClass(), LockInterceptor.class);
90       assertEquals(list.get(5).getClass(), CallInterceptor.class);
91    }
92
93    public void testUnsharedCacheLoaderConfig() throws Exception JavaDoc {
94       cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
95       cache.setCacheLoader(new LocalDelegatingCacheLoader(null));
96       cache.setCacheLoaderShared(false);
97       cache.setCacheMode(TreeCache.REPL_ASYNC);
98       cache.setFetchStateOnStartup(false);
99       cache.createService();
100       cache.startService();
101       System.out.println("interceptors are:\n" + cache.getInterceptorChain());
102       List JavaDoc list=cache.getInterceptors();
103       assertNotNull(list);
104
105       assertEquals(6, list.size());
106
107       assertEquals(list.get(0).getClass(), ReplicationInterceptor.class);
108       assertEquals(list.get(1).getClass(), UnlockInterceptor.class);
109       assertEquals(list.get(2).getClass(), CacheLoaderInterceptor.class);
110       assertEquals(list.get(3).getClass(), CacheStoreInterceptor.class);
111       // assertEquals(list.get(4).getClass(), CreateIfNotExistsInterceptor.class);
112
assertEquals(list.get(4).getClass(), LockInterceptor.class);
113       assertEquals(list.get(5).getClass(), CallInterceptor.class);
114    }
115
116    public void testTxAndRepl() throws Exception JavaDoc {
117       cache.setCacheMode("repl_sync");
118       cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
119       cache.createService();
120       cache.startService();
121       System.out.println("interceptors are:\n" + cache.getInterceptorChain());
122       List JavaDoc list=cache.getInterceptors();
123       assertNotNull(list);
124
125       assertEquals(4, list.size());
126
127       assertEquals(list.get(0).getClass(), ReplicationInterceptor.class);
128       assertEquals(list.get(1).getClass(), UnlockInterceptor.class);
129       // assertEquals(list.get(2).getClass(), CreateIfNotExistsInterceptor.class);
130
assertEquals(list.get(2).getClass(), LockInterceptor.class);
131       assertEquals(list.get(3).getClass(), CallInterceptor.class);
132    }
133
134    public static Test suite() {
135       return new TestSuite(InterceptorConfigurationTest.class);
136    }
137
138    public static void main(String JavaDoc[] args) {
139       junit.textui.TestRunner.run(suite());
140    }
141
142 }
143
Popular Tags