[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...
Brian Stansberry
brian.stansberry at jboss.com
Sat Nov 4 00:31:38 EST 2006
User: bstansberry
Date: 06/11/04 00:31:38
Modified: tests/functional/org/jboss/cache/multiplexer Tag:
Branch_JBossCache_1_4_0 MultiplexerTestHelper.java
Added: tests/functional/org/jboss/cache/multiplexer Tag:
Branch_JBossCache_1_4_0 BadMuxConfigTest.java
Log:
Add tests that the cache starts with various broken mux configs
Revision Changes Path
No revision
No revision
1.1.2.5 +16 -3 JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MultiplexerTestHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MultiplexerTestHelper.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MultiplexerTestHelper.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- MultiplexerTestHelper.java 4 Nov 2006 04:49:46 -0000 1.1.2.4
+++ MultiplexerTestHelper.java 4 Nov 2006 05:31:38 -0000 1.1.2.5
@@ -46,13 +46,13 @@
* a JGroups JChannelFactory.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision: 1.1.2.4 $
+ * @version $Revision: 1.1.2.5 $
*/
public class MultiplexerTestHelper
{
private static final Log log = LogFactory.getLog(MultiplexerTestHelper.class);
- private static final String MUX_STACK = "jbc-test";
+ public static final String MUX_STACK = "jbc-test";
private static final String FACTORY_OBJECT_NAME_BASE = "jboss.cache:service=MuxChannelFactory,count=";
private MBeanServer mbeanServer;
@@ -108,7 +108,20 @@
return createMuxChannelFactory(getClusterConfigElement(props));
}
- private ObjectName createMuxChannelFactory(Element muxConfig) throws Exception
+
+ /**
+ * Creates a JChannelFactory and binds it to this object's
+ * internal MBeanServer. The JChannelFactory will
+ * produce MuxChannels configured with according to the given
+ * protocol stack(s).
+ *
+ * @param muxConfig Element that looks like the root element
+ * of a multiplexer stacks.xml file.
+ *
+ * @return the ObjectName of the channel factory.
+ * @throws Exception
+ */
+ public ObjectName createMuxChannelFactory(Element muxConfig) throws Exception
{
synchronized (factories)
{
No revision
No revision
1.1.2.1 +150 -0 JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/BadMuxConfigTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BadMuxConfigTest.java
===================================================================
RCS file: BadMuxConfigTest.java
diff -N BadMuxConfigTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BadMuxConfigTest.java 4 Nov 2006 05:31:38 -0000 1.1.2.1
@@ -0,0 +1,150 @@
+package org.jboss.cache.multiplexer;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import org.jboss.cache.TreeCache;
+import org.jgroups.JChannel;
+import org.w3c.dom.Element;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests that JBC starts correctly even if the multiplexer
+ * configuration is incorrect.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1.2.1 $
+ */
+public class BadMuxConfigTest extends TestCase
+{
+ private MultiplexerTestHelper muxHelper;
+ private TreeCache cache;
+ private boolean cacheStarted;
+
+ protected void setUp() throws Exception
+ {
+ muxHelper = new MultiplexerTestHelper();
+ cache = new TreeCache();
+ cache.setCacheMode("REPL_SYNC");
+ cache.setClusterProperties(JChannel.DEFAULT_PROTOCOL_STACK);
+ cacheStarted = false;
+
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ if (cacheStarted && cache != null)
+ {
+ cache.stopService();
+ cache.destroyService();
+ }
+ }
+ finally
+ {
+ if (muxHelper != null)
+ {
+ muxHelper.tearDown();
+ muxHelper = null;
+ }
+ }
+ }
+
+ public void testValidMuxConfig() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+
+ checkStart(false, true);
+ }
+
+ public void testWrongMBeanServer() throws Exception
+ {
+ Element el = MultiplexerTestHelper.getClusterConfigElement(cache.getClusterProperties());
+ ObjectName on = muxHelper.createMuxChannelFactory(el);
+ cache.setMultiplexerService(on.getCanonicalName());
+ cache.setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
+
+ MBeanServer wrong =
+ MBeanServerFactory.createMBeanServer("wrong");
+ try
+ {
+ wrong.registerMBean(cache, new ObjectName("jboss.cache:service=MuxTest"));
+ checkStart(false, false);
+ }
+ finally
+ {
+ MBeanServerFactory.releaseMBeanServer(wrong);
+ }
+ }
+
+ public void testBadMuxServiceName() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+ // This creates a non-conformant ObjectName
+ String badName = cache.getMultiplexerService() + ",bad";
+ cache.setMultiplexerService(badName);
+
+ checkStart(false, false);
+ }
+
+ public void testInvalidMuxServiceName() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+ // This is a valid but non-existent ObjectName
+ String badName = cache.getMultiplexerService() + ",type=invalid";
+ cache.setMultiplexerService(badName);
+
+ checkStart(false, false);
+ }
+
+ public void testMissingMuxServiceName() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+ cache.setMultiplexerService(null);
+
+ checkStart(false, false);
+ }
+
+ public void testInvalidStackName() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+ cache.setMultiplexerStack("bogus");
+
+ checkStart(false, false);
+ }
+
+ public void testMissingStackName() throws Exception
+ {
+ muxHelper.configureCacheForMux(cache);
+ cache.setMultiplexerStack(null);
+
+ checkStart(false, false);
+ }
+
+ private void checkStart(boolean expectFail, boolean expectMux)
+ {
+ try
+ {
+ cache.startService();
+ cacheStarted = true;
+ if (expectFail)
+ fail("Start did not fail as expected");
+
+ if (expectMux)
+ assertTrue("Cache is using mux", cache.isUsingMultiplexer());
+ else
+ assertFalse("Cache is not using mux ", cache.isUsingMultiplexer());
+ }
+ catch (Exception e)
+ {
+ if (!expectFail)
+ fail("Caught exception starting cache " + e.getLocalizedMessage());
+ }
+
+ }
+}
More information about the jboss-cvs-commits
mailing list