[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/timeout ...
Ron Sigal
ron_sigal at yahoo.com
Fri Aug 31 19:59:12 EDT 2007
User: rsigal
Date: 07/08/31 19:59:12
Modified: src/tests/org/jboss/test/remoting/timeout Tag: remoting_2_x
QuickDisconnectClientParent.java
Log:
JBREM-757: Split testQuickRemoveListener into testQuickRemovePushListener() and testQuickRemovePullListner and split testQuickRemoveListenerZeroTimeout into testQuickRemovePushListenerZeroTimeout and testQuickRemovePullListenerZeroTimeout.
Revision Changes Path
No revision
No revision
1.1.2.5 +194 -6 JBossRemoting/src/tests/org/jboss/test/remoting/timeout/Attic/QuickDisconnectClientParent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: QuickDisconnectClientParent.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/timeout/Attic/QuickDisconnectClientParent.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
--- QuickDisconnectClientParent.java 19 Jun 2007 06:14:38 -0000 1.1.2.4
+++ QuickDisconnectClientParent.java 31 Aug 2007 23:59:12 -0000 1.1.2.5
@@ -30,10 +30,7 @@
import junit.framework.TestCase;
-import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
import org.jboss.remoting.Client;
import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.InvocationRequest;
@@ -53,7 +50,7 @@
* removeListener().
*
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.2.4 $
+ * @version $Revision: 1.1.2.5 $
* <p>
* Copyright Jan 24, 2007
* </p>
@@ -348,8 +345,10 @@
* and sets the client's disconnectTimeout to 0. The client should be
* able to remove the callback handler quickly even though it cannot
* complete an invocation on the server.
+ *
+ * Push callbacks are used.
*/
- public void testQuickRemoveListenerZeroTimeout() throws Throwable
+ public void testQuickRemovePushListenerZeroTimeout() throws Throwable
{
log.info("entering " + getName());
String host = InetAddress.getLocalHost().getHostAddress();
@@ -436,11 +435,106 @@
/**
* This test starts a server, connects a client to it, disables the server,
+ * and sets the client's disconnectTimeout to 0. The client should be
+ * able to remove the callback handler quickly even though it cannot
+ * complete an invocation on the server.
+ *
+ * If the transport is not bidirectional, pull callbacks are used.
+ */
+ public void testQuickRemovePullListenerZeroTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostAddress();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(ServerInvoker.TIMEOUT, "60000");
+ config.put(Client.ENABLE_LEASE, "true");
+ addClientConfig(config);
+ final Client client = new Client(locator, config);
+ try
+ {
+ client.connect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ log.info("making first invocation");
+ Object response = client.invoke("test");
+ assertEquals("test", response);
+ log.info("first invocation succeeds");
+ final InvokerCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, new HashMap(), null, false);
+
+ final Holder removeListener = new Holder();
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ // Wait for the server to be disabled.
+ Thread.sleep(10000);
+
+ try
+ {
+ // This invocation may use up a listening connection,
+ // depending on transport.
+ HashMap metadata = new HashMap();
+ metadata.put("timeout", shortTimeoutString());
+ log.info("making invocation");
+ client.invoke("test", metadata);
+ log.info("made invocation");
+ }
+ catch (Exception e)
+ {
+ log.info("client.invoke(\"test\") failed (that's OK)");
+ }
+
+ // Set disconnectTimeout to 0.
+ client.setDisconnectTimeout(0);
+ client.removeListener(callbackHandler);
+ removeListener.done = true;
+ log.info("returned from client.removeListener()");
+ }
+ catch (Throwable e)
+ {
+ log.info("error in client.removeListener()", e);
+ }
+ }
+ }.start();
+
+
+ // Verify that a callback Connector has been created.
+ Field field = Client.class.getDeclaredField("callbackPollers");
+ field.setAccessible(true);
+ Map callbackPollers = (Map) field.get(client);
+ assertEquals(1, callbackPollers.size());
+
+ // Wait for about 4 seconds after the call to Client.removeListener() and then
+ // verify that the Client has successfully removed the callback handler even
+ // though the server is disabled.
+ Thread.sleep(16000);
+ assertEquals(0, callbackPollers.size());
+
+ // Verify that attempt to remove callback handler on server has timed out and
+ // client was able to complete call to removeListener().
+ assertTrue(removeListener.done);
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * This test starts a server, connects a client to it, disables the server,
* and sets the client's disconnectTimeout to 1 second. The client should be
* able to remove the callback handler quickly even though it cannot
* complete an invocation on the server.
+ *
+ * Push callbacks are used.
*/
- public void testQuickRemoveListener() throws Throwable
+ public void testQuickRemovePushListener() throws Throwable
{
log.info("entering " + getName());
String host = InetAddress.getLocalHost().getHostAddress();
@@ -527,6 +621,100 @@
/**
+ * This test starts a server, connects a client to it, disables the server,
+ * and sets the client's disconnectTimeout to 1 second. The client should be
+ * able to remove the callback handler quickly even though it cannot
+ * complete an invocation on the server.
+ *
+ * If the transport is not bidirectional, pull callbacks are used.
+ */
+ public void testQuickRemovePullListener() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostAddress();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(ServerInvoker.TIMEOUT, "60000");
+ config.put(Client.ENABLE_LEASE, "true");
+ addClientConfig(config);
+ final Client client = new Client(locator, config);
+ try
+ {
+ client.connect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ log.info("making first invocation");
+ Object response = client.invoke("test");
+ assertEquals("test", response);
+ log.info("first invocation succeeds");
+ final InvokerCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, new HashMap(), null, false);
+
+ final Holder removeListener = new Holder();
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ // Wait for the server to be disabled.
+ Thread.sleep(10000);
+
+ try
+ {
+ // This invocation may use up a listening connection,
+ // depending on transport.
+ HashMap metadata = new HashMap();
+ metadata.put("timeout", shortTimeoutString());
+ log.info("making invocation");
+ client.invoke("test", metadata);
+ log.info("made invocation");
+ }
+ catch (Exception e)
+ {
+ log.info("client.invoke(\"test\") failed (that's OK)");
+ }
+
+ // Set disconnectTimeout to 1 second.
+ client.setDisconnectTimeout(shortTimeout());
+ log.info("calling client.removeListener()");
+ client.removeListener(callbackHandler);
+ removeListener.done = true;
+ log.info("returned from client.removeListener()");
+ }
+ catch (Throwable e)
+ {
+ log.info("error in client.removeListener()", e);
+ }
+ }
+ }.start();
+
+
+ // Verify that a CallbackPoller has been created.
+ Field field = Client.class.getDeclaredField("callbackPollers");
+ field.setAccessible(true);
+ Map callbackPollers = (Map) field.get(client);
+ assertEquals(1, callbackPollers.size());
+
+ // Wait for about 4 seconds after the call to Client.removeListener() and then
+ // verify that the Client has successfully removed the callback handler even
+ // though the server is disabled.
+ Thread.sleep(16000);
+ assertEquals(0, callbackPollers.size());
+
+ // Verify that attempt to remove callback handler on server has timed out and
+ // client was able to complete call to removeListener().
+ assertTrue(removeListener.done);
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
* This test is identical to testQuickRemoveListener() except that the
* disconnectTimeout value is not set on the client. Therefore, the client
* will not be able to remove the callback handler as quickly as it does in
More information about the jboss-cvs-commits
mailing list