Author: ron.sigal(a)jboss.com
Date: 2010-09-07 15:34:04 -0400 (Tue, 07 Sep 2010)
New Revision: 6086
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
Log:
JBREM-1228: Changes due to reorganization of RemotingTestBase; other corrections.
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07
19:28:13 UTC (rev 6085)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java 2010-09-07
19:34:04 UTC (rev 6086)
@@ -27,44 +27,19 @@
import static org.testng.Assert.assertSame;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashSet;
-import java.util.Properties;
import java.util.ServiceLoader;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import org.jboss.marshalling.river.RiverProviderDescriptor;
import org.jboss.remoting3.Client;
-import org.jboss.remoting3.ClientContext;
-import org.jboss.remoting3.ClientListener;
-import org.jboss.remoting3.CloseHandler;
import org.jboss.remoting3.Connection;
import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.Registration;
import org.jboss.remoting3.RemoteExecutionException;
import org.jboss.remoting3.Remoting;
import org.jboss.remoting3.RequestContext;
import org.jboss.remoting3.RequestListener;
-import org.jboss.remoting3.Endpoint.ServiceBuilder;
-import org.jboss.remoting3.remote.RemoteProtocolDescriptor;
-import org.jboss.remoting3.security.SimpleServerAuthenticationProvider;
-import org.jboss.remoting3.spi.ConnectionProviderFactory;
-import org.jboss.remoting3.spi.NetworkServerProvider;
-import org.jboss.remoting3.spi.ProtocolServiceType;
import org.jboss.remoting3.spi.RemotingServiceDescriptor;
-import org.jboss.xnio.AcceptingServer;
-import org.jboss.xnio.ChannelListener;
-import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.OptionMap;
-import org.jboss.xnio.Options;
-import org.jboss.xnio.TcpServer;
-import org.jboss.xnio.Xnio;
-import org.jboss.xnio.channels.BoundChannel;
-import org.jboss.xnio.channels.ConnectedStreamChannel;
import org.jboss.xnio.log.Logger;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -113,8 +88,10 @@
int id1 = counter++;
// Set up services.
- sp0 = setupServer(null, id0, null, "test", "test", 4444);
- sp1 = setupServer(null, id1, null, "test", "test", 5555);
+ TestRequestListener testRequestListener0 = new TestRequestListener(id0);
+ TestRequestListener testRequestListener1 = new TestRequestListener(id1);
+ sp0 = setupServer(null, id0, testRequestListener0, "test",
"test");
+ sp1 = setupServer(null, id1, testRequestListener1, "test",
"test");
// Verify configuration.
assertNotSame(sp0.executor, sp1.executor, "Should be distinct");
@@ -124,10 +101,10 @@
assertNotSame(sp0.requestListener, sp1.requestListener, "Should be
distinct");
// Set up connections and clients.
- Connection connection00 = setupConnection(4444); connections.add(connection00);
- Connection connection01 = setupConnection(4444); connections.add(connection01);
- Connection connection10 = setupConnection(5555); connections.add(connection10);
- Connection connection11 = setupConnection(5555); connections.add(connection11);
+ Connection connection00 = setupConnection(sp0.port);
connections.add(connection00);
+ Connection connection01 = setupConnection(sp0.port);
connections.add(connection01);
+ Connection connection10 = setupConnection(sp1.port);
connections.add(connection10);
+ Connection connection11 = setupConnection(sp1.port);
connections.add(connection11);
Client<Object, Object> client000 = setupClient(connection00,
"test", "test"); clients.add(client000);
Client<Object, Object> client001 = setupClient(connection00,
"test", "test"); clients.add(client001);
Client<Object, Object> client010 = setupClient(connection01,
"test", "test"); clients.add(client010);
@@ -148,14 +125,22 @@
assertEquals(id1, client110.invoke("dummy"), "Should be
equal");
assertEquals(id1, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(20, sp0.requestListener.counter, "Should be equal");
- assertEquals(20, sp1.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(20, ((TestRequestListener)(sp0.requestListener)).counter,
"Should be equal");
+ assertEquals(20, ((TestRequestListener)(sp1.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp0.close();
- sp1.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp0 != null) {
+ sp0.close();
+ }
+ if (sp1 != null) {
+ sp1.close();
+ }
exit();
}
}
@@ -182,9 +167,11 @@
String instanceName1 = serviceType1;
// Set up services.
- sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+ TestRequestListener testRequestListener0 = new TestRequestListener(id0);
+ sp0 = setupServer(null, id0, testRequestListener0, serviceType0,
instanceName0);
+ TestRequestListener testRequestListener1 = new TestRequestListener(id1);
sp1 = new ServerPackage(sp0.executor, null, null, null, null, null, -1);
- setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+ setupServer(sp1, id1, testRequestListener1, serviceType1, instanceName1);
// Verify configuration.
assertSame(sp0.executor, sp1.executor, "Should be same");
@@ -218,14 +205,22 @@
assertEquals(id1, client110.invoke("dummy"), "Should be
equal");
assertEquals(id1, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(20, sp0.requestListener.counter, "Should be equal");
- assertEquals(20, sp1.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(20, ((TestRequestListener)(sp0.requestListener)).counter,
"Should be equal");
+ assertEquals(20, ((TestRequestListener)(sp1.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp0.close();
- sp1.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp0 != null) {
+ sp0.close();
+ }
+ if (sp1 != null) {
+ sp1.close();
+ }
exit();
}
}
@@ -251,9 +246,11 @@
String instanceName1 = serviceType1;
// Set up services.
- sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+ TestRequestListener testRequestListener0 = new TestRequestListener(id0);
+ sp0 = setupServer(null, id0, testRequestListener0, serviceType0,
instanceName0);
sp1 = new ServerPackage(sp0.executor, sp0.endpoint, null, null, null, null,
-1);
- setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+ TestRequestListener testRequestListener1 = new TestRequestListener(id1);
+ setupServer(sp1, id1, testRequestListener1, serviceType1, instanceName1);
// Verify configuration.
assertSame(sp0.executor, sp1.executor, "Should be same");
@@ -287,14 +284,22 @@
assertEquals(id0, client110.invoke("dummy"), "Should be
equal");
assertEquals(id1, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(20, sp0.requestListener.counter, "Should be equal");
- assertEquals(20, sp1.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(20, ((TestRequestListener)(sp0.requestListener)).counter,
"Should be equal");
+ assertEquals(20, ((TestRequestListener)(sp1.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp0.close();
- sp1.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp0 != null) {
+ sp0.close();
+ }
+ if (sp1 != null) {
+ sp1.close();
+ }
exit();
}
}
@@ -320,9 +325,11 @@
String instanceName1 = serviceType1;
// Set up services.
- sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+ TestRequestListener testRequestListener0 = new TestRequestListener(id0);
+ sp0 = setupServer(null, id0, testRequestListener0, serviceType0,
instanceName0);
sp1 = new ServerPackage(sp0.executor, sp0.endpoint, sp0.xnio, null, null, null,
-1);
- setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+ TestRequestListener testRequestListener1 = new TestRequestListener(id1);
+ setupServer(sp1, id1, testRequestListener1, serviceType1, instanceName1);
// Verify configuration.
assertSame(sp0.executor, sp1.executor, "Should be same");
@@ -356,14 +363,22 @@
assertEquals(id0, client110.invoke("dummy"), "Should be
equal");
assertEquals(id1, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(20, sp0.requestListener.counter, "Should be equal");
- assertEquals(20, sp1.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(20, ((TestRequestListener)(sp0.requestListener)).counter,
"Should be equal");
+ assertEquals(20, ((TestRequestListener)(sp1.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp0.close();
- sp1.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp0 != null) {
+ sp0.close();
+ }
+ if (sp1 != null) {
+ sp1.close();
+ }
exit();
}
}
@@ -391,13 +406,17 @@
String instanceName1 = "instance1";
// Set up services.
- sp00 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+ TestRequestListener testRequestListener00 = new TestRequestListener(id0);
+ sp00 = setupServer(null, id0, testRequestListener00, serviceType0,
instanceName0);
sp01 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp01, id0, null, serviceType0, instanceName1, 0);
+ TestRequestListener testRequestListener01 = new TestRequestListener(id0);
+ setupServer(sp01, id0, testRequestListener01, serviceType0, instanceName1);
sp10 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp10, id1, null, serviceType1, instanceName0, 0);
+ TestRequestListener testRequestListener10 = new TestRequestListener(id1);
+ setupServer(sp10, id1, testRequestListener10, serviceType1, instanceName0);
sp11 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp11, id1, null, serviceType1, instanceName1, 0);
+ TestRequestListener testRequestListener11 = new TestRequestListener(id1);
+ setupServer(sp11, id1, testRequestListener11, serviceType1, instanceName1);
// Verify configuration.
assertSame(sp00.executor, sp01.executor, "Should be same");
@@ -442,18 +461,30 @@
assertEquals(id1, client110.invoke("dummy"), "Should be
equal");
assertEquals(id1, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(10, sp00.requestListener.counter, "Should be equal");
- assertEquals(10, sp01.requestListener.counter, "Should be equal");
- assertEquals(10, sp10.requestListener.counter, "Should be equal");
- assertEquals(10, sp11.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(10, ((TestRequestListener)(sp00.requestListener)).counter,
"Should be equal");
+ assertEquals(10, ((TestRequestListener)(sp01.requestListener)).counter,
"Should be equal");
+ assertEquals(10, ((TestRequestListener)(sp10.requestListener)).counter,
"Should be equal");
+ assertEquals(10, ((TestRequestListener)(sp11.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp00.close();
- sp01.close();
- sp10.close();
- sp11.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp00 != null) {
+ sp00.close();
+ }
+ if (sp01 != null) {
+ sp01.close();
+ }
+ if (sp10 != null) {
+ sp10.close();
+ }
+ if (sp11 != null) {
+ sp11.close();
+ }
exit();
}
}
@@ -481,13 +512,14 @@
String instanceName1 = "instance1";
// Set up services.
- sp00 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+ TestRequestListener testRequestListener = new TestRequestListener(id0);
+ sp00 = setupServer(null, id0, testRequestListener, serviceType0,
instanceName0);
sp01 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp01, -1, sp00.requestListener, serviceType0, instanceName1, 0);
+ setupServer(sp01, -1, sp00.requestListener, serviceType0, instanceName1);
sp10 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp10, -1, sp00.requestListener, serviceType1, instanceName0, 0);
+ setupServer(sp10, -1, sp00.requestListener, serviceType1, instanceName0);
sp11 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio,
sp00.tcpServer, null, null, -1);
- setupServer(sp11, -1, sp00.requestListener, serviceType1, instanceName1, 0);
+ setupServer(sp11, -1, sp00.requestListener, serviceType1, instanceName1);
// Verify configuration.
assertSame(sp00.executor, sp01.executor, "Should be same");
@@ -529,81 +561,31 @@
assertEquals(id0, client110.invoke("dummy"), "Should be
equal");
assertEquals(id0, client111.invoke("dummy"), "Should be
equal");
}
- assertEquals(40, sp00.requestListener.counter, "Should be equal");
- log.info(getName() + " PASSES");
+ assertEquals(40, ((TestRequestListener)(sp00.requestListener)).counter,
"Should be equal");
+ log.debug(getName() + " PASSES");
} finally {
- clients.close();
- connections.close();
- sp00.close();
- sp01.close();
- sp10.close();
- sp11.close();
+ if (clients != null) {
+ clients.close();
+ }
+ if (connections != null) {
+ connections.close();
+ }
+ if (sp00 != null) {
+ sp00.close();
+ }
+ if (sp01 != null) {
+ sp01.close();
+ }
+ if (sp10 != null) {
+ sp10.close();
+ }
+ if (sp11 != null) {
+ sp11.close();
+ }
exit();
}
}
-
- protected String getRemotingScheme() {
- return "remote";
- }
-
- protected RemotingServiceDescriptor<ConnectionProviderFactory>
getProtocolDescriptor() {
- return new RemoteProtocolDescriptor();
- }
- protected ServerPackage setupServer(ServerPackage sp, int id, TestRequestListener
requestListener, String serviceType, String instanceName, int port) throws IOException {
-
- if (sp == null) {
- sp = new ServerPackage();
- }
-
- // Create and configure endpoint.
- if (sp.endpoint == null) {
- if (sp.executor == null) {
- sp.executor = new ThreadPoolExecutor(8, 64, 30, TimeUnit.SECONDS, new
ArrayBlockingQueue<Runnable>(64));
- }
- sp.endpoint = Remoting.createEndpoint("endpoint" + id, sp.executor,
OptionMap.EMPTY);
- final Registration reg1 =
sp.endpoint.addProtocolService(ProtocolServiceType.MARSHALLER_PROVIDER_DESCRIPTOR,
"river", new RiverProviderDescriptor());
- final Registration reg2 = sp.endpoint.addConnectionProvider(getRemotingScheme(),
getProtocolDescriptor().getService(new Properties()));
- sp.endpoint.addCloseHandler(new CloseHandler<Endpoint>() {
- public void handleClose(final Endpoint closed) {
- reg1.close();
- reg2.close();
- }});
- }
-
- // Set up XNIO layer.
- OptionMap serverOptions = OptionMap.builder().setSequence(Options.SASL_MECHANISMS,
"EXTERNAL", "DIGEST-MD5").getMap();
- SimpleServerAuthenticationProvider authenticationProvider = new
SimpleServerAuthenticationProvider();
- authenticationProvider.addUser("user", sp.endpoint.getName(),
"password".toCharArray());
- NetworkServerProvider provider =
sp.endpoint.getConnectionProviderInterface(getRemotingScheme(),
NetworkServerProvider.class);
- ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener =
provider.getServerListener(serverOptions, authenticationProvider);
- if (sp.xnio == null) {
- sp.xnio = Xnio.getInstance(String.valueOf(id));
- }
- if (sp.tcpServer == null) {
- createTcpServer(sp, listener, port);
- }
-
- // Register service with endpoint.
- sp.requestListener = (requestListener == null) ? new TestRequestListener(id) :
requestListener;
- if (sp.registration == null) {
- ServiceBuilder<Object, Object> sb =
sp.endpoint.serviceBuilder(Object.class, Object.class);
- sb.setInstanceName(instanceName).setServiceType(serviceType);
- sb.setClientListener(new TestClientListener(sp.requestListener));
- sp.registration = sb.register();
- }
- return sp;
- }
-
- protected void createTcpServer(ServerPackage sp,
ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener, int port)
throws IOException {
- log.info(this + " creating TcpServer");
- TcpServer tcpServer = sp.xnio.createTcpServer(listener, OptionMap.EMPTY);
- IoFuture<? extends BoundChannel<InetSocketAddress>> future =
tcpServer.bind(new InetSocketAddress("localhost", port));
- getFutureResult(future, "unable to bind " + sp.tcpServer);
- sp.tcpServer = tcpServer;
- sp.port = tcpServer.getChannels().iterator().next().getLocalAddress().getPort();
- }
-
protected Connection setupConnection(int port) throws IOException, URISyntaxException
{
Endpoint endpoint = Remoting.getConfiguredEndpoint();
URI uri = new URI(getRemotingScheme() + "://localhost:" + port);
@@ -611,10 +593,6 @@
return connection;
}
- protected OptionMap getConnectionOptionMap() {
- return OptionMap.EMPTY;
- }
-
protected Client<Object, Object> setupClient(Connection connection, String
serviceType, String instanceName) throws IOException, URISyntaxException {
Client<Object, Object> client =
getFutureResult(connection.openClient(serviceType, instanceName, Object.class,
Object.class), "unable to open client to " + serviceType + ":" +
instanceName);
return client;
@@ -643,76 +621,6 @@
}
}
- static class TestClientListener implements ClientListener<Object, Object> {
- private RequestListener<Object, Object> requestListener;
-
- TestClientListener(RequestListener<Object, Object> requestListener) {
- this.requestListener = requestListener;
- }
-
- public RequestListener<Object, Object> handleClientOpen(final ClientContext
clientContext, final OptionMap optionMap) {
- clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
- public void handleClose(final ClientContext closed) {
- log.info("Client closed");
- }
- });
- return requestListener;
- }
- }
-
- static class ServerPackage {
- public ThreadPoolExecutor executor;
- public Endpoint endpoint;
- public Xnio xnio;
- public AcceptingServer<?, ?, ?> tcpServer;
- public TestRequestListener requestListener;
- public Registration registration;
- public int port;
-
- public ServerPackage(ThreadPoolExecutor executor, Endpoint endpoint, Xnio xnio,
AcceptingServer<?, ?, ?> tcpServer, TestRequestListener requestListener,
Registration registration, int port) {
- this.executor = executor;
- this.endpoint = endpoint;
- this.xnio = xnio;
- this.tcpServer = tcpServer;
- this.requestListener = requestListener;
- this.registration = registration;
- this.port = port;
- }
-
- public ServerPackage() {
- }
-
- public void close() {
- if (executor != null) {
- executor.shutdown();
- }
- if (endpoint != null) {
- try {
- endpoint.close();
- } catch (IOException e) {
- log.error("unable to close " + endpoint);
- }
- }
- if (xnio != null) {
- try {
- xnio.close();
- } catch (IOException e) {
- log.error("unable to close " + xnio);
- }
- }
- if (tcpServer != null) {
- try {
- tcpServer.close();
- } catch (IOException e) {
- log.error("unable to close " + tcpServer);
- }
- }
- if (registration != null) {
- registration.close();
- }
- }
- }
-
static class ConnectionSet extends HashSet<Connection> {
private static final long serialVersionUID = 1L;