1 |
| package org.jboss.cache.config; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| import org.jboss.cache.Cache; |
5 |
| import org.jboss.cache.DefaultCacheFactory; |
6 |
| import org.jboss.cache.Fqn; |
7 |
| import org.jboss.cache.misc.TestingUtil; |
8 |
| import org.jgroups.JChannel; |
9 |
| |
10 |
| import java.util.HashSet; |
11 |
| import java.util.Set; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class ChannelInjectionTest extends TestCase |
21 |
| { |
22 |
| private Set<Cache> caches = new HashSet(); |
23 |
| |
24 |
1
| public void tearDown() throws Exception
|
25 |
| { |
26 |
1
| super.tearDown();
|
27 |
| |
28 |
1
| for (Cache cache : caches)
|
29 |
| { |
30 |
2
| try
|
31 |
| { |
32 |
2
| cache.stop();
|
33 |
| } |
34 |
| catch (Exception e) |
35 |
| { |
36 |
0
| e.printStackTrace(System.out);
|
37 |
| } |
38 |
| } |
39 |
| } |
40 |
| |
41 |
1
| public void testChannelInjectionPreference() throws Exception
|
42 |
| { |
43 |
1
| Cache cache1 = createCache();
|
44 |
1
| Cache cache2 = createCache();
|
45 |
| |
46 |
1
| JChannel ch1 = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
|
47 |
1
| cache1.getConfiguration().getRuntimeConfig().setChannel(ch1);
|
48 |
| |
49 |
1
| JChannel ch2 = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
|
50 |
1
| cache2.getConfiguration().getRuntimeConfig().setChannel(ch2);
|
51 |
| |
52 |
1
| cache1.start();
|
53 |
1
| cache2.start();
|
54 |
| |
55 |
1
| TestingUtil.blockUntilViewsReceived(new Cache[]{cache1, cache2}, 10000);
|
56 |
| |
57 |
1
| Fqn fqn = Fqn.fromString("/a");
|
58 |
1
| cache1.put(fqn, "key", "value");
|
59 |
1
| assertEquals("Value replicated", "value", cache2.get(fqn, "key"));
|
60 |
| } |
61 |
| |
62 |
2
| private Cache createCache() throws Exception
|
63 |
| { |
64 |
2
| Configuration config = new Configuration();
|
65 |
2
| config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
|
66 |
2
| Cache cache = DefaultCacheFactory.getInstance().createCache(config, false);
|
67 |
2
| caches.add(cache);
|
68 |
| |
69 |
2
| return cache;
|
70 |
| } |
71 |
| } |