1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.loader; |
8 |
| |
9 |
| import org.jboss.cache.CacheImpl; |
10 |
| import org.jboss.cache.DefaultCacheFactory; |
11 |
| import org.jboss.cache.interceptors.CacheStoreInterceptor; |
12 |
| import org.jboss.cache.interceptors.Interceptor; |
13 |
| |
14 |
| import java.util.Iterator; |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase |
22 |
| { |
23 |
| private CacheImpl cache1, cache2; |
24 |
| private DummyCacheLoader dummyCacheLoader; |
25 |
| |
26 |
1
| protected void setUp() throws Exception
|
27 |
| { |
28 |
0
| if (cache1 != null || cache2 != null) tearDown();
|
29 |
| |
30 |
| |
31 |
1
| cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
32 |
1
| cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
33 |
| |
34 |
1
| cache1.getConfiguration().setCacheMode("REPL_SYNC");
|
35 |
1
| cache2.getConfiguration().setCacheMode("REPL_SYNC");
|
36 |
| |
37 |
1
| cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
|
38 |
1
| cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
|
39 |
| |
40 |
1
| cache1.start();
|
41 |
1
| cache2.start();
|
42 |
| |
43 |
| |
44 |
1
| dummyCacheLoader = new DummyCacheLoader();
|
45 |
| |
46 |
1
| cache1.setCacheLoader(dummyCacheLoader);
|
47 |
1
| cache2.setCacheLoader(dummyCacheLoader);
|
48 |
1
| findCacheStoreInterceptor(cache1).setCache(cache1);
|
49 |
1
| findCacheStoreInterceptor(cache2).setCache(cache2);
|
50 |
| } |
51 |
| |
52 |
2
| protected CacheStoreInterceptor findCacheStoreInterceptor(CacheImpl cache)
|
53 |
| { |
54 |
2
| Iterator ints = cache.getInterceptors().iterator();
|
55 |
2
| CacheStoreInterceptor csi = null;
|
56 |
10
| while (ints.hasNext())
|
57 |
| { |
58 |
10
| Interceptor i = (Interceptor) ints.next();
|
59 |
10
| if (i instanceof CacheStoreInterceptor)
|
60 |
| { |
61 |
2
| csi = (CacheStoreInterceptor) i;
|
62 |
2
| break;
|
63 |
| } |
64 |
| } |
65 |
2
| return csi;
|
66 |
| } |
67 |
| |
68 |
1
| protected void tearDown()
|
69 |
| { |
70 |
1
| if (cache1 != null) cache1.stop();
|
71 |
1
| if (cache2 != null) cache2.stop();
|
72 |
1
| cache1 = null;
|
73 |
1
| cache2 = null;
|
74 |
| } |
75 |
| |
76 |
1
| public void testReplicationWithSharedCL() throws Exception
|
77 |
| { |
78 |
1
| cache1.put("/test", "one", "two");
|
79 |
| |
80 |
| |
81 |
1
| assertEquals("two", cache1.get("/test", "one"));
|
82 |
1
| assertEquals("two", cache2.get("/test", "one"));
|
83 |
| |
84 |
| |
85 |
1
| assertEquals(1, dummyCacheLoader.getPutCount());
|
86 |
| } |
87 |
| } |