KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jboss.cache.tests.basic;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.jboss.cache.TreeCache;
7 import org.jboss.cache.interceptors.*;
8 import org.jboss.cache.loader.LocalDelegatingCacheLoader;
9
10 import java.util.List JavaDoc;
11
12 /**
13  * Created by IntelliJ IDEA.
14  * User: bela
15  * Date: Jun 9, 2004
16  * Time: 9:05:19 AM
17  */

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