[jboss-cvs] JBoss Messaging SVN: r2052 - in trunk/tests: src/org/jboss/test/thirdparty/remoting and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 25 06:19:00 EST 2007
Author: ovidiu.feodorov at jboss.com
Date: 2007-01-25 06:19:00 -0500 (Thu, 25 Jan 2007)
New Revision: 2052
Added:
trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java
trunk/tests/src/org/jboss/test/thirdparty/remoting/util/OnewayCallbackTrigger.java
Removed:
trunk/tests/src/org/jboss/test/thirdparty/remoting/util/CallbackTrigger.java
Modified:
trunk/tests/build.xml
trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java
trunk/tests/src/org/jboss/test/thirdparty/remoting/util/RemotingTestSubsystem.java
Log:
two more tests that fail because of the same thing that causes http://jira.jboss.org/jira/browse/JBMESSAGING-371
Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml 2007-01-25 11:09:31 UTC (rev 2051)
+++ trunk/tests/build.xml 2007-01-25 11:19:00 UTC (rev 2052)
@@ -421,6 +421,7 @@
<exclude name="**/thirdparty/remoting/ManualConnectionValidatorTest.class"/>
<exclude name="**/thirdparty/remoting/PureAsynchronousCallTest.class"/>
<exclude name="**/thirdparty/remoting/RemotingConnectionFailureTest.class"/>
+ <exclude name="**/thirdparty/remoting/CallbackServerTimeoutTest.class"/>
</fileset>
</batchtest>
</junit>
Added: trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.java 2007-01-25 11:19:00 UTC (rev 2052)
@@ -0,0 +1,245 @@
+/**
+ * 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.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.ServiceContainer;
+import org.jboss.test.thirdparty.remoting.util.RemotingTestSubsystemService;
+import org.jboss.test.thirdparty.remoting.util.OnewayCallbackTrigger;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.HandleCallbackException;
+
+import javax.management.ObjectName;
+
+import EDU.oswego.cs.dl.util.concurrent.Channel;
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+
+/**
+ * An extra test for the same root problem that causes
+ * http://jira.jboss.org/jira/browse/JBMESSAGING-371. The callback server seems to timeout never
+ * to be heard from it again.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class CallbackServerTimeoutTest extends MessagingTestCase
+{
+ // Constants ------------------------------------------------------------------------------------
+
+ private static final Logger log = Logger.getLogger(CallbackServerTimeoutTest.class);
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private InvokerLocator serverLocator;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public CallbackServerTimeoutTest(String name)
+ {
+ super(name);
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public void testTimeoutOnewayCallback() throws Throwable
+ {
+ if (!isRemote())
+ {
+ fail("This test should be run in a remote configuration!");
+ }
+
+ Client client = null;
+ ObjectName subsystemService = null;
+ CallbackServerTimeoutTest.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 OnewayCallbackTrigger("blip"));
+
+ // make sure we get the callback
+
+ Callback c = callbackHandler.getNextCallback(3000);
+
+ assertNotNull(c);
+ assertEquals("blip", c.getParameter());
+
+ // sleep for twice the timeout, to be sure
+ long sleepTime = ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 60000;
+ log.info("sleeping for " + (sleepTime / 60000) + " minutes ...");
+
+ Thread.sleep(sleepTime);
+
+ log.debug("woke up");
+
+ client.invoke(new OnewayCallbackTrigger("blop"));
+
+ // make sure we get the callback
+
+ c = callbackHandler.getNextCallback(3000);
+
+ assertNotNull(c);
+ assertEquals("blop", c.getParameter());
+
+ }
+ finally
+ {
+ if (client != null)
+ {
+ client.disconnect();
+ }
+
+ RemotingTestSubsystemService.undeployService(subsystemService);
+ }
+ }
+
+ public void testTimeoutOnewayCallback2() throws Throwable
+ {
+ if (!isRemote())
+ {
+ fail("This test should be run in a remote configuration!");
+ }
+
+ Client client = null;
+ ObjectName subsystemService = null;
+ CallbackServerTimeoutTest.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);
+
+ log.info("added listener");
+
+ // sleep for twice the timeout, to be sure
+ long sleepTime = ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 60000;
+
+ client.invoke(new OnewayCallbackTrigger("blip", new long[] { 0, sleepTime + 10000 }));
+
+ log.info("sent invocation");
+
+ // make sure we get the callback
+
+ Callback c = callbackHandler.getNextCallback(3000);
+
+ assertNotNull(c);
+ assertEquals("blip", c.getParameter());
+
+ log.info("sleeping for " + (sleepTime / 60000) + " minutes ...");
+
+ Thread.sleep(sleepTime);
+
+ log.debug("woke up");
+
+ // make sure we get the second callback
+
+ c = callbackHandler.getNextCallback(20000);
+
+ assertNotNull(c);
+ assertEquals("blip1", c.getParameter());
+
+ }
+ finally
+ {
+ if (client != null)
+ {
+ client.disconnect();
+ }
+
+ RemotingTestSubsystemService.undeployService(subsystemService);
+ }
+ }
+
+
+
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ 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();
+ }
+
+ // Private --------------------------------------------------------------------------------------
+
+ // 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);
+ }
+ }
+
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/CallbackServerTimeoutTest.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-25 11:09:31 UTC (rev 2051)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/PureAsynchronousCallTest.java 2007-01-25 11:19:00 UTC (rev 2052)
@@ -9,7 +9,7 @@
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
-import org.jboss.test.thirdparty.remoting.util.CallbackTrigger;
+import org.jboss.test.thirdparty.remoting.util.OnewayCallbackTrigger;
import org.jboss.test.thirdparty.remoting.util.RemotingTestSubsystemService;
import org.jboss.logging.Logger;
import org.jboss.remoting.InvokerLocator;
@@ -160,7 +160,7 @@
client.addListener(callbackHandler, null, null, true);
- client.invoke(new CallbackTrigger("blop"));
+ client.invoke(new OnewayCallbackTrigger("blop"));
// make sure we get the callback
Deleted: trunk/tests/src/org/jboss/test/thirdparty/remoting/util/CallbackTrigger.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/util/CallbackTrigger.java 2007-01-25 11:09:31 UTC (rev 2051)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/util/CallbackTrigger.java 2007-01-25 11:19:00 UTC (rev 2052)
@@ -1,55 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.test.thirdparty.remoting.util;
-
-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 --------------------------------------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/test/thirdparty/remoting/util/OnewayCallbackTrigger.java (from rev 2049, trunk/tests/src/org/jboss/test/thirdparty/remoting/util/CallbackTrigger.java)
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/util/OnewayCallbackTrigger.java (rev 0)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/util/OnewayCallbackTrigger.java 2007-01-25 11:19:00 UTC (rev 2052)
@@ -0,0 +1,67 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.thirdparty.remoting.util;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class OnewayCallbackTrigger implements Serializable
+{
+ // Constants ------------------------------------------------------------------------------------
+
+ private static final long serialVersionUID = 2887545875458754L;
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private String payload;
+ private long[] triggerTimes;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public OnewayCallbackTrigger(String payload)
+ {
+ this(payload, new long[] {0});
+ }
+
+ public OnewayCallbackTrigger(String payload, long[] triggerTimes)
+ {
+ this.payload = payload;
+ this.triggerTimes = triggerTimes;
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public String getPayload()
+ {
+ return payload;
+ }
+
+ public long[] getTriggerTimes()
+ {
+ return triggerTimes;
+ }
+
+ public String toString()
+ {
+ return "OnewayCallbackTrigger[" + payload + "]";
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+}
Property changes on: trunk/tests/src/org/jboss/test/thirdparty/remoting/util/OnewayCallbackTrigger.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Modified: trunk/tests/src/org/jboss/test/thirdparty/remoting/util/RemotingTestSubsystem.java
===================================================================
--- trunk/tests/src/org/jboss/test/thirdparty/remoting/util/RemotingTestSubsystem.java 2007-01-25 11:09:31 UTC (rev 2051)
+++ trunk/tests/src/org/jboss/test/thirdparty/remoting/util/RemotingTestSubsystem.java 2007-01-25 11:19:00 UTC (rev 2052)
@@ -81,7 +81,7 @@
{
log.debug(this + " received " + invocation);
- Object parameter = invocation.getParameter();
+ final Object parameter = invocation.getParameter();
if ("ignore".equals(parameter))
{
@@ -93,25 +93,60 @@
invocationHistory.put(dirtyCopy(invocation));
- if (parameter instanceof CallbackTrigger)
+ if (parameter instanceof OnewayCallbackTrigger)
{
- Callback callback = new Callback(((CallbackTrigger)parameter).getPayload());
+ // send all oneway invocations from a different thread to avoid blocking the worker thread
+ // that has to return and write a response on the wire
- // seding a callback asynchronously
- pushToClient(callback, false);
+ new Thread(new Runnable()
+ {
+ public void run()
+ {
+ OnewayCallbackTrigger t = (OnewayCallbackTrigger)parameter;
+ String payload = t.getPayload();
+ long[] triggerTimes = t.getTriggerTimes();
+
+ for(int i = 0; i < triggerTimes.length; i++)
+ {
+ Callback callback = new Callback(payload + (i != 0 ? Integer.toString(i) : ""));
+
+ try
+ {
+ Thread.sleep(triggerTimes[i]);
+ }
+ catch(InterruptedException e)
+ {
+ log.error("interrupted", e);
+ return;
+ }
+
+ // seding a callback asynchronously
+ pushToClient(callback, false);
+ }
+ }
+ }, "Oneway Invoker Thread").start();
+
+ log.debug(this + " started a new oneway invoker thread");
+
}
return null;
}
- public synchronized void addListener(InvokerCallbackHandler callbackHandler)
+ public void addListener(InvokerCallbackHandler callbackHandler)
{
- callbackListeners.add(callbackHandler);
+ synchronized(callbackListeners)
+ {
+ callbackListeners.add(callbackHandler);
+ }
}
- public synchronized void removeListener(InvokerCallbackHandler callbackHandler)
+ public void removeListener(InvokerCallbackHandler callbackHandler)
{
- callbackListeners.remove(callbackHandler);
+ synchronized(callbackListeners)
+ {
+ callbackListeners.remove(callbackHandler);
+ }
}
// Public ---------------------------------------------------------------------------------------
@@ -129,20 +164,26 @@
private synchronized void pushToClient(Callback callback, boolean sendSynchronously)
{
- for(Iterator i = callbackListeners.iterator(); i.hasNext(); )
+ // make a copy to avoid ConcurrentModificationException
+ List callbackListenersCopy;
+ synchronized(callbackListeners)
{
+ callbackListenersCopy = new ArrayList(callbackListeners);
+ }
+
+ for(Iterator i = callbackListenersCopy.iterator(); i.hasNext(); )
+ {
ServerInvokerCallbackHandler h = (ServerInvokerCallbackHandler)i.next();
try
{
if (sendSynchronously)
{
- log.debug("pushing synchronous callback to " + h);
+ log.debug("pushing synchronous callback " + callback + " to " + h);
h.handleCallback(callback);
-
}
else
{
- log.debug("pushing asynchronous callback to " + h);
+ log.debug("pushing asynchronous callback " + callback + " to " + h);
h.handleCallbackOneway(callback);
}
}
More information about the jboss-cvs-commits
mailing list