[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...
Brian Stansberry
brian.stansberry at jboss.com
Wed May 9 14:32:55 EDT 2007
User: bstansberry
Date: 07/05/09 14:32:55
Modified: tests/functional/org/jboss/cache/multiplexer
BadMuxConfigTest.java MultiplexerTestHelper.java
Log:
[JBCACHE--1044] RuntimeConfig's channel factory should by type ChannelFactory, not JChannelFactoryMBean
Revision Changes Path
1.5 +6 -55 JBossCache/tests/functional/org/jboss/cache/multiplexer/BadMuxConfigTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BadMuxConfigTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/multiplexer/BadMuxConfigTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- BadMuxConfigTest.java 11 Jan 2007 13:49:22 -0000 1.4
+++ BadMuxConfigTest.java 9 May 2007 18:32:55 -0000 1.5
@@ -1,21 +1,18 @@
package org.jboss.cache.multiplexer;
import junit.framework.TestCase;
+
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jgroups.JChannel;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
/**
* 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.4 $
+ * @version $Revision: 1.5 $
*/
public class BadMuxConfigTest extends TestCase
{
@@ -63,56 +60,10 @@
checkStart(false, true);
}
- public void testMuxConfigViaInjection() throws Exception
- {
- muxHelper.configureCacheForMuxViaDirectInjection(cache);
-
- checkStart(false, true);
- }
-
- public void testWrongMBeanServer() throws Exception
- {
- ObjectName on = muxHelper.createMuxChannelFactory(cache.getConfiguration().getClusterConfig());
- cache.getConfiguration().setMultiplexerService(on.getCanonicalName());
- cache.getConfiguration().setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
-
- MBeanServer wrong =
- MBeanServerFactory.createMBeanServer("wrong");
- try
- {
- cache.getConfiguration().getRuntimeConfig().setMbeanServer(wrong);
- checkStart(false, false);
- }
- finally
- {
- MBeanServerFactory.releaseMBeanServer(wrong);
- }
- }
-
- public void testBadMuxServiceName() throws Exception
- {
- muxHelper.configureCacheForMux(cache);
- // This creates a non-conformant ObjectName
- String badName = cache.getConfiguration().getMultiplexerService() + ",bad";
- cache.getConfiguration().setMultiplexerService(badName);
-
- checkStart(false, false);
- }
-
- public void testInvalidMuxServiceName() throws Exception
+ public void testMissingMuxChannelFactory() throws Exception
{
muxHelper.configureCacheForMux(cache);
- // This is a valid but non-existent ObjectName
- String badName = cache.getConfiguration().getMultiplexerService() + ",type=invalid";
- cache.getConfiguration().setMultiplexerService(badName);
-
- checkStart(false, false);
- }
-
- public void testMissingMuxServiceName() throws Exception
- {
- muxHelper.configureCacheForMux(cache);
- cache.getConfiguration().setMultiplexerService(null);
+ cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(null);
checkStart(false, false);
}
@@ -122,7 +73,7 @@
muxHelper.configureCacheForMux(cache);
cache.getConfiguration().setMultiplexerStack("bogus");
- checkStart(false, false);
+ checkStart(true, false);
}
public void testMissingStackName() throws Exception
@@ -130,7 +81,7 @@
muxHelper.configureCacheForMux(cache);
cache.getConfiguration().setMultiplexerStack(null);
- checkStart(false, false);
+ checkStart(true, false);
}
private void checkStart(boolean expectFail, boolean expectMux)
1.3 +20 -127 JBossCache/tests/functional/org/jboss/cache/multiplexer/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/MultiplexerTestHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- MultiplexerTestHelper.java 3 Jan 2007 04:03:47 -0000 1.2
+++ MultiplexerTestHelper.java 9 May 2007 18:32:55 -0000 1.3
@@ -23,48 +23,36 @@
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
+import org.jgroups.ChannelFactory;
import org.jgroups.JChannel;
import org.jgroups.JChannelFactory;
-import org.jgroups.jmx.JChannelFactoryMBean;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
- * Utility class that can associate a cache with a JMX server and a
- * a JGroups JChannelFactory.
+ * Utility class that can associate a cache with a multiplexer-enabled
+ * JGroups ChannelFactory.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class MultiplexerTestHelper
{
- private static final Log log = LogFactory.getLog(MultiplexerTestHelper.class);
-
public static final String MUX_STACK = "jbc-test";
- private static final String FACTORY_OBJECT_NAME_BASE = "jboss.cache:service=MuxChannelFactory,count=";
- private MBeanServer mbeanServer;
private final Set factories = Collections.synchronizedSet(new HashSet());
private final Set caches = Collections.synchronizedSet(new HashSet());
public MultiplexerTestHelper()
{
- mbeanServer =
- MBeanServerFactory.createMBeanServer();
}
/**
@@ -73,57 +61,31 @@
* produce MuxChannels configured with the same protocol stack as
* whatever the provided cache is configured with.
*
- * @param cache
+ * @param cache the cache
* @throws Exception
*/
public void configureCacheForMux(Cache cache) throws Exception
{
synchronized (caches)
{
- ObjectName on = createMuxChannelFactory(cache);
- cache.getConfiguration().setMultiplexerService(on.getCanonicalName());
- cache.getConfiguration().setMultiplexerStack(MUX_STACK);
- cache.getConfiguration().getRuntimeConfig().setMbeanServer(mbeanServer);
-// ObjectName cacheON = new ObjectName("jboss.cache:service=TestCache,count=" + caches.size());
-// mbeanServer.registerMBean(cache, cacheON);
-// caches.add(cacheON);
- }
- }
-
- /**
- * Configures the given cache to get its JChannel from a
- * multiplexer-enabled JChannelFactory. The JChannelFactory will
- * produce MuxChannels configured with the same protocol stack as
- * whatever the provided cache is configured with.
- *
- * @param cache
- * @throws Exception
- */
- public void configureCacheForMuxViaDirectInjection(Cache cache) throws Exception
- {
- synchronized (caches)
- {
- String props = getChannelProperties(cache);
-
- JChannelFactoryMBean mbean = (JChannelFactoryMBean) createMuxChannelFactory(props, false);
- cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(mbean);
+ ChannelFactory factory = createMuxChannelFactory(cache);
+ cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(factory);
cache.getConfiguration().setMultiplexerStack(MUX_STACK);
}
}
/**
- * Creates a JChannelFactory and binds it to this object's
- * internal MBeanServer. The JChannelFactory will
+ * Creates a JChannelFactory. The JChannelFactory will
* produce MuxChannels configured with the same protocol stack as
* whatever the provided cache is configured with.
*
* @param cache the cache from which the protocol stack config should
* be obtained
*
- * @return the ObjectName of the channel factory.
+ * @return the channel factory.
* @throws Exception
*/
- public ObjectName createMuxChannelFactory(Cache cache) throws Exception
+ public ChannelFactory createMuxChannelFactory(Cache cache) throws Exception
{
return createMuxChannelFactory(getChannelProperties(cache));
}
@@ -135,24 +97,17 @@
}
/**
- * Creates a JChannelFactory and binds it to this object's
- * internal MBeanServer. The JChannelFactory will
- * produce MuxChannels configured with according to the given
+ * Creates a JChannelFactory. The JChannelFactory will
+ * produce MuxChannels configured 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.
+ * @return the channel factory.
* @throws Exception
*/
- public ObjectName createMuxChannelFactory(String muxConfig) throws Exception
- {
- return (ObjectName) createMuxChannelFactory(muxConfig, true);
- }
-
- private Object createMuxChannelFactory(String muxConfig, boolean returnObjectName)
- throws Exception
+ public ChannelFactory createMuxChannelFactory(String muxConfig) throws Exception
{
synchronized (factories)
{
@@ -161,17 +116,9 @@
factory.setExposeChannels(false);
factory.setMultiplexerConfig(getClusterConfigElement(muxConfig));
- JChannelFactoryMBean muxFactory = new org.jgroups.jmx.JChannelFactory(factory);
- // Give the factory a unique ObjectName
- ObjectName on = new ObjectName(FACTORY_OBJECT_NAME_BASE + factories.size());
- mbeanServer.registerMBean(muxFactory, on);
-
- factories.add(on);
+ factories.add(factory);
- muxFactory.create();
- muxFactory.start();
-
- return returnObjectName ? on : muxFactory;
+ return factory;
}
}
@@ -228,67 +175,13 @@
}
/**
- * Performs cleanup work, most importantly unregistering the
- * internal MBeanServer. Once this method is invoked, this
+ * Performs cleanup work. Once this method is invoked, this
* object should no longer be used.
*/
public void tearDown()
{
- try
- {
- for (Iterator it = caches.iterator(); it.hasNext(); )
- {
- try
- {
- mbeanServer.unregisterMBean((ObjectName) it.next());
- }
- catch (Exception e)
- {
- log.error(e);
- }
- }
-
- for (Iterator it = factories.iterator(); it.hasNext(); )
- {
- try
- {
- mbeanServer.unregisterMBean((ObjectName) it.next());
- }
- catch (Exception e)
- {
- log.error(e);
- }
- }
- }
- catch (Exception e)
- {
- log.error(e);
- }
- finally
- {
factories.clear();
caches.clear();
-
- if (mbeanServer != null)
- {
- MBeanServerFactory.releaseMBeanServer(mbeanServer);
- mbeanServer = null;
- }
-
-
- }
- }
-
- /**
- * Makes sure the internal MBeanServer is unregistered.
- */
- protected void finalize() throws Throwable
- {
- if (mbeanServer != null)
- {
- MBeanServerFactory.releaseMBeanServer(mbeanServer);
- }
- super.finalize();
}
/**
More information about the jboss-cvs-commits
mailing list