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.jgroups.JChannel; |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| public class BadMuxConfigTest extends TestCase |
17 |
| { |
18 |
| private MultiplexerTestHelper muxHelper; |
19 |
| private Cache cache; |
20 |
| private boolean cacheStarted; |
21 |
| |
22 |
4
| protected void setUp() throws Exception
|
23 |
| { |
24 |
4
| muxHelper = new MultiplexerTestHelper();
|
25 |
4
| Configuration config = new Configuration();
|
26 |
4
| config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
|
27 |
4
| config.setClusterConfig(JChannel.DEFAULT_PROTOCOL_STACK);
|
28 |
4
| cache = DefaultCacheFactory.getInstance().createCache(config, false);
|
29 |
4
| cacheStarted = false;
|
30 |
| |
31 |
4
| super.setUp();
|
32 |
| } |
33 |
| |
34 |
4
| public void tearDown() throws Exception
|
35 |
| { |
36 |
4
| try
|
37 |
| { |
38 |
4
| super.tearDown();
|
39 |
4
| if (cacheStarted && cache != null)
|
40 |
| { |
41 |
2
| cache.stop();
|
42 |
2
| cache.destroy();
|
43 |
| } |
44 |
| } |
45 |
| finally |
46 |
| { |
47 |
4
| if (muxHelper != null)
|
48 |
| { |
49 |
4
| muxHelper.tearDown();
|
50 |
4
| muxHelper = null;
|
51 |
| } |
52 |
| } |
53 |
| } |
54 |
| |
55 |
1
| public void testValidMuxConfig() throws Exception
|
56 |
| { |
57 |
1
| muxHelper.configureCacheForMux(cache);
|
58 |
| |
59 |
1
| checkStart(false, true);
|
60 |
| } |
61 |
| |
62 |
1
| public void testMissingMuxChannelFactory() throws Exception
|
63 |
| { |
64 |
1
| muxHelper.configureCacheForMux(cache);
|
65 |
1
| cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(null);
|
66 |
| |
67 |
1
| checkStart(false, false);
|
68 |
| } |
69 |
| |
70 |
1
| public void testInvalidStackName() throws Exception
|
71 |
| { |
72 |
1
| muxHelper.configureCacheForMux(cache);
|
73 |
1
| cache.getConfiguration().setMultiplexerStack("bogus");
|
74 |
| |
75 |
1
| checkStart(true, false);
|
76 |
| } |
77 |
| |
78 |
1
| public void testMissingStackName() throws Exception
|
79 |
| { |
80 |
1
| muxHelper.configureCacheForMux(cache);
|
81 |
1
| cache.getConfiguration().setMultiplexerStack(null);
|
82 |
| |
83 |
1
| checkStart(true, false);
|
84 |
| } |
85 |
| |
86 |
4
| private void checkStart(boolean expectFail, boolean expectMux)
|
87 |
| { |
88 |
4
| try
|
89 |
| { |
90 |
4
| cache.start();
|
91 |
2
| cacheStarted = true;
|
92 |
2
| if (expectFail)
|
93 |
| { |
94 |
0
| fail("Start did not fail as expected");
|
95 |
| } |
96 |
| |
97 |
2
| if (expectMux)
|
98 |
| { |
99 |
1
| assertTrue("Cache is using mux", cache.getConfiguration().isUsingMultiplexer());
|
100 |
| } |
101 |
| else |
102 |
| { |
103 |
1
| assertFalse("Cache is not using mux ", cache.getConfiguration().isUsingMultiplexer());
|
104 |
| } |
105 |
| } |
106 |
| catch (Exception e) |
107 |
| { |
108 |
2
| if (!expectFail)
|
109 |
| { |
110 |
0
| fail("Caught exception starting cache " + e.getLocalizedMessage());
|
111 |
| } |
112 |
| } |
113 |
| |
114 |
| } |
115 |
| } |