[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...
Brian Stansberry
brian.stansberry at jboss.com
Fri Nov 3 13:55:21 EST 2006
User: bstansberry
Date: 06/11/03 13:55:21
Added: tests/functional/org/jboss/cache/multiplexer Tag:
Branch_JBossCache_1_4_0 MuxChannelFactory.java
MuxChannelFactoryMBean.java
MultiplexerTestHelper.java
Log:
Add helper classes for multiplexer testing
Revision Changes Path
No revision
No revision
1.1.2.1 +61 -0 JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MuxChannelFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MuxChannelFactory.java
===================================================================
RCS file: MuxChannelFactory.java
diff -N MuxChannelFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MuxChannelFactory.java 3 Nov 2006 18:55:21 -0000 1.1.2.1
@@ -0,0 +1,61 @@
+package org.jboss.cache.multiplexer;
+
+import org.jgroups.Channel;
+import org.jgroups.JChannelFactory;
+import org.w3c.dom.Element;
+
+/**
+ * Delegates to a JChannelFactory but exposes a StandardMBean interface.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1.2.1 $
+ */
+public class MuxChannelFactory implements MuxChannelFactoryMBean
+{
+ private final JChannelFactory delegate;
+ private final Element muxConfig;
+
+ public MuxChannelFactory(JChannelFactory jChannelFactory, Element muxConfig) throws Exception
+ {
+ this.delegate = jChannelFactory;
+ delegate.setMultiplexerConfig(muxConfig);
+ this.muxConfig = muxConfig;
+ }
+
+ public Channel createMultiplexerChannel(String stack_name, String id) throws Exception
+ {
+ return delegate.createMultiplexerChannel(stack_name, id);
+ }
+
+ public Element getMultiplexerConfig()
+ {
+ return muxConfig;
+ }
+
+ public JChannelFactory getJChannelFactory()
+ {
+ return delegate;
+ }
+
+ public void create() throws Exception
+ {
+ delegate.create();
+ }
+
+ public void destroy() throws Exception
+ {
+ delegate.destroy();
+ }
+
+ public void start() throws Exception
+ {
+ delegate.start();
+ }
+
+ public void stop() throws Exception
+ {
+ delegate.stop();
+ }
+
+
+}
1.1.2.1 +22 -0 JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MuxChannelFactoryMBean.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MuxChannelFactoryMBean.java
===================================================================
RCS file: MuxChannelFactoryMBean.java
diff -N MuxChannelFactoryMBean.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MuxChannelFactoryMBean.java 3 Nov 2006 18:55:21 -0000 1.1.2.1
@@ -0,0 +1,22 @@
+package org.jboss.cache.multiplexer;
+
+import org.jgroups.Channel;
+import org.jgroups.JChannelFactory;
+import org.w3c.dom.Element;
+
+public interface MuxChannelFactoryMBean
+{
+ public Channel createMultiplexerChannel(String stack_name, String id) throws Exception;
+
+ public JChannelFactory getJChannelFactory();
+
+ public Element getMultiplexerConfig();
+
+ public void create() throws Exception;
+
+ public void start() throws Exception;
+
+ public void stop() throws Exception;
+
+ public void destroy() throws Exception;
+}
1.1.2.1 +189 -0 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: MultiplexerTestHelper.java
diff -N MultiplexerTestHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MultiplexerTestHelper.java 3 Nov 2006 18:55:21 -0000 1.1.2.1
@@ -0,0 +1,189 @@
+package org.jboss.cache.multiplexer;
+
+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.MalformedObjectNameException;
+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.TreeCacheMBean;
+import org.jgroups.JChannel;
+import org.jgroups.JChannelFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class MultiplexerTestHelper
+{
+ private static final Log log = LogFactory.getLog(MultiplexerTestHelper.class);
+
+ private static final String MUX_STACK = "jbc-test";
+ private static final ObjectName FACTORY_OBJECT_NAME;
+
+ static
+ {
+ try
+ {
+ FACTORY_OBJECT_NAME = new ObjectName("jboss.cache:service=JChannelFactory");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ private final MBeanServer mbeanServer;
+ private MuxChannelFactory muxFactory;
+ private final Set registeredCaches = Collections.synchronizedSet(new HashSet());
+
+
+ public MultiplexerTestHelper()
+ {
+ mbeanServer =
+ MBeanServerFactory.createMBeanServer("jboss");
+ }
+
+ public void configureCacheForMux(TreeCacheMBean cache) throws Exception
+ {
+ ObjectName on = new ObjectName("jboss.cache:service=TestCache,count=" + registeredCaches.size());
+ configureCacheForMux(cache, on);
+ }
+
+ public void configureCacheForMux(TreeCacheMBean cache, ObjectName cacheObjectName) throws Exception
+ {
+ cache.setMultiplexerService(FACTORY_OBJECT_NAME.getCanonicalName());
+ cache.setMultiplexerStack(MUX_STACK);
+
+ MBeanServer server = getMBeanServerWithMux(cache);
+ server.registerMBean(cache, cacheObjectName);
+ registeredCaches.add(cacheObjectName);
+ }
+
+ public MBeanServer getMBeanServerWithMux(TreeCacheMBean cache) throws Exception
+ {
+ return getMBeanServerWithMux(getClusterConfigElement(cache.getClusterProperties()));
+ }
+
+ public MBeanServer getMBeanServerWithMux(Element muxConfig) throws Exception
+ {
+ if (muxFactory == null)
+ {
+ JChannelFactory factory = new JChannelFactory();
+ factory.setDomain("jbc.mux.test");
+
+ muxFactory = new MuxChannelFactory(factory, muxConfig);
+ mbeanServer.registerMBean(muxFactory, FACTORY_OBJECT_NAME);
+
+ muxFactory.create();
+ muxFactory.start();
+ }
+// else if (!muxConfig.equals(muxFactory.getMultiplexerConfig()) )
+// {
+// throw new IllegalStateException("Inconsistent muxConfig");
+// }
+
+ return mbeanServer;
+ }
+
+ public static Element getClusterConfigElement(String clusterConfig) throws Exception
+ {
+ clusterConfig = clusterConfig.trim();
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = db.newDocument();
+ Element top = doc.createElement("protocol_stacks");
+ doc.appendChild(top);
+ Element stack = doc.createElement("stack");
+ stack.setAttribute("name", MUX_STACK);
+ top.appendChild(stack);
+ Element config = doc.createElement("config");
+
+ StringTokenizer outer = new StringTokenizer(clusterConfig, ":");
+ while (outer.hasMoreTokens())
+ {
+ String protocol = outer.nextToken();
+ String protName = protocol;
+ String attribs = null;
+ int nameEnd = protocol.indexOf('(');
+ if (nameEnd > 0)
+ {
+ protName = protocol.substring(0, nameEnd);
+ attribs = protocol.substring(nameEnd + 1, protocol.length() -1);
+ }
+ Element element = doc.createElement(protName);
+ if (attribs != null && attribs.length() > 0)
+ {
+ StringTokenizer inner = new StringTokenizer(attribs, ";");
+ while (inner.hasMoreTokens())
+ {
+ String attrib = inner.nextToken();
+ int eq = attrib.indexOf('=');
+ String name = attrib.substring(0, eq);
+ String value = attrib.substring(eq +1);
+ element.setAttribute(name, value);
+ }
+ }
+ config.appendChild(element);
+ }
+
+ stack.appendChild(config);
+ return top;
+ }
+
+ public void tearDown()
+ {
+ try
+ {
+ for (Iterator it = registeredCaches.iterator(); it.hasNext(); )
+ {
+ try
+ {
+ mbeanServer.unregisterMBean((ObjectName) it.next());
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ }
+
+ if (muxFactory != null)
+ {
+ muxFactory.stop();
+ muxFactory.destroy();
+ }
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ finally
+ {
+ if (mbeanServer != null)
+ MBeanServerFactory.releaseMBeanServer(mbeanServer);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ MultiplexerTestHelper helper = new MultiplexerTestHelper();
+ try
+ {
+ helper.getMBeanServerWithMux(getClusterConfigElement(JChannel.DEFAULT_PROTOCOL_STACK));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ helper.tearDown();
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list