[jboss-remoting-commits] JBoss Remoting SVN: r5874 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Jun 22 16:29:57 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-06-22 16:29:57 -0400 (Tue, 22 Jun 2010)
New Revision: 5874

Added:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java
Log:
JBREM-1228: Added unit tests for a variety of shared and unshared components.

Added: 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	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteConfigurationTestCase.java	2010-06-22 20:29:57 UTC (rev 5874)
@@ -0,0 +1,771 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.remoting3.test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotSame;
+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.IoFuture.Status;
+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;
+import org.testng.annotations.Test;
+
+/**
+ * Tests various Client and Connection configurations to various
+ * server configurations of Executors, Endpoints, Xnio's, TcpServers, and RequestListeners.
+ * 
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 7, 2010
+ */
+ at Test(suiteName = "ClientServerRemoteConfiguration")
+public class ClientServerRemoteConfigurationTestCase {
+
+   private static final Logger log = Logger.getLogger(ClientServerRemoteConfigurationTestCase.class);
+
+   private static int counter;
+
+   static void enter() {
+      final StackTraceElement e = new Throwable().getStackTrace()[1];
+      log.info("Entering: %s#%s", e.getClassName(), e.getMethodName());
+   }
+
+   static void exit() {
+      final StackTraceElement e = new Throwable().getStackTrace()[1];
+      log.info("Exiting: %s#%s", e.getClassName(), e.getMethodName());
+      log.info("-------------------------------------------------------------");
+   }
+   
+   static <T> T getFutureResult(IoFuture<T> future, String errorMessage) throws IOException {
+      Status status = null;
+      switch (status = future.await(5000, TimeUnit.MILLISECONDS)) {
+         case DONE: {
+            return future.get();
+         }
+         case FAILED: {
+            log.error(errorMessage);
+            throw future.getException();
+         }
+         default: {
+            throw new RuntimeException("unexpected future state: " + status);
+         }
+      }
+   }
+
+   @BeforeMethod
+   public void setUp() {
+      ServiceLoader.load(RemotingServiceDescriptor.class);
+   }
+
+   @AfterMethod
+   public void tearDown() throws IOException {
+   }
+   
+   /**
+    * Distinct Executors, Endpoints, Xnio's, TcpServers, RequestListeners. 
+    * One instance of one service in each Endpoint.
+    * Two Connections per TcpServer, two Clients per Connection.
+    */
+   @Test
+   public void testAllDistinct() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         
+         // Set up services.
+         sp0 = setupServer(null, id0, null, "test", "test", 4444);
+         sp1 = setupServer(null, id1, null, "test", "test", 5555);
+         
+         // Verify configuration.
+         assertNotSame(sp0.executor, sp1.executor, "Should be distinct");
+         assertNotSame(sp0.endpoint, sp1.endpoint, "Should be distinct");
+         assertNotSame(sp0.xnio, sp1.xnio, "Should be distinct");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         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);
+         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);
+         Client<Object, Object> client011 = setupClient(connection01, "test", "test"); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection10, "test", "test"); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection10, "test", "test"); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection11, "test", "test"); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection11, "test", "test"); clients.add(client111);
+          
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client101.invoke("dummy"), "Should be equal");
+            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("testAllDistinct() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp0.close();
+         sp1.close();
+         exit();
+      }
+   }
+
+   /**
+    * Distinct Endpoints, Xnio's, TcpServers, RequestListeners.
+    * One instance of one service in each Endpoint.
+    * Two Connections per TcpServer, two Clients per Connection.
+    */
+   @Test
+   public void testSharedExecutor() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         String serviceType0 = "test" + id0;
+         String instanceName0 = serviceType0;
+         String serviceType1 = "test" + id1;
+         String instanceName1 = serviceType1;
+         
+         // Set up services.
+         sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+         sp1 = new ServerPackage(sp0.executor, null, null, null, null, null, -1);
+         setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+         
+         // Verify configuration.
+         assertSame(sp0.executor, sp1.executor, "Should be same");
+         assertNotSame(sp0.endpoint, sp1.endpoint, "Should be distinct");
+         assertNotSame(sp0.xnio, sp1.xnio, "Should be distinct");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         assertNotSame(sp0.requestListener, sp1.requestListener, "Should be distinct");
+         
+         // Set up connections and clients.
+         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, serviceType0, instanceName0); clients.add(client000);
+         Client<Object, Object> client001 = setupClient(connection00, serviceType0, instanceName0); clients.add(client001);
+         Client<Object, Object> client010 = setupClient(connection01, serviceType0, instanceName0); clients.add(client010);
+         Client<Object, Object> client011 = setupClient(connection01, serviceType0, instanceName0); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection10, serviceType1, instanceName1); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection10, serviceType1, instanceName1); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection11, serviceType1, instanceName1); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection11, serviceType1, instanceName1); clients.add(client111);
+         
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client101.invoke("dummy"), "Should be equal");
+            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("testSharedExecutor() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp0.close();
+         sp1.close();
+         exit();
+      }
+   }
+   
+   /**
+    * Distinct Xnio's, TcpServers, RequestListeners: one instance each of two distinct services in single Endpoint
+    * Two Connections per TcpServer, two Clients per Connection, one connected to service1 and the other connected to service2.
+    */
+   @Test
+   public void testSharedExecutorEndpoint() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         String serviceType0 = "test" + id0;
+         String instanceName0 = serviceType0;
+         String serviceType1 = "test" + id1;
+         String instanceName1 = serviceType1;
+         
+         // Set up services.
+         sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+         sp1 = new ServerPackage(sp0.executor, sp0.endpoint, null, null, null, null, -1);
+         setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+
+         // Verify configuration.
+         assertSame(sp0.executor, sp1.executor, "Should be same");
+         assertSame(sp0.endpoint, sp1.endpoint, "Should be same");
+         assertNotSame(sp0.xnio, sp1.xnio, "Should be distinct");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         assertNotSame(sp0.requestListener, sp1.requestListener, "Should be distinct");
+         
+         // Set up connections and clients.
+         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, serviceType0, instanceName0); clients.add(client000);
+         Client<Object, Object> client001 = setupClient(connection00, serviceType1, instanceName1); clients.add(client001);
+         Client<Object, Object> client010 = setupClient(connection01, serviceType0, instanceName0); clients.add(client010);
+         Client<Object, Object> client011 = setupClient(connection01, serviceType1, instanceName1); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection10, serviceType0, instanceName0); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection10, serviceType1, instanceName1); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection11, serviceType0, instanceName0); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection11, serviceType1, instanceName1); clients.add(client111);
+         
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client101.invoke("dummy"), "Should be equal");
+            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("testSharedExecutorEndpoint() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp0.close();
+         sp1.close();
+         exit();
+      }
+   }
+   
+   /**
+    * Distinct TcpServers, RequestListeners: one instance each of two distinct services in single Endpoint
+    * Two Connections per TcpServer, two Clients per Connection, one connected to service1 and the other connected to service2.
+    */
+   @Test
+   public void testSharedExecutorEndpointXnio() throws Exception {
+      enter();
+      ServerPackage sp0 = null;
+      ServerPackage sp1 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         String serviceType0 = "test" + id0;
+         String instanceName0 = serviceType0;
+         String serviceType1 = "test" + id1;
+         String instanceName1 = serviceType1;
+         
+         // Set up services.
+         sp0 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+         sp1 = new ServerPackage(sp0.executor, sp0.endpoint, sp0.xnio, null, null, null, -1);
+         setupServer(sp1, id1, null, serviceType1, instanceName1, 0);
+         
+         // Verify configuration.
+         assertSame(sp0.executor, sp1.executor, "Should be same");
+         assertSame(sp0.endpoint, sp1.endpoint, "Should be same");
+         assertSame(sp0.xnio, sp1.xnio, "Should be same");
+         assertNotSame(sp0.tcpServer, sp1.tcpServer, "Should be distinct");
+         assertNotSame(sp0.requestListener, sp1.requestListener, "Should be distinct");
+         
+         // Set up connections and clients.
+         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, serviceType0, instanceName0); clients.add(client000);
+         Client<Object, Object> client001 = setupClient(connection00, serviceType1, instanceName1); clients.add(client001);
+         Client<Object, Object> client010 = setupClient(connection01, serviceType0, instanceName0); clients.add(client010);
+         Client<Object, Object> client011 = setupClient(connection01, serviceType1, instanceName1); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection10, serviceType0, instanceName0); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection10, serviceType1, instanceName1); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection11, serviceType0, instanceName0); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection11, serviceType1, instanceName1); clients.add(client111);  
+         
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client101.invoke("dummy"), "Should be equal");
+            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("testSharedExecutorEndpointXnio() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp0.close();
+         sp1.close();
+         exit();
+      }
+   }
+   
+   /**
+    * Two instances each of two distinct services in single Endpoint, each with a distinct RequestListener.
+    * Two Connections to the single TcpServer, four Clients per Connection, one per service instance.
+    */
+   @Test
+   public void testSharedExecutorEndpointXnioTcpServer() throws Exception {
+      enter();
+      ServerPackage sp00 = null;
+      ServerPackage sp01 = null;
+      ServerPackage sp10 = null;
+      ServerPackage sp11 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         String serviceType0 = "test" + id0;
+         String serviceType1 = "test" + id1;
+         String instanceName0 = "instance0";
+         String instanceName1 = "instance1";
+         
+         // Set up services.
+         sp00 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+         sp01 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp01, id0, null, serviceType0, instanceName1, 0);
+         sp10 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp10, id1, null, serviceType1, instanceName0, 0);
+         sp11 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp11, id1, null, serviceType1, instanceName1, 0);
+         
+         // Verify configuration.
+         assertSame(sp00.executor, sp01.executor, "Should be same");
+         assertSame(sp00.executor, sp10.executor, "Should be same");
+         assertSame(sp00.executor, sp11.executor, "Should be same");
+         assertSame(sp00.endpoint, sp01.endpoint, "Should be same");
+         assertSame(sp00.endpoint, sp10.endpoint, "Should be same");
+         assertSame(sp00.endpoint, sp11.endpoint, "Should be same");
+         assertSame(sp00.xnio, sp01.xnio, "Should be same");
+         assertSame(sp00.xnio, sp10.xnio, "Should be same");
+         assertSame(sp00.xnio, sp11.xnio, "Should be same");
+         assertSame(sp00.tcpServer, sp01.tcpServer, "Should be same");
+         assertSame(sp00.tcpServer, sp10.tcpServer, "Should be same");
+         assertSame(sp00.tcpServer, sp11.tcpServer, "Should be same");
+         assertNotSame(sp00.requestListener, sp01.requestListener, "Should be distinct");
+         assertNotSame(sp00.requestListener, sp10.requestListener, "Should be distinct");
+         assertNotSame(sp00.requestListener, sp11.requestListener, "Should be distinct");
+         assertNotSame(sp01.requestListener, sp10.requestListener, "Should be distinct");
+         assertNotSame(sp01.requestListener, sp11.requestListener, "Should be distinct");
+         assertNotSame(sp10.requestListener, sp11.requestListener, "Should be distinct");
+         
+         // Set up connections and clients.
+         Connection connection0 = setupConnection(sp00.port); connections.add(connection0);
+         Connection connection1 = setupConnection(sp00.port); connections.add(connection1);
+         Client<Object, Object> client000 = setupClient(connection0, serviceType0, instanceName0); clients.add(client000);
+         Client<Object, Object> client001 = setupClient(connection0, serviceType0, instanceName1); clients.add(client001);
+         Client<Object, Object> client010 = setupClient(connection0, serviceType1, instanceName0); clients.add(client010);
+         Client<Object, Object> client011 = setupClient(connection0, serviceType1, instanceName1); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection1, serviceType0, instanceName0); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection1, serviceType0, instanceName1); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection1, serviceType1, instanceName0); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection1, serviceType1, instanceName1); clients.add(client111); 
+         
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id1, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client101.invoke("dummy"), "Should be equal");
+            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("testSharedExecutorEndpointXnioTcpServer() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp00.close();
+         sp01.close();
+         sp10.close();
+         sp11.close();
+         exit();
+      }
+   }
+   
+   /**
+    * Two instances each of two distinct services in single Endpoint, all sharing a single RequestListener.
+    * Two Connections to the single TcpServer, four Clients per Connection, one per service instance.
+    */
+   @Test
+   public void testSharedExecutorEndpointXnioTcpServerRequestListener() throws Exception {
+      enter();
+      ServerPackage sp00 = null;
+      ServerPackage sp01 = null;
+      ServerPackage sp10 = null;
+      ServerPackage sp11 = null;
+      ConnectionSet connections = new ConnectionSet();
+      ClientSet clients = new ClientSet();
+      
+      try {
+         int id0 = counter++;
+         int id1 = counter++;
+         String serviceType0 = "test" + id0;
+         String serviceType1 = "test" + id1;
+         String instanceName0 = "instance0";
+         String instanceName1 = "instance1";
+         
+         // Set up services.
+         sp00 = setupServer(null, id0, null, serviceType0, instanceName0, 0);
+         sp01 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp01, -1, sp00.requestListener, serviceType0, instanceName1, 0);
+         sp10 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp10, -1, sp00.requestListener, serviceType1, instanceName0, 0);
+         sp11 = new ServerPackage(sp00.executor, sp00.endpoint, sp00.xnio, sp00.tcpServer, null, null, -1);
+         setupServer(sp11, -1, sp00.requestListener, serviceType1, instanceName1, 0);
+         
+         // Verify configuration.
+         assertSame(sp00.executor, sp01.executor, "Should be same");
+         assertSame(sp00.executor, sp10.executor, "Should be same");
+         assertSame(sp00.executor, sp11.executor, "Should be same");
+         assertSame(sp00.endpoint, sp01.endpoint, "Should be same");
+         assertSame(sp00.endpoint, sp10.endpoint, "Should be same");
+         assertSame(sp00.endpoint, sp11.endpoint, "Should be same");
+         assertSame(sp00.xnio, sp01.xnio, "Should be same");
+         assertSame(sp00.xnio, sp10.xnio, "Should be same");
+         assertSame(sp00.xnio, sp11.xnio, "Should be same");
+         assertSame(sp00.tcpServer, sp01.tcpServer, "Should be same");
+         assertSame(sp00.tcpServer, sp10.tcpServer, "Should be same");
+         assertSame(sp00.tcpServer, sp11.tcpServer, "Should be same");
+         assertSame(sp00.requestListener, sp01.requestListener, "Should be same");
+         assertSame(sp00.requestListener, sp10.requestListener, "Should be same");
+         assertSame(sp00.requestListener, sp11.requestListener, "Should be same");
+         
+         // Set up connections and clients.
+         Connection connection0 = setupConnection(sp00.port); connections.add(connection0);
+         Connection connection1 = setupConnection(sp00.port); connections.add(connection1);
+         Client<Object, Object> client000 = setupClient(connection0, serviceType0, instanceName0); clients.add(client000);
+         Client<Object, Object> client001 = setupClient(connection0, serviceType0, instanceName1); clients.add(client001);
+         Client<Object, Object> client010 = setupClient(connection0, serviceType1, instanceName0); clients.add(client010);
+         Client<Object, Object> client011 = setupClient(connection0, serviceType1, instanceName1); clients.add(client011);
+         Client<Object, Object> client100 = setupClient(connection1, serviceType0, instanceName0); clients.add(client100);
+         Client<Object, Object> client101 = setupClient(connection1, serviceType0, instanceName1); clients.add(client101);
+         Client<Object, Object> client110 = setupClient(connection1, serviceType1, instanceName0); clients.add(client110);
+         Client<Object, Object> client111 = setupClient(connection1, serviceType1, instanceName1); clients.add(client111); 
+         
+         // Test invocations.
+         for (int i = 0; i < 5; i++) {
+            assertEquals(id0, client000.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client001.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client010.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client011.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client100.invoke("dummy"), "Should be equal");
+            assertEquals(id0, client101.invoke("dummy"), "Should be equal");
+            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("testSharedExecutorEndpointXnioTcpServerRequestListener() PASSES");
+      } finally {
+         clients.close();
+         connections.close();
+         sp00.close();
+         sp01.close();
+         sp10.close();
+         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);
+      Connection connection = getFutureResult(endpoint.connect(uri, getConnectionOptionMap(), "user", null, "password".toCharArray()), "unable to connect to " + uri);
+      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;
+   }
+
+   static class TestRequestListener implements RequestListener<Object, Object> {
+      public int counter = 0;
+      private int answer;
+
+      public TestRequestListener(int answer) {
+         this.answer = answer;
+      }
+
+      public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException {
+         try {
+            counter++;
+            context.sendReply(answer);
+         } catch (IOException e) {
+            try {
+               context.sendFailure("error returning response", e);
+            } catch (IOException e1) {
+               e.printStackTrace();
+               throw new RemoteExecutionException("error returning exception", e1);
+            }
+         }
+      }
+   }
+
+   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;
+
+      public void close() {
+         for (Connection connection: this) {
+            try {
+               connection.close();
+            } catch (IOException e) {
+               log.error("unable to close " + connection);
+            }
+         }
+      }
+   }
+
+   static class ClientSet extends HashSet<Client<?, ?>> {
+      private static final long serialVersionUID = 1L;
+
+      public void close() {
+         for (Client<?,?> client: this) {
+            try {
+               client.close();
+            } catch (IOException e) {
+               log.error("unable to close " + client);
+            }
+         }
+      }
+   }
+}

Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ClientServerRemoteSSLConfigurationTestCase.java	2010-06-22 20:29:57 UTC (rev 5874)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.remoting3.test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+
+import org.jboss.remoting3.remote.RemoteSslProtocolDescriptor;
+import org.jboss.remoting3.spi.ConnectionProviderFactory;
+import org.jboss.remoting3.spi.RemotingServiceDescriptor;
+import org.jboss.xnio.ChannelListener;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Options;
+import org.jboss.xnio.SslTcpServer;
+import org.jboss.xnio.Xnio;
+import org.jboss.xnio.OptionMap.Builder;
+import org.jboss.xnio.channels.BoundChannel;
+import org.jboss.xnio.channels.ConnectedStreamChannel;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 10, 2010
+ */
+ at Test(suiteName = "ClientServerRemoteSSLConfiguration")
+public class ClientServerRemoteSSLConfigurationTestCase extends ClientServerRemoteConfigurationTestCase {
+
+   private static final Logger log = Logger.getLogger(ClientServerRemoteSSLConfigurationTestCase.class);
+   
+   // Use anonymous ciphers so we don't need a trust store configuration of any sort
+   private static final String[] CIPHER_SUITES = {
+           "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
+           "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
+           "TLS_DH_anon_WITH_AES_128_CBC_SHA",
+           "TLS_DH_anon_WITH_AES_256_CBC_SHA",
+           "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
+           "SSL_DH_anon_WITH_DES_CBC_SHA",
+           "SSL_DH_anon_WITH_RC4_128_MD5",
+           "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
+           "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
+   };
+
+   private static final String[] PROTOCOLS = {
+           "TLSv1",
+   };
+   
+   protected String getRemotingScheme() {
+      return "remote+ssl";
+   }
+   
+   protected RemotingServiceDescriptor<ConnectionProviderFactory> getProtocolDescriptor() {
+      return new RemoteSslProtocolDescriptor();
+   }
+   
+   protected OptionMap getConnectionOptionMap() {
+      Builder builder = OptionMap.builder();
+      builder.setSequence(Options.SSL_ENABLED_CIPHER_SUITES, CIPHER_SUITES);
+      builder.setSequence(Options.SSL_ENABLED_PROTOCOLS, PROTOCOLS);
+      return builder.getMap();
+   }
+   
+   @Override
+   protected void createTcpServer(ServerPackage sp, ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener, int port) throws IOException {
+      log.info(this + " creating SslTcpServer");
+      Builder builder = OptionMap.builder();
+      builder.setSequence(Options.SSL_ENABLED_CIPHER_SUITES, CIPHER_SUITES);
+      builder.setSequence(Options.SSL_ENABLED_PROTOCOLS, PROTOCOLS);
+      SslTcpServer sslTcpServer;
+      try {
+         sslTcpServer = sp.xnio.createSslTcpServer(listener, builder.getMap());
+      } catch (NoSuchProviderException e) {
+         throw new IOException(e);
+      } catch (NoSuchAlgorithmException e) {
+         throw new IOException(e);
+      }
+      IoFuture<? extends BoundChannel<InetSocketAddress>> future = sslTcpServer.bind(new InetSocketAddress("localhost", port));
+      getFutureResult(future, "unable to bind " + sp.tcpServer);
+      sp.tcpServer = sslTcpServer;
+      sp.port = sslTcpServer.getChannels().iterator().next().getLocalAddress().getPort();
+   }
+   
+   protected SslTcpServer getServer(final ChannelListener<ConnectedStreamChannel<InetSocketAddress>> listener, final Xnio xnio) throws NoSuchProviderException, NoSuchAlgorithmException {
+       final OptionMap serverOptions = OptionMap.builder()
+               .setSequence(Options.SSL_ENABLED_CIPHER_SUITES, CIPHER_SUITES)
+               .setSequence(Options.SSL_ENABLED_PROTOCOLS, PROTOCOLS)
+               .getMap();
+       return xnio.createSslTcpServer(listener, serverOptions);
+   }
+}



More information about the jboss-remoting-commits mailing list