[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket ...
Ron Sigal
ron_sigal at yahoo.com
Wed Dec 27 01:13:49 EST 2006
User: rsigal
Date: 06/12/27 01:13:49
Added: src/tests/org/jboss/test/remoting/transport/bisocket
BisocketTestCase.java BisocketTestServer.java
BisocketPerformanceTestClient.java
BisocketTestClient.java
BisocketPerformanceTestServer.java
Log:
JBREM-650: Unit tests for bisocket transport.
Revision Changes Path
1.2 +1410 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BisocketTestCase.java
===================================================================
RCS file: BisocketTestCase.java
diff -N BisocketTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BisocketTestCase.java 27 Dec 2006 06:13:49 -0000 1.2
@@ -0,0 +1,1410 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+import org.jboss.remoting.transport.bisocket.BisocketClientInvoker;
+import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Nov 25, 2006
+ * </p>
+ */
+public class BisocketTestCase extends TestCase
+{
+ public static int port = 5413;
+
+ private static Logger log = Logger.getLogger(BisocketTestCase.class);
+
+ private static final String INVOCATION_TEST = "invocationTest";
+ private static final String CALLBACK_TEST = "callbackTest";
+ private static final String COUNTER = "counter";
+
+ private static final String TEST_PING_FREQUENCY_STRING = "1000";
+ private static final int TEST_PING_FREQUENCY = 1000;
+ private static final String TEST_MAX_POOL_SIZE_STRING = "5";
+ private static final int TEST_MAX_POOL_SIZE = 5;
+
+ // remoting server connector
+ private Connector connector;
+ private SampleInvocationHandler invocationHandler;
+
+
+
+ /**
+ * Sets up target remoting server.
+ */
+ public void setUp() throws Exception
+ {
+ String locatorURI = getTransport() + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ System.out.println("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
+ config.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, TEST_MAX_POOL_SIZE_STRING);
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new SampleInvocationHandler();
+ connector.addInvocationHandler("sample", invocationHandler);
+ connector.start();
+ }
+
+
+ /**
+ * Shuts down the server
+ */
+ public void tearDown()
+ {
+ connector.stop();
+ connector.destroy();
+ }
+
+
+ public void testInvocations() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ int invocationCount = 1000;
+ HashMap metadata = new HashMap(1);
+ for (int i = 0; i < invocationCount; i++)
+ {
+ Integer count = new Integer(i);
+ metadata.put(COUNTER, count);
+ Object response = client.invoke(INVOCATION_TEST, metadata);
+ response.equals(count);
+ }
+
+ client.disconnect();
+ }
+
+
+ public void testInvocationsThenCallbacksThenInvocations() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ int invocationCount = 100;
+ HashMap metadata = new HashMap(1);
+ for (int i = 0; i < invocationCount; i++)
+ {
+ Integer count = new Integer(i);
+ metadata.put(COUNTER, count);
+ Object response = client.invoke(INVOCATION_TEST, metadata);
+ assertTrue(response.equals(count));
+ }
+
+ SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+
+ for (int i = 0; i < invocationCount; i++)
+ {
+ client.invoke(CALLBACK_TEST);
+ }
+
+ assertEquals(invocationCount, callbackHandler.callbackCounter);
+
+ for (int i = 0; i < invocationCount; i++)
+ {
+ Integer count = new Integer(i);
+ metadata.put(COUNTER, count);
+ Object response = client.invoke(INVOCATION_TEST, metadata);
+ assertTrue(response.equals(count));
+ }
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testAlternatingInvocationsAndCallbacks() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+
+ int invocationCount = 100;
+ HashMap metadata = new HashMap(1);
+ for (int i = 0; i < invocationCount; i++)
+ {
+ Integer count = new Integer(i);
+ metadata.put(COUNTER, count);
+ Object response = client.invoke(INVOCATION_TEST, metadata);
+ client.invoke(CALLBACK_TEST);
+ assertTrue(response.equals(count));
+ }
+
+ assertEquals(invocationCount, callbackHandler.callbackCounter);
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testMaxSocketPoolSize() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ assertEquals(1, invocationHandler.callbackHandlers.size());
+ log.info("client added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool = (List) field.get(clientInvoker);
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+ assertEquals(0, pool.size());
+ Long usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(0, usedPooled.intValue());
+
+ int invocationCount = TEST_MAX_POOL_SIZE;
+ for (int i = 0; i < invocationCount; i++)
+ {
+ client.invokeOneway(CALLBACK_TEST);
+ }
+
+ Thread.sleep(100);
+ assertEquals(invocationCount, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(invocationCount, usedPooled.intValue());
+
+ for (int i = 0; i < invocationCount; i++)
+ {
+ client.invokeOneway(CALLBACK_TEST);
+ }
+
+ assertEquals(invocationCount, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(invocationCount, usedPooled.intValue());
+
+ Thread.sleep(1000);
+ assertEquals(invocationCount, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(invocationCount, usedPooled.intValue());
+
+ Thread.sleep(1500);
+ assertEquals(2 * invocationCount, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(invocationCount, usedPooled.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(2 * invocationCount, callbackHandler.callbackCounter);
+ assertEquals(invocationCount, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(0, usedPooled.intValue());
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testOneClientOneConnectorOneHandler() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+ log.info("client is connected");
+
+ String callbackLocatorURI = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector = new Connector(callbackLocatorURI, config);
+ callbackConnector.start();
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
+ assertEquals(1, invocationHandler.callbackHandlers.size());
+ log.info("client added callback handler");
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+ Thread.sleep(100);
+ assertEquals(3, callbackHandler.callbackCounter);
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool = (List) field.get(clientInvoker);
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+ assertEquals(0, pool.size());
+ Long usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(3, usedPooled.intValue());
+
+ Thread.sleep(3000);
+ assertEquals(3, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(0, usedPooled.intValue());
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ callbackConnector.stop();
+ }
+
+
+ public void testOneClientOneConnectorTwoHandlers() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector = new Connector(callbackLocatorURI, config);
+ callbackConnector.start();
+
+ DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI));
+ DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+
+ ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
+ assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
+ ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
+ assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
+ assertNotSame(clientInvoker1, clientInvoker2);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+ // Same pool because same address
+ assertSame(pool, pool2);
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ int count1 = callbackHandler1.callbackCounter;
+ int count2 = callbackHandler2.callbackCounter;
+ assertTrue(count1 == 2 && count2 == 0 || count1 == 0 && count2 == 2);
+ if (count1 == 0)
+ {
+ Object temp = callbackHandler1;
+ callbackHandler1 = callbackHandler2;
+ callbackHandler2 = (DelayedCallbackHandler) temp;;
+ }
+
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(0, usedPooled2.intValue());
+
+ client.removeListener(callbackHandler1);
+ client.removeListener(callbackHandler2);
+ client.disconnect();
+ callbackConnector.stop();
+ }
+
+
+ public void testOneClientTwoConnectorsOneHandler() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+ log.info("client is connected");
+
+ String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
+ callbackConnector1.start();
+ String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
+ Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
+ callbackConnector2.start();
+
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI1));
+ client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI2));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("client added callback handlers");
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+ Thread.sleep(100);
+ assertEquals(2, callbackHandler.callbackCounter);
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+ assertTrue(callbackClient1.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker1 = (MicroSocketClientInvoker) callbackClient1.getInvoker();
+ assertTrue(callbackClient2.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker2 = (MicroSocketClientInvoker) callbackClient2.getInvoker();
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool1 = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ assertEquals(2, usedPooled1.intValue());
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled2.intValue());
+
+ Thread.sleep(3000);
+ assertEquals(2, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ assertEquals(0, usedPooled1.intValue());
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(3000);
+ assertEquals(2, pool1.size());
+ assertEquals(2, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ assertEquals(0, usedPooled1.intValue());
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled2.intValue());
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ callbackConnector1.stop();
+ callbackConnector2.stop();
+ }
+
+
+ public void testOneClientTwoConnectorsTwoHandlers() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
+ callbackConnector1.start();
+ String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
+ Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
+ callbackConnector2.start();
+
+ DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI1));
+ DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI2));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+
+ ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
+ assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
+ ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
+ assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
+ assertNotSame(clientInvoker1, clientInvoker2);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool1 = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ int count1 = callbackHandler1.callbackCounter;
+ int count2 = callbackHandler2.callbackCounter;
+ assertTrue(count1 == 2 && count2 == 0 || count1 == 0 && count2 == 2);
+ if (count1 == 0)
+ {
+ Object temp = callbackHandler1;
+ callbackHandler1 = callbackHandler2;
+ callbackHandler2 = (DelayedCallbackHandler) temp;;
+ }
+
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(2, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(0, usedPooled2.intValue());
+
+ client.removeListener(callbackHandler1);
+ client.removeListener(callbackHandler2);
+ client.disconnect();
+ callbackConnector1.stop();
+ callbackConnector2.stop();
+ }
+
+
+ public void testTwoClientsOneConnectorOneHandler() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client1 = new Client(serverLocator, config);
+ client1.connect();
+ Client client2 = new Client(serverLocator, config);
+ client2.connect();
+ log.info("clients are connected");
+ assertTrue(client1.getInvoker() instanceof BisocketClientInvoker);
+ assertTrue(client2.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector = new Connector(callbackLocatorURI, config);
+ callbackConnector.start();
+
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client1.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
+ client2.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
+ assertEquals(1, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ ClientInvoker clientInvoker = callbackClient.getInvoker();
+ assertTrue(clientInvoker instanceof BisocketClientInvoker);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool = (List) field.get(clientInvoker);
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ Long usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(0, usedPooled.longValue());
+
+ client1.invokeOneway(CALLBACK_TEST);
+ client2.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ assertEquals(2, callbackHandler.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(2, usedPooled.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler.callbackCounter);
+ assertEquals(2, pool.size());
+ usedPooled = (Long) field.get(clientInvoker);
+ assertEquals(0, usedPooled.intValue());
+
+ client1.removeListener(callbackHandler);
+ client1.disconnect();
+ client2.removeListener(callbackHandler);
+ client2.disconnect();
+ callbackConnector.stop();
+ }
+
+
+ public void testTwoClientsOneConnectorTwoHandlers() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector = new Connector(callbackLocatorURI, config);
+ callbackConnector.start();
+
+ DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI));
+ DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+ ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
+ assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
+ ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
+ assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
+ assertNotSame(clientInvoker1, clientInvoker2);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+ // Same pool because same address
+ assertSame(pool, pool2);
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ int count1 = callbackHandler1.callbackCounter;
+ int count2 = callbackHandler2.callbackCounter;
+ assertTrue(count1 == 2 && count2 == 0 || count1 == 0 && count2 == 2);
+ if (count1 == 0)
+ {
+ Object temp = callbackHandler1;
+ callbackHandler1 = callbackHandler2;
+ callbackHandler2 = (DelayedCallbackHandler) temp;;
+ }
+
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(0, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(0, usedPooled2.intValue());
+
+ client.removeListener(callbackHandler1);
+ client.removeListener(callbackHandler2);
+ client.disconnect();
+ callbackConnector.stop();
+ }
+
+
+ public void testTwoClientsTwoConnectorsOneHandler() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client1 = new Client(serverLocator, config);
+ client1.connect();
+ Client client2 = new Client(serverLocator, config);
+ client2.connect();
+ log.info("clients are connected");
+ assertTrue(client1.getInvoker() instanceof BisocketClientInvoker);
+ assertTrue(client2.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
+ callbackConnector1.start();
+ String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
+ Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
+ callbackConnector2.start();
+
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client1.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI1));
+ client2.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI2));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+ ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
+ assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
+ ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
+ assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
+ assertNotSame(clientInvoker1, clientInvoker2);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool1 = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler.callbackCounter);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ client1.invokeOneway(CALLBACK_TEST);
+ client2.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ assertEquals(2, callbackHandler.callbackCounter);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(4, callbackHandler.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(4, callbackHandler.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(2, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(0, usedPooled2.intValue());
+
+ client1.removeListener(callbackHandler);
+ client1.disconnect();
+ client2.removeListener(callbackHandler);
+ client2.disconnect();
+ callbackConnector1.stop();
+ callbackConnector2.stop();
+ }
+
+
+ public void testTwoClientsTwoConnectorsTwoHandlers() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ String callbackLocatorURI1 = getTransport() + "://" + host + ":1";
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ Connector callbackConnector1 = new Connector(callbackLocatorURI1, config);
+ callbackConnector1.start();
+ String callbackLocatorURI2 = getTransport() + "://" + host + ":2";
+ Connector callbackConnector2 = new Connector(callbackLocatorURI2, config);
+ callbackConnector2.start();
+
+ DelayedCallbackHandler callbackHandler1 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler1, new InvokerLocator(callbackLocatorURI1));
+ DelayedCallbackHandler callbackHandler2 = new DelayedCallbackHandler();
+ client.addListener(callbackHandler2, new InvokerLocator(callbackLocatorURI2));
+ assertEquals(2, invocationHandler.callbackHandlers.size());
+ log.info("clients added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler1 = (ServerInvokerCallbackHandler) it.next();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler2 = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient1 = serverInvokerCallbackHandler1.getCallbackClient();
+ Client callbackClient2 = serverInvokerCallbackHandler2.getCallbackClient();
+ assertNotSame(callbackClient1, callbackClient2);
+ ClientInvoker clientInvoker1 = callbackClient1.getInvoker();
+ assertTrue(clientInvoker1 instanceof BisocketClientInvoker);
+ ClientInvoker clientInvoker2 = callbackClient2.getInvoker();
+ assertTrue(clientInvoker2 instanceof BisocketClientInvoker);
+ assertNotSame(clientInvoker1, clientInvoker2);
+
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ List pool1 = (List) field.get(clientInvoker1);
+ List pool2 = (List) field.get(clientInvoker2);
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
+ field.setAccessible(true);
+
+ assertEquals(0, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool1.size());
+ Long usedPooled1 = (Long) field.get(clientInvoker1);
+ Long usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ client.invokeOneway(CALLBACK_TEST);
+ client.invokeOneway(CALLBACK_TEST);
+
+ Thread.sleep(500);
+ int count1 = callbackHandler1.callbackCounter;
+ int count2 = callbackHandler2.callbackCounter;
+ assertTrue(count1 == 2 && count2 == 0 || count1 == 0 && count2 == 2);
+ if (count1 == 0)
+ {
+ Object temp = callbackHandler1;
+ callbackHandler1 = callbackHandler2;
+ callbackHandler2 = (DelayedCallbackHandler) temp;;
+ }
+
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(0, callbackHandler2.callbackCounter);
+ assertEquals(0, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(2, usedPooled1.longValue());
+ assertEquals(0, usedPooled2.longValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(0, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(2, usedPooled2.intValue());
+
+ Thread.sleep(2000);
+ assertEquals(2, callbackHandler1.callbackCounter);
+ assertEquals(2, callbackHandler2.callbackCounter);
+ assertEquals(2, pool1.size());
+ assertEquals(2, pool2.size());
+ usedPooled1 = (Long) field.get(clientInvoker1);
+ usedPooled2 = (Long) field.get(clientInvoker2);
+ assertEquals(0, usedPooled1.intValue());
+ assertEquals(0, usedPooled2.intValue());
+
+ client.removeListener(callbackHandler1);
+ client.removeListener(callbackHandler2);
+ client.disconnect();
+ callbackConnector1.stop();
+ callbackConnector2.stop();
+ }
+
+
+ public void testHearbeat() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+ client.invoke(CALLBACK_TEST);
+ client.invoke(CALLBACK_TEST);
+ client.invoke(CALLBACK_TEST);
+
+ Thread.sleep(100);
+ assertEquals(3, callbackHandler.callbackCounter);
+
+ Field field = Client.class.getDeclaredField("callbackConnectors");
+ field.setAccessible(true);
+ Map callbackConnectors = (Map) field.get(client);
+ assertEquals(1, callbackConnectors.size());
+ Connector callbackConnector = (Connector) callbackConnectors.values().iterator().next();
+ BisocketServerInvoker invoker = (BisocketServerInvoker) callbackConnector.getServerInvoker();
+ field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
+ field.setAccessible(true);
+ Map controlConnectionThreadMap = (Map) field.get(invoker);
+ assertEquals(1, controlConnectionThreadMap.size());
+ Thread t = (Thread) controlConnectionThreadMap.values().iterator().next();
+ Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
+ assertEquals(3, classes.length);
+ Class invokerClass = null;
+ for (int i = 0; i < classes.length; i++)
+ {
+ log.info(classes[i]);
+ String fqn = classes[i].getName();
+ String className = fqn.substring(fqn.lastIndexOf('.') + 1);
+ log.info(className);
+ if ("BisocketServerInvoker$ControlConnectionThread".equals(className))
+ {
+ invokerClass = classes[i];
+ break;
+ }
+ }
+
+ assertTrue(invokerClass != null);
+ field = invokerClass.getDeclaredField("lastPing");
+ field.setAccessible(true);
+ int pingFrequency = Integer.parseInt(TEST_PING_FREQUENCY_STRING);
+ Thread.sleep(2 * pingFrequency);
+ Long lastPing = (Long) field.get(t);
+ log.info("current: " + System.currentTimeMillis() + ", lastPing: " + lastPing);
+ assertTrue((System.currentTimeMillis() - lastPing.longValue()) < pingFrequency);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testControlConnectionFailureServerSide() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.callbackCounter);
+
+ ServerInvoker serverInvoker = connector.getServerInvoker();
+ assertTrue(serverInvoker instanceof BisocketServerInvoker);
+ Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
+ field.setAccessible(true);
+ Map callbackHandlers = (Map) field.get(serverInvoker);
+ assertEquals(1, callbackHandlers.size());
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler;
+ serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().toArray()[0];
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
+ field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket controlSocket = (Socket) field.get(clientInvoker);
+ controlSocket.close();
+
+ Thread.sleep(TEST_PING_FREQUENCY * 2);
+ client.invoke(CALLBACK_TEST);
+ assertEquals(2, callbackHandler.callbackCounter);
+
+ field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket newControlSocket = (Socket) field.get(clientInvoker);
+ assertTrue(!controlSocket.equals(newControlSocket));
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testControlConnectionFailureClientSide() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+ DelayedCallbackHandler callbackHandler = new DelayedCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.callbackCounter);
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
+ BisocketClientInvoker clientInvoker = (BisocketClientInvoker) callbackClient.getInvoker();
+ Field field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket serverSideControlSocket = (Socket) field.get(clientInvoker);
+
+ field = Client.class.getDeclaredField("callbackConnectors");
+ field.setAccessible(true);
+ Map callbackConnectors = (Map) field.get(client);
+ assertEquals(1, callbackConnectors.size());
+ Connector callbackConnector = (Connector) callbackConnectors.values().iterator().next();
+ BisocketServerInvoker invoker = (BisocketServerInvoker) callbackConnector.getServerInvoker();
+ field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
+ field.setAccessible(true);
+ Map controlConnectionThreadMap = (Map) field.get(invoker);
+ assertEquals(1, controlConnectionThreadMap.size());
+ Collection controlConnectionThreads = controlConnectionThreadMap.values();
+ Thread controlConnectionThread = (Thread) controlConnectionThreads.iterator().next();
+ Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
+ assertEquals(3, classes.length);
+ Class controlConnectionThreadClass = null;
+ for (int i = 0; i < classes.length; i++)
+ {
+ log.info(classes[i]);
+ String fqn = classes[i].getName();
+ String className = fqn.substring(fqn.lastIndexOf('.') + 1);
+ log.info(className);
+ if ("BisocketServerInvoker$ControlConnectionThread".equals(className))
+ {
+ controlConnectionThreadClass = classes[i];
+ break;
+ }
+ }
+
+ assertTrue(controlConnectionThreadClass != null);
+ field = controlConnectionThreadClass.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket clientSideControlSocket = (Socket) field.get(controlConnectionThread);
+ clientSideControlSocket.close();
+
+ Thread.sleep(TEST_PING_FREQUENCY * 2);
+ client.invoke(CALLBACK_TEST);
+ assertEquals(2, callbackHandler.callbackCounter);
+ Thread newControlConnectionThread = (Thread) controlConnectionThreads.iterator().next();
+ assertTrue(!controlConnectionThread.equals(newControlConnectionThread));
+
+ field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket newServerSideControlSocket = (Socket) field.get(clientInvoker);
+ assertTrue(!serverSideControlSocket.equals(newServerSideControlSocket));
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public void testNoControlConnectionRestart() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostName();
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Connecting to: " + serverLocator);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+ log.info("client is connected");
+ assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
+
+ SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+
+ Iterator it = invocationHandler.callbackHandlers.iterator();
+ ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) it.next();
+ Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
+ assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
+ Field field = BisocketClientInvoker.class.getDeclaredField("controlSocket");
+ field.setAccessible(true);
+ Socket controlSocketBefore = (Socket) field.get(clientInvoker);
+
+ Thread.sleep(4 * TEST_PING_FREQUENCY);
+ Socket controlSocketAfter = (Socket) field.get(clientInvoker);
+ assertEquals(controlSocketBefore, controlSocketAfter);
+ log.info("control socket: " + controlSocketBefore);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ public static void main(String[] args)
+ {
+ BisocketTestCase testCase = new BisocketTestCase();
+ try
+ {
+ testCase.setUp();
+ Thread.sleep(600000);
+ testCase.tearDown();
+ }
+ catch(Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config)
+ {
+ }
+
+
+ protected void addExtraServerConfig(Map config)
+ {
+ }
+
+
+ /**
+ * Simple invocation handler implementation. When callback client's are registered, will
+ * generate callbacks periodically.
+ */
+ static class SampleInvocationHandler implements ServerInvocationHandler
+ {
+ public Set callbackHandlers = new HashSet();
+ private int counter = 0;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ System.out.println("Adding callback listener.");
+ callbackHandlers.add(callbackHandler);
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ Object payload = invocation.getParameter();
+ if (INVOCATION_TEST.equals(payload))
+ {
+ Map requestMap = invocation.getRequestPayload();
+ Integer counter = (Integer) requestMap.get(COUNTER);
+ return counter;
+ }
+ else if (CALLBACK_TEST.equals(payload))
+ {
+ try
+ {
+ Iterator it = callbackHandlers.iterator();
+ while (it.hasNext())
+ {
+ InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler) it.next();
+ log.info("sending callback: " + ++counter);
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ log.info("sent callback");
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Unable to send callback");
+ }
+ return null;
+ }
+ else
+ {
+ throw new Exception("unrecognized invocation: " + payload);
+ }
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class SimpleCallbackHandler implements InvokerCallbackHandler
+ {
+ public int callbackCounter;
+ private Object lock = new Object();
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.debug("received callback: " + callback.getParameter());
+ synchronized (lock)
+ {
+ callbackCounter++;
+ }
+ }
+ }
+
+
+ static class DelayedCallbackHandler implements InvokerCallbackHandler
+ {
+ public int callbackCounter;
+ private Object lock = new Object();
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.debug("received callback: " + callback.getParameter());
+ synchronized (lock)
+ {
+ callbackCounter++;
+ }
+ try
+ {
+ Thread.sleep(2000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+}
\ No newline at end of file
1.1 date: 2006/12/27 06:13:49; author: rsigal; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestServer.java
<<Binary file>>
1.2 +148 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketPerformanceTestClient.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BisocketPerformanceTestClient.java
===================================================================
RCS file: BisocketPerformanceTestClient.java
diff -N BisocketPerformanceTestClient.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BisocketPerformanceTestClient.java 27 Dec 2006 06:13:49 -0000 1.2
@@ -0,0 +1,148 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Nov 25, 2006
+ * </p>
+ */
+public class BisocketPerformanceTestClient extends TestCase
+{
+ private static Logger log = Logger.getLogger(BisocketPerformanceTestClient.class);
+ private static String transport = "bisocket";
+ private static int invocations = 1000;
+
+
+ public void testBisocket() throws Throwable
+ {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int port = BisocketPerformanceTestServer.port;
+ String locatorURI = transport + "://" + host + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ System.out.println("Connecting to: " + serverLocator);
+ Client client = new Client(serverLocator);
+ client.connect();
+ System.out.println("client is connected");
+ InvokerCallbackHandler callbackHandler = new SampleCallbackHandler();
+ client.addListener(callbackHandler, new HashMap(), null, true);
+ System.out.println("client added callback handler");
+
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < invocations; i++)
+ {
+ client.invoke("test");
+ }
+ long finish = System.currentTimeMillis();
+ System.out.println("time to make " + invocations + " invocations: " + (finish - start));
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
+ /**
+ * Can pass transport and port to be used as parameters.
+ *
+ * @param args
+ */
+ public static void main(String[] args)
+ {
+ if(args != null && args.length > 0)
+ {
+ transport = args[0];
+ if (args.length > 1)
+ invocations = Integer.parseInt(args[1]);
+ }
+ BisocketPerformanceTestClient testCase = new BisocketPerformanceTestClient();
+ try
+ {
+ testCase.setUp();
+ testCase.testBisocket();
+ Thread.sleep(10000);
+ testCase.tearDown();
+ System.out.println("done");
+ }
+ catch(Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Simple invocation handler implementation. When callback client's are registered, will
+ * generate callbacks periodically.
+ */
+ static class SampleInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ System.out.println("Adding callback listener.");
+ try
+ {
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Unable to send callback");
+ }
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable {return null;}
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class SampleCallbackHandler implements InvokerCallbackHandler
+ {
+ int counter;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ counter++;
+ if ((counter + 1) % 1000 == 0)
+ {
+ System.out.println("received callback " + (counter + 1));
+ }
+ }
+ }
+}
1.1 date: 2006/12/27 06:13:49; author: rsigal; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestClient.java
<<Binary file>>
1.2 +140 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketPerformanceTestServer.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BisocketPerformanceTestServer.java
===================================================================
RCS file: BisocketPerformanceTestServer.java
diff -N BisocketPerformanceTestServer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BisocketPerformanceTestServer.java 27 Dec 2006 06:13:49 -0000 1.2
@@ -0,0 +1,140 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+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.bisocket.Bisocket;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.2 $
+ * <p>
+ * Copyright Nov 25, 2006
+ * </p>
+ */
+public class BisocketPerformanceTestServer extends TestCase
+{
+ public static int port = 5423;
+
+ private static Logger log = Logger.getLogger(BisocketPerformanceTestServer.class);
+ private static String transport = "bisocket";
+
+ // remoting server connector
+ private Connector connector;
+
+
+ /**
+ * Sets up target remoting server.
+ */
+ public void setUp() throws Exception
+ {
+ String locatorURI = transport + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + port;
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ System.out.println("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(Bisocket.IS_CALLBACK_SERVER, "false");
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
+ connector.addInvocationHandler("sample", invocationHandler);
+ connector.start();
+ }
+
+
+ /**
+ * Shuts down the server
+ */
+ public void tearDown()
+ {
+ if (connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ }
+ }
+
+
+ public static void main(String[] args)
+ {
+ if (args.length == 1)
+ transport = args[0];
+
+ BisocketPerformanceTestServer testCase = new BisocketPerformanceTestServer();
+ try
+ {
+ testCase.setUp();
+ Thread.sleep(600000);
+ testCase.tearDown();
+ }
+ catch(Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Simple invocation handler implementation. When callback client's are registered, will
+ * generate callbacks periodically.
+ */
+ static class SampleInvocationHandler implements ServerInvocationHandler
+ {
+ InvokerCallbackHandler callbackHandler;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ System.out.println("Adding callback listener.");
+ this.callbackHandler = callbackHandler;
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ try
+ {
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Unable to send callback");
+ }
+ return null;
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+}
More information about the jboss-cvs-commits
mailing list