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