[jboss-cvs] JBoss Messaging SVN: r2000 - in trunk: tests/etc and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jan 20 03:52:24 EST 2007
Author: ovidiu.feodorov at jboss.com
Date: 2007-01-20 03:52:23 -0500 (Sat, 20 Jan 2007)
New Revision: 2000
Added:
trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackTrigger.java
trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystem.java
trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemService.java
trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemServiceMBean.java
Modified:
trunk/messaging.ipr
trunk/tests/etc/log4j.xml
trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java
Log:
preparing http://jira.jboss.org/jira/browse/JBMESSAGING-699; modification required by task not checked in yet
Modified: trunk/messaging.ipr
===================================================================
--- trunk/messaging.ipr 2007-01-20 08:51:32 UTC (rev 1999)
+++ trunk/messaging.ipr 2007-01-20 08:52:23 UTC (rev 2000)
@@ -354,11 +354,11 @@
</library>
<library name="jboss-remoting">
<CLASSES>
- <root url="jar://$PROJECT_DIR$/thirdparty/jboss/remoting/lib/jboss-remoting.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/jboss-remoting.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="file://C:/work/src/cvs/JBossRemoting-2.2.0.Alpha5/src/main" />
+ <root url="file://C:/work/src/cvs/JBossRemoting-remoting_2_x/src/main" />
</SOURCES>
</library>
</component>
Modified: trunk/tests/etc/log4j.xml
===================================================================
--- trunk/tests/etc/log4j.xml 2007-01-20 08:51:32 UTC (rev 1999)
+++ trunk/tests/etc/log4j.xml 2007-01-20 08:52:23 UTC (rev 2000)
@@ -84,6 +84,10 @@
<priority value="DEBUG"/>
</category>
+ <category name="org.jboss.remoting">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
Added: trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackTrigger.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackTrigger.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackTrigger.java 2007-01-20 08:52:23 UTC (rev 2000)
@@ -0,0 +1,55 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class CallbackTrigger implements Serializable
+{
+ // Constants ------------------------------------------------------------------------------------
+
+ private static final long serialVersionUID = 2887545875458754L;
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private String payload;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public CallbackTrigger(String payload)
+ {
+ this.payload = payload;
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public String getPayload()
+ {
+ return payload;
+ }
+
+ public String toString()
+ {
+ return "CallbackTrigger[" + payload + "]";
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackTrigger.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Modified: trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java 2007-01-20 08:51:32 UTC (rev 1999)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java 2007-01-20 08:52:23 UTC (rev 2000)
@@ -8,29 +8,19 @@
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.logging.Logger;
-import org.jboss.remoting.transport.Connector;
import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
-import javax.naming.InitialContext;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Connection;
-import javax.jms.Session;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Message;
-import javax.jms.TextMessage;
-import javax.jms.MessageListener;
-import javax.management.MBeanServer;
+import javax.management.ObjectName;
-import EDU.oswego.cs.dl.util.concurrent.Slot;
+import EDU.oswego.cs.dl.util.concurrent.Channel;
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
/**
* A test case in which we play with "pure" remoting asynchronous calls.
@@ -51,6 +41,8 @@
// Attributes -----------------------------------------------------------------------------------
+ private InvokerLocator serverLocator;
+
// Constructors ---------------------------------------------------------------------------------
public PureAsynchronousCallTest(String name)
@@ -60,16 +52,88 @@
// Public ---------------------------------------------------------------------------------------
- public void testPureAsynchronousCall() throws Exception
+ public void testAsynchronousDirectCall() throws Throwable
{
if (!isRemote())
{
fail("This test should be run in a remote configuration!");
}
- log.debug("I am here");
+ Client client = null;
+ ObjectName subsystemService = null;
+
+ try
+ {
+ subsystemService = RemotingTestSubsystemService.deployService();
+
+ client = new Client(serverLocator, RemotingTestSubsystemService.SUBSYSTEM_LABEL);
+
+ client.connect();
+
+ client.invokeOneway("blip");
+
+ // make sure invocation reached the target subsystem
+
+ InvocationRequest i = getNextInvocationFromServer(subsystemService, 2000);
+
+ assertNotNull(i);
+ assertEquals("blip", i.getParameter());
+ }
+ finally
+ {
+ if (client != null)
+ {
+ client.disconnect();
+ }
+
+ RemotingTestSubsystemService.undeployService(subsystemService);
+ }
}
+ public void testAsynchronousCallback() throws Throwable
+ {
+ if (!isRemote())
+ {
+ fail("This test should be run in a remote configuration!");
+ }
+
+ Client client = null;
+ ObjectName subsystemService = null;
+ SimpleCallbackHandler callbackHandler = null;
+
+ try
+ {
+ subsystemService = RemotingTestSubsystemService.deployService();
+
+ client = new Client(serverLocator, RemotingTestSubsystemService.SUBSYSTEM_LABEL);
+
+ callbackHandler = new SimpleCallbackHandler();
+
+ client.connect();
+
+ client.addListener(callbackHandler, null, null, true);
+
+ client.invoke(new CallbackTrigger("blop"));
+
+ // make sure we get the callback
+
+ Callback c = callbackHandler.getNextCallback(3000);
+
+ assertNotNull(c);
+ assertEquals("blop", c.getParameter());
+ }
+ finally
+ {
+ if (client != null)
+ {
+ client.disconnect();
+ }
+
+ RemotingTestSubsystemService.undeployService(subsystemService);
+ }
+ }
+
+
// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
@@ -80,11 +144,18 @@
ServerManagement.start(0, "remoting", null, true, false);
+ String s = (String)ServerManagement.
+ getAttribute(ServiceContainer.REMOTING_OBJECT_NAME, "InvokerLocator");
+
+ serverLocator = new InvokerLocator(s);
+
log.debug("setup done");
}
protected void tearDown() throws Exception
{
+ serverLocator = null;
+
ServerManagement.stop();
super.tearDown();
@@ -92,6 +163,43 @@
// Private --------------------------------------------------------------------------------------
+ private InvocationRequest getNextInvocationFromServer(ObjectName on, long timeout)
+ throws Exception
+ {
+ return (InvocationRequest)ServerManagement.
+ invoke(on, "nextInvocation",
+ new Object[] { new Long(timeout) },
+ new String[] { "java.lang.Long" });
+ }
+
+
// Inner classes --------------------------------------------------------------------------------
+ private class SimpleCallbackHandler implements InvokerCallbackHandler
+ {
+ private Channel callbackHistory;
+
+ public SimpleCallbackHandler()
+ {
+ callbackHistory = new LinkedQueue();
+ }
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ try
+ {
+ callbackHistory.put(callback);
+ }
+ catch(InterruptedException e)
+ {
+ throw new HandleCallbackException("Got InterruptedException", e);
+ }
+ }
+
+ public Callback getNextCallback(long timeout) throws InterruptedException
+ {
+ return (Callback)callbackHistory.poll(timeout);
+ }
+ }
+
}
Added: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystem.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystem.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystem.java 2007-01-20 08:52:23 UTC (rev 2000)
@@ -0,0 +1,134 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting;
+
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.logging.Logger;
+
+import javax.management.MBeanServer;
+import java.io.Serializable;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+import EDU.oswego.cs.dl.util.concurrent.Channel;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class RemotingTestSubsystem implements ServerInvocationHandler, Serializable
+{
+ // Constants ------------------------------------------------------------------------------------
+
+ private static final long serialVersionUID = 5457454557215715L;
+
+ private static final Logger log = Logger.getLogger(RemotingTestSubsystem.class);
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private Channel invocationHistory;
+ private List callbackListeners;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public RemotingTestSubsystem()
+ {
+ invocationHistory = new LinkedQueue();
+ callbackListeners = new ArrayList();
+ }
+
+ // ServerInvocationHandler implementation -------------------------------------------------------
+
+ public void setMBeanServer(MBeanServer server)
+ {
+ }
+
+ public void setInvoker(ServerInvoker invoker)
+ {
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ log.debug(this + " received " + invocation);
+
+ invocationHistory.put(invocation);
+
+ Object parameter = invocation.getParameter();
+
+ if (parameter instanceof CallbackTrigger)
+ {
+ Callback callback = new Callback(((CallbackTrigger)parameter).getPayload());
+
+ // seding a callback asynchronously
+ pushToClient(callback, false);
+ }
+
+ return null;
+ }
+
+ public synchronized void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ callbackListeners.add(callbackHandler);
+ }
+
+ public synchronized void removeListener(InvokerCallbackHandler callbackHandler)
+ {
+ callbackListeners.remove(callbackHandler);
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public InvocationRequest getNextInvocation(long timeout) throws InterruptedException
+ {
+ return (InvocationRequest)invocationHistory.poll(timeout);
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ private synchronized void pushToClient(Callback callback, boolean sendSynchronously)
+ {
+ for(Iterator i = callbackListeners.iterator(); i.hasNext(); )
+ {
+ ServerInvokerCallbackHandler h = (ServerInvokerCallbackHandler)i.next();
+ try
+ {
+ if (sendSynchronously)
+ {
+ log.debug("pushing synchronous callback to " + h);
+ h.handleCallback(callback);
+
+ }
+ else
+ {
+ log.debug("pushing asynchronous callback to " + h);
+ h.handleCallbackOneway(callback);
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("Sending callback failed", e);
+ }
+ }
+ }
+
+ // Inner classes --------------------------------------------------------------------------------
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystem.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Added: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemService.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemService.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemService.java 2007-01-20 08:52:23 UTC (rev 2000)
@@ -0,0 +1,148 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.messaging.tools.jmx.ServiceContainer;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.remoting.InvocationRequest;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.MBeanRegistration;
+
+/**
+ * A standard MBean service to be used when testing remoting.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class RemotingTestSubsystemService
+ implements MBeanRegistration, RemotingTestSubsystemServiceMBean
+{
+ // Constants ------------------------------------------------------------------------------------
+
+ private static final Logger log = Logger.getLogger(RemotingTestSubsystemService.class);
+
+ public static final String SUBSYSTEM_LABEL = "TEST_SUBSYSTEM";
+
+ // Static ---------------------------------------------------------------------------------------
+
+ public static ObjectName deployService() throws Exception
+ {
+ String testSubsystemConfig =
+ "<mbean code=\"org.jboss.test.thirdparty.remoting.RemotingTestSubsystemService\"\n" +
+ " name=\"test:service=RemotingTestSubsystem\">\n" +
+ "</mbean>";
+
+ ObjectName on = ServerManagement.deploy(testSubsystemConfig);
+ ServerManagement.invoke(on, "start", new Object[0], new String[0]);
+
+ return on;
+ }
+
+ public static void undeployService(ObjectName on) throws Exception
+ {
+ ServerManagement.invoke(on, "stop", new Object[0], new String[0]);
+ ServerManagement.undeploy(on);
+ }
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private MBeanServer mbeanServer;
+ private ObjectName myObjectName;
+
+ private RemotingTestSubsystem delegate;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ // MBeanRegistration implementation -------------------------------------------------------------
+
+ public ObjectName preRegister(MBeanServer mbeanServer, ObjectName objectName) throws Exception
+ {
+ this.mbeanServer = mbeanServer;
+ this.myObjectName = objectName;
+ return objectName;
+ }
+
+ public void postRegister(Boolean b)
+ {
+ // noop
+ }
+
+ public void preDeregister() throws Exception
+ {
+ // noop
+ }
+
+ public void postDeregister()
+ {
+ // noop
+ }
+
+ // RemotingTestSubsystemServiceMBean implementation ---------------------------------------------
+
+ public void start() throws Exception
+ {
+ // register to the remoting connector
+
+ delegate = new RemotingTestSubsystem();
+
+ mbeanServer.invoke(ServiceContainer.REMOTING_OBJECT_NAME,
+ "addInvocationHandler",
+ new Object[] {SUBSYSTEM_LABEL, delegate},
+ new String[] {"java.lang.String",
+ "org.jboss.remoting.ServerInvocationHandler"});
+
+ log.debug(myObjectName + " started");
+ }
+
+ public void stop()
+ {
+ try
+ {
+ // unregister from the remoting connector
+
+ mbeanServer.invoke(ServiceContainer.REMOTING_OBJECT_NAME,
+ "removeInvocationHandler",
+ new Object[] {SUBSYSTEM_LABEL},
+ new String[] {"java.lang.String"});
+ }
+ catch(Exception e)
+ {
+ log.error("Cannot deinstall remoting subsystem", e);
+ }
+
+ delegate = null;
+
+ log.debug(myObjectName + " stopped");
+ }
+
+ public InvocationRequest nextInvocation(Long timeout) throws Exception
+ {
+ if (delegate == null)
+ {
+ return null;
+ }
+
+ return delegate.getNextInvocation(timeout.longValue());
+
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemService.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Added: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemServiceMBean.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemServiceMBean.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemServiceMBean.java 2007-01-20 08:52:23 UTC (rev 2000)
@@ -0,0 +1,22 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting;
+
+import org.jboss.remoting.InvocationRequest;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ * $Id$
+ */
+public interface RemotingTestSubsystemServiceMBean
+{
+ void start() throws Exception;
+ void stop();
+
+ InvocationRequest nextInvocation(Long timeout) throws Exception;
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/RemotingTestSubsystemServiceMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
More information about the jboss-cvs-commits
mailing list