[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket ...
Ron Sigal
ron_sigal at yahoo.com
Sat Apr 7 00:06:24 EDT 2007
User: rsigal
Date: 07/04/07 00:06:24
Modified: src/tests/org/jboss/test/remoting/transport/bisocket Tag:
remoting_2_x BisocketTestCase.java
Log:
JBREM-731: Added two unit tests.
Revision Changes Path
No revision
No revision
1.1.2.13 +142 -2 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: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -b -r1.1.2.12 -r1.1.2.13
--- BisocketTestCase.java 15 Mar 2007 22:24:10 -0000 1.1.2.12
+++ BisocketTestCase.java 7 Apr 2007 04:06:24 -0000 1.1.2.13
@@ -64,7 +64,7 @@
/**
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1.2.12 $
+ * @version $Revision: 1.1.2.13 $
* <p>
* Copyright Nov 25, 2006
* </p>
@@ -1538,7 +1538,11 @@
}
- public void testServerRestart() throws Throwable
+ /**
+ * This method tests the ability of a client to connect to a restarted
+ * server after a failure has been detected on the control connection.
+ */
+ public void testServerSlowRestart() throws Throwable
{
log.info("entering " + getName());
String host = InetAddress.getLocalHost().getHostName();
@@ -1581,6 +1585,7 @@
log.info("RESTARTED CONNECTOR");
assertNotSame(connector, oldConnector);
+ // Wait until a failure has been detected on the control connection.
Thread.sleep(TEST_PING_FREQUENCY * 5);
// It is beyond the scope of Remoting to fail over to a new server,
@@ -1608,6 +1613,141 @@
}
+ /**
+ * This method tests the ability of a client to connect to a restarted
+ * server before a failure has been detected on the control connection.
+ * It guards against the bug in JBREM-731.
+ */
+ public void testServerQuickRestart() 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");
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.callbackCounter);
+
+ Connector oldConnector = connector;
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ Set threads = clientpool.getContents();
+ for (Iterator it = threads.iterator(); it.hasNext(); )
+ {
+ ServerThread t = (ServerThread) it.next();
+ field = ServerThread.class.getDeclaredField("socketWrapper");
+ field.setAccessible(true);
+ SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
+ socketWrapper.close();
+ }
+ connector.stop();
+ log.info("STOPPED CONNECTOR");
+
+ internalSetUp(port);
+ log.info("RESTARTED CONNECTOR");
+ assertNotSame(connector, oldConnector);
+
+ // It is beyond the scope of Remoting to fail over to a new server,
+ // complete with registered callback handlers.
+ log.info("adding callback handler");
+ client.addListener(callbackHandler, new HashMap());
+ log.info("client added callback handler");
+
+ client.invoke(CALLBACK_TEST);
+ assertEquals(2, callbackHandler.callbackCounter);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+
+ // The ControlMonitorTimerTask from the first callback handler tries to recreate
+ // its control connection, which adds an entry to
+ // BisocketClientInvoker.listenerIdToSocketsMap which cannot be removed, which
+ // interferes with testForLeaks().
+ //
+ // TODO: Should the possibility of a leak because of this phenomenon be handled?
+ field = BisocketClientInvoker.class.getDeclaredField("listenerIdToSocketsMap");
+ field.setAccessible(true);
+ Map listenerIdToSocketsMap = (Map) field.get(null);
+ listenerIdToSocketsMap.clear();
+ }
+
+
+ public void testDeadControlConnectionShutdown() 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);
+ int MAX_RETRIES = 3;
+ config.put(Bisocket.MAX_CONTROL_CONNECTION_RESTARTS, Integer.toString(MAX_RETRIES));
+ 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();
+ SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
+ client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
+ log.info("client added callback handler");
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.callbackCounter);
+
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ Set threads = clientpool.getContents();
+ for (Iterator it = threads.iterator(); it.hasNext(); )
+ {
+ ServerThread t = (ServerThread) it.next();
+ field = ServerThread.class.getDeclaredField("socketWrapper");
+ field.setAccessible(true);
+ SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
+ socketWrapper.close();
+ }
+ connector.stop();
+ log.info("STOPPED CONNECTOR");
+ internalSetUp(port);
+ log.info("RESTARTED CONNECTOR");
+
+ // Wait until a failure has been detected on the control connection.
+ Thread.sleep(TEST_PING_FREQUENCY * MAX_RETRIES * 5);
+
+ ServerInvoker callbackServerInvoker = callbackConnector.getServerInvoker();
+ field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
+ field.setAccessible(true);
+ Map controlConnectionThreadMap = (Map) field.get(callbackServerInvoker);
+ assertEquals(0, controlConnectionThreadMap.size());
+
+ client.setDisconnectTimeout(0);
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ }
+
+
public void testForLeaks() throws Throwable
{
log.info("entering " + getName());
More information about the jboss-cvs-commits
mailing list