1 |
| package org.jboss.cache.multiplexer; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| import org.jboss.cache.Cache; |
5 |
| import org.jboss.cache.DefaultCacheFactory; |
6 |
| import org.jboss.cache.config.Configuration; |
7 |
| import org.jboss.cache.config.RuntimeConfig; |
8 |
| import org.jgroups.Channel; |
9 |
| import org.jgroups.JChannel; |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| public class ChannelInjectionPreferenceTest extends TestCase |
19 |
| { |
20 |
| private MultiplexerTestHelper muxHelper; |
21 |
| private Cache cache; |
22 |
| private boolean cacheStarted; |
23 |
| |
24 |
1
| protected void setUp() throws Exception
|
25 |
| { |
26 |
1
| muxHelper = new MultiplexerTestHelper();
|
27 |
1
| Configuration config = new Configuration();
|
28 |
1
| config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
|
29 |
1
| config.setClusterConfig(JChannel.DEFAULT_PROTOCOL_STACK);
|
30 |
1
| cache = DefaultCacheFactory.getInstance().createCache(config, false);
|
31 |
1
| cacheStarted = false;
|
32 |
| |
33 |
1
| super.setUp();
|
34 |
| } |
35 |
| |
36 |
1
| public void tearDown() throws Exception
|
37 |
| { |
38 |
1
| try
|
39 |
| { |
40 |
1
| super.tearDown();
|
41 |
1
| if (cacheStarted && cache != null)
|
42 |
| { |
43 |
1
| cache.stop();
|
44 |
1
| cache.destroy();
|
45 |
| } |
46 |
| } |
47 |
| finally |
48 |
| { |
49 |
1
| if (muxHelper != null)
|
50 |
| { |
51 |
1
| muxHelper.tearDown();
|
52 |
1
| muxHelper = null;
|
53 |
| } |
54 |
| } |
55 |
| } |
56 |
| |
57 |
1
| public void testChannelInjectionPreference() throws Exception
|
58 |
| { |
59 |
1
| muxHelper.configureCacheForMux(cache);
|
60 |
| |
61 |
1
| Channel channel = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
|
62 |
| |
63 |
1
| RuntimeConfig rtcfg = cache.getConfiguration().getRuntimeConfig();
|
64 |
1
| rtcfg.setChannel(channel);
|
65 |
| |
66 |
| |
67 |
1
| checkStart(false, false);
|
68 |
| |
69 |
1
| assertEquals("Injected channel used", channel, rtcfg.getChannel());
|
70 |
| } |
71 |
| |
72 |
1
| private void checkStart(boolean expectFail, boolean expectMux)
|
73 |
| { |
74 |
1
| try
|
75 |
| { |
76 |
1
| cache.start();
|
77 |
1
| cacheStarted = true;
|
78 |
1
| if (expectFail)
|
79 |
| { |
80 |
0
| fail("Start did not fail as expected");
|
81 |
| } |
82 |
| |
83 |
1
| if (expectMux)
|
84 |
| { |
85 |
0
| assertTrue("Cache is using mux", cache.getConfiguration().isUsingMultiplexer());
|
86 |
| } |
87 |
| else |
88 |
| { |
89 |
1
| assertFalse("Cache is not using mux ", cache.getConfiguration().isUsingMultiplexer());
|
90 |
| } |
91 |
| } |
92 |
| catch (Exception e) |
93 |
| { |
94 |
0
| if (!expectFail)
|
95 |
| { |
96 |
0
| fail("Caught exception starting cache " + e.getLocalizedMessage());
|
97 |
| } |
98 |
| } |
99 |
| |
100 |
| } |
101 |
| } |