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 |
| import javax.management.MBeanServer; |
10 |
| import javax.management.MBeanServerFactory; |
11 |
| import javax.management.ObjectName; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class BadMuxConfigTest extends TestCase |
21 |
| { |
22 |
| private MultiplexerTestHelper muxHelper; |
23 |
| private Cache cache; |
24 |
| private boolean cacheStarted; |
25 |
| |
26 |
8
| protected void setUp() throws Exception
|
27 |
| { |
28 |
8
| muxHelper = new MultiplexerTestHelper();
|
29 |
8
| Configuration config = new Configuration();
|
30 |
8
| config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
|
31 |
8
| config.setClusterConfig(JChannel.DEFAULT_PROTOCOL_STACK);
|
32 |
8
| cache = DefaultCacheFactory.getInstance().createCache(config, false);
|
33 |
8
| cacheStarted = false;
|
34 |
| |
35 |
8
| super.setUp();
|
36 |
| } |
37 |
| |
38 |
8
| public void tearDown() throws Exception
|
39 |
| { |
40 |
8
| try
|
41 |
| { |
42 |
8
| super.tearDown();
|
43 |
8
| if (cacheStarted && cache != null)
|
44 |
| { |
45 |
8
| cache.stop();
|
46 |
8
| cache.destroy();
|
47 |
| } |
48 |
| } |
49 |
| finally |
50 |
| { |
51 |
8
| if (muxHelper != null)
|
52 |
| { |
53 |
8
| muxHelper.tearDown();
|
54 |
8
| muxHelper = null;
|
55 |
| } |
56 |
| } |
57 |
| } |
58 |
| |
59 |
1
| public void testValidMuxConfig() throws Exception
|
60 |
| { |
61 |
1
| muxHelper.configureCacheForMux(cache);
|
62 |
| |
63 |
1
| checkStart(false, true);
|
64 |
| } |
65 |
| |
66 |
1
| public void testMuxConfigViaInjection() throws Exception
|
67 |
| { |
68 |
1
| muxHelper.configureCacheForMuxViaDirectInjection(cache);
|
69 |
| |
70 |
1
| checkStart(false, true);
|
71 |
| } |
72 |
| |
73 |
1
| public void testWrongMBeanServer() throws Exception
|
74 |
| { |
75 |
1
| ObjectName on = muxHelper.createMuxChannelFactory(cache.getConfiguration().getClusterConfig());
|
76 |
1
| cache.getConfiguration().setMultiplexerService(on.getCanonicalName());
|
77 |
1
| cache.getConfiguration().setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
|
78 |
| |
79 |
1
| MBeanServer wrong =
|
80 |
| MBeanServerFactory.createMBeanServer("wrong"); |
81 |
1
| try
|
82 |
| { |
83 |
1
| cache.getConfiguration().getRuntimeConfig().setMbeanServer(wrong);
|
84 |
1
| checkStart(false, false);
|
85 |
| } |
86 |
| finally |
87 |
| { |
88 |
1
| MBeanServerFactory.releaseMBeanServer(wrong);
|
89 |
| } |
90 |
| } |
91 |
| |
92 |
1
| public void testBadMuxServiceName() throws Exception
|
93 |
| { |
94 |
1
| muxHelper.configureCacheForMux(cache);
|
95 |
| |
96 |
1
| String badName = cache.getConfiguration().getMultiplexerService() + ",bad";
|
97 |
1
| cache.getConfiguration().setMultiplexerService(badName);
|
98 |
| |
99 |
1
| checkStart(false, false);
|
100 |
| } |
101 |
| |
102 |
1
| public void testInvalidMuxServiceName() throws Exception
|
103 |
| { |
104 |
1
| muxHelper.configureCacheForMux(cache);
|
105 |
| |
106 |
1
| String badName = cache.getConfiguration().getMultiplexerService() + ",type=invalid";
|
107 |
1
| cache.getConfiguration().setMultiplexerService(badName);
|
108 |
| |
109 |
1
| checkStart(false, false);
|
110 |
| } |
111 |
| |
112 |
1
| public void testMissingMuxServiceName() throws Exception
|
113 |
| { |
114 |
1
| muxHelper.configureCacheForMux(cache);
|
115 |
1
| cache.getConfiguration().setMultiplexerService(null);
|
116 |
| |
117 |
1
| checkStart(false, false);
|
118 |
| } |
119 |
| |
120 |
1
| public void testInvalidStackName() throws Exception
|
121 |
| { |
122 |
1
| muxHelper.configureCacheForMux(cache);
|
123 |
1
| cache.getConfiguration().setMultiplexerStack("bogus");
|
124 |
| |
125 |
1
| checkStart(false, false);
|
126 |
| } |
127 |
| |
128 |
1
| public void testMissingStackName() throws Exception
|
129 |
| { |
130 |
1
| muxHelper.configureCacheForMux(cache);
|
131 |
1
| cache.getConfiguration().setMultiplexerStack(null);
|
132 |
| |
133 |
1
| checkStart(false, false);
|
134 |
| } |
135 |
| |
136 |
8
| private void checkStart(boolean expectFail, boolean expectMux)
|
137 |
| { |
138 |
8
| try
|
139 |
| { |
140 |
8
| cache.start();
|
141 |
8
| cacheStarted = true;
|
142 |
8
| if (expectFail)
|
143 |
| { |
144 |
0
| fail("Start did not fail as expected");
|
145 |
| } |
146 |
| |
147 |
8
| if (expectMux)
|
148 |
| { |
149 |
2
| assertTrue("Cache is using mux", cache.getConfiguration().isUsingMultiplexer());
|
150 |
| } |
151 |
| else |
152 |
| { |
153 |
6
| assertFalse("Cache is not using mux ", cache.getConfiguration().isUsingMultiplexer());
|
154 |
| } |
155 |
| } |
156 |
| catch (Exception e) |
157 |
| { |
158 |
0
| if (!expectFail)
|
159 |
| { |
160 |
0
| fail("Caught exception starting cache " + e.getLocalizedMessage());
|
161 |
| } |
162 |
| } |
163 |
| |
164 |
| } |
165 |
| } |