[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/socketfactory ...
Ron Sigal
ron_sigal at yahoo.com
Wed Jan 17 00:18:00 EST 2007
User: rsigal
Date: 07/01/17 00:18:00
Modified: src/tests/org/jboss/test/remoting/socketfactory
CreationListenerTestRoot.java
Log:
JBREM-298: Added unit tests for creating listeners from class names.
Revision Changes Path
1.3 +71 -50 JBossRemoting/src/tests/org/jboss/test/remoting/socketfactory/CreationListenerTestRoot.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CreationListenerTestRoot.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/socketfactory/CreationListenerTestRoot.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CreationListenerTestRoot.java 17 Jan 2007 03:10:39 -0000 1.2
+++ CreationListenerTestRoot.java 17 Jan 2007 05:18:00 -0000 1.3
@@ -56,7 +56,7 @@
/**
* @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* <p>
* Copyright Jan 10, 2007
* </p>
@@ -249,7 +249,7 @@
config.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener2);
Client client = new Client(locator, config);
assertFalse(listener1.visited());
- assertFalse(listener1.visited());
+ assertFalse(listener2.visited());
client.connect();
Integer i = (Integer) client.invoke(new Integer(17));
assertEquals(18, i.intValue());
@@ -371,7 +371,7 @@
HashMap config = new HashMap();
config.put(InvokerLocator.FORCE_REMOTE, "true");
- TestListener listener = new FailingTestListener();
+ FailingTestListener listener = new FailingTestListener();
config.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listener);
Client client = new Client(locator, config);
@@ -403,7 +403,7 @@
HashMap serverConfig = new HashMap();
ServerSocketFactory ssf = getServerSocketFactory();
serverConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
- TestListener listener = new FailingTestListener();
+ FailingTestListener listener = new FailingTestListener();
serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listener);
Connector connector = new Connector(locator, serverConfig);
connector.create();
@@ -445,70 +445,91 @@
}
- protected abstract String getTransport();
+ public void testCreateClientListenerFromClassName() throws Throwable
+ {
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int port = PortUtil.findFreePort(host);
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ Connector connector = new Connector(locator);
+ connector.create();
+ connector.addInvocationHandler("test", new TestHandler());
+ connector.start();
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ StaticTestListener.reset();
+ String listenerClassName = StaticTestListener.class.getName();
+ config.put(Remoting.SOCKET_CREATION_CLIENT_LISTENER, listenerClassName);
+ Client client = new Client(locator, config);
+ client.connect();
+ Integer i = (Integer) client.invoke(new Integer(17));
+ assertEquals(18, i.intValue());
+ Thread.sleep(500);
+ assertTrue(StaticTestListener.visited());
- protected SocketFactory getSocketFactory()
- {
- return SocketFactory.getDefault();
+ client.disconnect();
+ connector.stop();
+ log.info(getName() + " PASSES");
}
- protected ServerSocketFactory getServerSocketFactory()
+ public void testServerSideListenerFromClassName() throws Throwable
{
- return ServerSocketFactory.getDefault();
- }
+ log.info("entering " + getName());
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int port = PortUtil.findFreePort(host);
+ String locatorURI = getTransport() + "://" + host + ":" + port;
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ HashMap serverConfig = new HashMap();
+ ServerSocketFactory ssf = getServerSocketFactory();
+ serverConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ StaticTestListener.reset();
+ String listenerClassName = StaticTestListener.class.getName();
+ serverConfig.put(Remoting.SOCKET_CREATION_SERVER_LISTENER, listenerClassName);
+ Connector connector = new Connector(locator, serverConfig);
+ connector.create();
+ connector.addInvocationHandler("test", new TestHandler());
+ connector.start();
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ Client client = new Client(locator, clientConfig);
+ client.connect();
+ Integer i = (Integer) client.invoke(new Integer(29));
+ assertEquals(30, i.intValue());
+ Thread.sleep(500);
+ assertTrue(StaticTestListener.visited());
- protected void addExtraClientConfig(Map config)
- {
+ client.disconnect();
+ connector.stop();
+ log.info(getName() + " PASSES");
}
- protected void addExtraServerConfig(Map config)
- {
- }
+ protected abstract String getTransport();
- public class TestListener implements SocketCreationListener
- {
- private boolean visited;
- private boolean client;
- public void socketCreated(Socket socket, Object source) throws IOException
+ protected SocketFactory getSocketFactory()
{
- visited = true;
- if (source instanceof SocketFactory)
- client = true;
- else if (source instanceof ServerSocket)
- client = false;
- else
- log.error("unrecognized socket source: " + source);
- log.info(this + ": " + source);
+ return SocketFactory.getDefault();
}
- public boolean visited()
- {
- return visited;
- }
- public boolean isClient()
+ protected ServerSocketFactory getServerSocketFactory()
{
- return client;
+ return ServerSocketFactory.getDefault();
}
- public void reset()
+
+ protected void addExtraClientConfig(Map config)
{
- visited = false;
- }
}
- public class FailingTestListener extends TestListener
- {
- public void socketCreated(Socket socket, Object source) throws IOException
+ protected void addExtraServerConfig(Map config)
{
- throw new IOException();
- }
}
More information about the jboss-cvs-commits
mailing list