[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/callback/push/bidirectional/multiplex ...
Ron Sigal
ron_sigal at yahoo.com
Sun Oct 22 02:44:02 EDT 2006
User: rsigal
Date: 06/10/22 02:44:02
Modified: src/tests/org/jboss/test/remoting/callback/push/bidirectional/multiplex
MultiplexCallbackTestClient.java
Log:
JBREM-612: Added unit test.
Revision Changes Path
1.2 +90 -0 JBossRemoting/src/tests/org/jboss/test/remoting/callback/push/bidirectional/multiplex/MultiplexCallbackTestClient.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MultiplexCallbackTestClient.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/callback/push/bidirectional/multiplex/MultiplexCallbackTestClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- MultiplexCallbackTestClient.java 18 May 2006 07:55:31 -0000 1.1
+++ MultiplexCallbackTestClient.java 22 Oct 2006 06:44:02 -0000 1.2
@@ -1,13 +1,25 @@
package org.jboss.test.remoting.callback.push.bidirectional.multiplex;
import junit.framework.TestCase;
+
import org.jboss.remoting.Client;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.multiplex.MultiplexClientInvoker;
+import org.jboss.remoting.transport.multiplex.MultiplexServerInvoker;
+import org.jboss.remoting.transport.multiplex.MultiplexingManager;
+import org.jboss.remoting.transport.multiplex.VirtualServerSocket;
+import org.jboss.remoting.transport.multiplex.VirtualSocket;
+import org.jboss.remoting.transport.multiplex.MultiplexServerInvoker.SocketGroupInfo;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import java.lang.reflect.Field;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
/**
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
@@ -33,6 +45,84 @@
assertTrue(gotCallback);
}
+
+
+ /**
+ * This test verifies that when Client creates an anonymous callback Connector,
+ * the callback connection from server to client uses the same underlying
+ * socket as the client to server connection.
+ *
+ * @throws Throwable
+ */
+ public void testSharedCallbackConnection() throws Throwable
+ {
+ // Wait for any existing MultiplexingManagers to close.
+ Thread.sleep(5000);
+
+ // There should be 0 MultiplexingManagers before Client is connected.
+ Field field = MultiplexingManager.class.getDeclaredField("allManagers");
+ field.setAccessible(true);
+ Set allManagers = (Set) field.get(null);
+ assertNotNull(allManagers);
+ assertEquals(0, allManagers.size());
+
+ // Create and connect Client.
+ Client client = new Client(new InvokerLocator(locatorUri));
+ client.connect();
+
+ // There should be 1 MultiplexingManager now that Client is connected.
+ assertEquals(1, allManagers.size());
+
+ // Add a push CallbackHandler.
+ InvokerCallbackHandler testCallbackHandler = new TestCallbackHandler();
+ client.addListener(testCallbackHandler, new HashMap(), "foobar");
+
+ // There should still be 1 MultiplexingManager, since client invoker and
+ // server invoker should be using the same connection.
+ assertEquals(1, allManagers.size());
+
+ // Show connection works.
+ client.invoke("foobar");
+ Thread.sleep(5000);
+ assertTrue(gotCallback);
+
+ // Get client invoker's MultiplexingManager.
+ MultiplexClientInvoker clientInvoker = (MultiplexClientInvoker) client.getInvoker();
+ field = MultiplexClientInvoker.class.getDeclaredField("socketGroupInfo");
+ field.setAccessible(true);
+ SocketGroupInfo sgi = (SocketGroupInfo) field.get(clientInvoker);
+ VirtualSocket socket = sgi.getPrimingSocket();
+ field = VirtualSocket.class.getDeclaredField("manager");
+ field.setAccessible(true);
+ MultiplexingManager clientManager = (MultiplexingManager) field.get(socket);
+ assertNotNull(clientManager);
+
+ // Get server invoker's MultiplexingManager.
+ field = Client.class.getDeclaredField("callbackConnectors");
+ field.setAccessible(true);
+ Map callbackConnectors = (Map) field.get(client);
+ assertEquals(1, callbackConnectors.size());
+ Connector connector = (Connector) callbackConnectors.values().iterator().next();
+ MultiplexServerInvoker serverInvoker = (MultiplexServerInvoker) connector.getServerInvoker();
+ field = SocketServerInvoker.class.getDeclaredField("serverSocket");
+ field.setAccessible(true);
+ VirtualServerSocket serverSocket = (VirtualServerSocket) field.get(serverInvoker);
+ field = VirtualServerSocket.class.getDeclaredField("manager");
+ field.setAccessible(true);
+ MultiplexingManager serverManager = (MultiplexingManager) field.get(serverSocket);
+
+ // Show client and server invokers are using the same MultiplexingManager.
+ assertEquals(clientManager, serverManager);
+
+ client.removeListener(testCallbackHandler);
+ client.disconnect();
+
+ Thread.sleep(5000);
+
+ // The connection should be closed and there should be 0 MultiplexingManagers.
+ assertEquals(0, allManagers.size());
+ }
+
public class TestCallbackHandler implements InvokerCallbackHandler
{
More information about the jboss-cvs-commits
mailing list