Author: ron.sigal(a)jboss.com
Date: 2008-02-29 03:27:41 -0500 (Fri, 29 Feb 2008)
New Revision: 3544
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketServerSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketServerSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketSocketConfigurationTestCase.java
Log:
JBREM-703: New unit test.
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketServerSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketServerSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketServerSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,43 @@
+/*
+* 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.configuration;
+
+import
org.jboss.test.remoting.transport.socket.configuration.SocketServerSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class BisocketServerSocketConfigurationTestCase
+extends SocketServerSocketConfigurationTestCase
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/configuration/BisocketSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,43 @@
+/*
+* 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.configuration;
+
+import
org.jboss.test.remoting.transport.socket.configuration.SocketSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class BisocketSocketConfigurationTestCase
+extends SocketSocketConfigurationTestCase
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,54 @@
+/*
+* 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.ssl.config;
+
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.sslbisocket.SSLBisocketServerInvoker;
+import
org.jboss.test.remoting.transport.socket.ssl.config.SSLSocketServerSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SSLBisocketServerSocketConfigurationTestCase
+extends SSLSocketServerSocketConfigurationTestCase
+{
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+
+ protected void configureServerInvoker(SocketServerInvoker invoker)
+ {
+ super.configureServerInvoker(invoker);
+ SSLBisocketServerInvoker sslInvoker = (SSLBisocketServerInvoker) invoker;
+ sslInvoker.setEnabledCipherSuites(cipherSuites);
+ sslInvoker.setEnabledProtocols(protocols);
+ sslInvoker.setEnableSessionCreation(true);
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/config/SSLBisocketSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,43 @@
+/*
+* 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.ssl.config;
+
+import
org.jboss.test.remoting.transport.socket.ssl.config.SSLSocketSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SSLBisocketSocketConfigurationTestCase
+extends SSLSocketSocketConfigurationTestCase
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketServerSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketServerSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketServerSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,265 @@
+/*
+* 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.socket.configuration;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+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.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SocketServerSocketConfigurationTestCase extends TestCase
+{
+ private static Logger log =
Logger.getLogger(SocketServerSocketConfigurationTestCase.class);
+
+ protected static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testConfigureByConfigMap() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool pool = (LRUPool) field.get(invoker);
+ Set keys = pool.getContents();
+ assertEquals(1, keys.size());
+ ServerThread t = (ServerThread) keys.iterator().next();
+ field = ServerThread.class.getDeclaredField("socket");
+ field.setAccessible(true);
+ Socket socket = (Socket) field.get(t);
+ doSocketTest(socket);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConfigureBySetter() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool pool = (LRUPool) field.get(invoker);
+ Set keys = pool.getContents();
+ assertEquals(1, keys.size());
+ ServerThread t = (ServerThread) keys.iterator().next();
+ field = ServerThread.class.getDeclaredField("socket");
+ field.setAccessible(true);
+ Socket socket = (Socket) field.get(t);
+ doSocketTest(socket);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void doSocketTest(Socket s) throws SocketException
+ {
+ assertTrue(s.getKeepAlive());
+ assertTrue(s.getOOBInline());
+ assertEquals(2345, s.getReceiveBufferSize());
+ assertEquals(3456, s.getSendBufferSize());
+ assertEquals(4567, s.getSoLinger());
+ assertEquals(0, s.getTrafficClass());
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean useConfigMap) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ if (useConfigMap)
+ {
+ addServerSocketConfig(config);
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ if (!useConfigMap)
+ {
+ SocketServerInvoker invoker = (SocketServerInvoker)
connector.getServerInvoker();
+ configureServerInvoker(invoker);
+ }
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void addServerSocketConfig(Map config)
+ {
+ config.put("keepAlive", "true");
+ config.put("oOBInline", "true");
+ config.put("receiveBufferSize", "2345");
+ config.put("sendBufferSize", "3456");
+ config.put("soLinger", "true");
+ config.put("soLingerDuration", "4567");
+ config.put("trafficClass", "0");
+ }
+
+
+ protected void configureServerInvoker(SocketServerInvoker invoker)
+ {
+ invoker.setReceiveBufferSize(12345);
+
+ invoker.setKeepAlive(true);
+ invoker.setOOBInline(true);
+ invoker.setReceiveBufferSize(2345);
+ invoker.setSendBufferSize(3456);
+ invoker.setSoLinger(true);
+ invoker.setSoLingerDuration(4567);
+ invoker.setTrafficClass(0);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/configuration/SocketSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,202 @@
+/*
+* 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.socket.configuration;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+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.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SocketSocketConfigurationTestCase extends TestCase
+{
+ private static Logger log =
Logger.getLogger(SocketSocketConfigurationTestCase.class);
+
+ protected static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testConfigureByConfigMap() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ setupClient(clientConfig);
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ assertTrue(client.getInvoker() instanceof MicroSocketClientInvoker);
+ MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ LinkedList pool = (LinkedList) field.get(invoker);
+ assertTrue(pool.size() > 0);
+ SocketWrapper socketWrapper = (SocketWrapper) pool.get(0);
+ Socket socket = socketWrapper.getSocket();
+ doSocketTest(socket);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void setupClient(Map config)
+ {
+ config.put("keepAlive", "true");
+ config.put("oOBInline", "true");
+ config.put("receiveBufferSize", "2345");
+ config.put("sendBufferSize", "3456");
+ config.put("soLinger", "true");
+ config.put("soLingerDuration", "4567");
+ config.put("trafficClass", "0");
+ }
+
+
+ protected void doSocketTest(Socket s) throws SocketException
+ {
+ assertTrue(s.getKeepAlive());
+ assertTrue(s.getOOBInline());
+ assertEquals(2345, s.getReceiveBufferSize());
+ assertEquals(3456, s.getSendBufferSize());
+ assertEquals(4567, s.getSoLinger());
+ assertEquals(0, s.getTrafficClass());
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,193 @@
+/*
+* 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.socket.ssl.config;
+
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.sslsocket.SSLSocketServerInvoker;
+import
org.jboss.test.remoting.transport.socket.configuration.SocketServerSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SSLSocketServerSocketConfigurationTestCase
+extends SocketServerSocketConfigurationTestCase
+{
+ private static Logger log =
Logger.getLogger(SSLSocketServerSocketConfigurationTestCase.class);
+
+ static protected String[] cipherSuites;
+ static protected String[] protocols;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ super.setUp();
+
+ SSLSocket s = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
+
+ String[] strings = s.getSupportedCipherSuites();
+ log.info("supported cipher suites: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getEnabledCipherSuites();
+ log.info("enabled cipher suites: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getSupportedProtocols();
+ log.info("supported protocols: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getEnabledProtocols();
+ log.info("enabled protocols: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+
+ strings = s.getSupportedCipherSuites();
+ int len = strings.length - 1;
+ cipherSuites = new String[len];
+ for (int i = 0; i < len; i++)
+ cipherSuites[i] = strings[i];
+
+ strings = s.getSupportedProtocols();
+ len = strings.length - 1;
+ protocols = new String[len];
+ for (int i = 0; i < len; i++)
+ protocols[i] = strings[i];
+
+ log.info("using cipherSuites: ");
+ for (int i = 0; i < cipherSuites.length; i++)
+ log.info(" " + cipherSuites[i]);
+ log.info("using protocols: ");
+ for (int i = 0; i < protocols.length; i++)
+ log.info(" " + protocols[i]);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ protected void doSocketTest(Socket s) throws SocketException
+ {
+ assertTrue(s.getKeepAlive());
+ assertEquals(2345, s.getReceiveBufferSize());
+ assertEquals(3456, s.getSendBufferSize());
+ assertEquals(4567, s.getSoLinger());
+ assertEquals(0, s.getTrafficClass());
+
+ assertTrue(s instanceof SSLSocket);
+ SSLSocket ss = (SSLSocket) s;
+ assertTrue(ss.getEnableSessionCreation());
+
+ log.info("actual enabledCipherSuites: ");
+ String[] strings = ss.getEnabledCipherSuites();
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ assertEquals(cipherSuites, ss.getEnabledCipherSuites());
+ assertEquals(protocols, ss.getEnabledProtocols());
+ }
+
+
+ protected void assertEquals(String[] strings1, String[] strings2)
+ {
+ HashSet set1 = new HashSet();
+ for (int i = 0; i < strings1.length; i++)
+ set1.add(strings1[i]);
+ HashSet set2 = new HashSet();
+ for (int i = 0; i < strings2.length; i++)
+ set2.add(strings2[i]);
+ assertEquals(set1, set2);
+ }
+
+
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config)
+ {
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
+ String trustStoreFilePath =
this.getClass().getResource("../.truststore").getFile();
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD,
"unit-tests-client");
+ }
+
+
+ protected void addExtraServerConfig(Map config)
+ {
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
+ String keyStoreFilePath =
this.getClass().getResource("../.keystore").getFile();
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD,
"unit-tests-server");
+ }
+
+
+ protected void addServerSocketConfig(Map config)
+ {
+ super.addServerSocketConfig(config);
+ config.put("enabledCipherSuites", cipherSuites);
+ config.put("enabledProtocols", protocols);
+ config.put("enableSessionCreation", "true");
+ }
+
+
+ protected void configureServerInvoker(SocketServerInvoker invoker)
+ {
+ super.configureServerInvoker(invoker);
+ if (invoker instanceof SSLSocketServerInvoker)
+ {
+ SSLSocketServerInvoker sslInvoker = (SSLSocketServerInvoker) invoker;
+ sslInvoker.setEnabledCipherSuites(cipherSuites);
+ sslInvoker.setEnabledProtocols(protocols);
+ sslInvoker.setEnableSessionCreation(true);
+ }
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketSocketConfigurationTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketSocketConfigurationTestCase.java
(rev 0)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/config/SSLSocketSocketConfigurationTestCase.java 2008-02-29
08:27:41 UTC (rev 3544)
@@ -0,0 +1,181 @@
+/*
+* 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.socket.ssl.config;
+
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+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.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.sslsocket.SSLSocketServerInvoker;
+import
org.jboss.test.remoting.transport.socket.configuration.SocketServerSocketConfigurationTestCase;
+import
org.jboss.test.remoting.transport.socket.configuration.SocketSocketConfigurationTestCase;
+
+
+/**
+ * Unit test for JBREM-703.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 28, 2008
+ * </p>
+ */
+public class SSLSocketSocketConfigurationTestCase
+extends SocketSocketConfigurationTestCase
+{
+ private static Logger log =
Logger.getLogger(SSLSocketSocketConfigurationTestCase.class);
+
+ static protected String[] cipherSuites;
+ static protected String[] protocols;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ super.setUp();
+
+ SSLSocket s = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
+
+ String[] strings = s.getSupportedCipherSuites();
+ log.info("supported cipher suites: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getEnabledCipherSuites();
+ log.info("enabled cipher suites: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getSupportedProtocols();
+ log.info("supported protocols: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ strings = s.getEnabledProtocols();
+ log.info("enabled protocols: ");
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+
+ strings = s.getSupportedCipherSuites();
+ int len = strings.length - 1;
+ cipherSuites = new String[len];
+ for (int i = 0; i < len; i++)
+ cipherSuites[i] = strings[i];
+
+ strings = s.getSupportedProtocols();
+ len = strings.length - 1;
+ protocols = new String[len];
+ for (int i = 0; i < len; i++)
+ protocols[i] = strings[i];
+
+ log.info("using cipherSuites: ");
+ for (int i = 0; i < cipherSuites.length; i++)
+ log.info(" " + cipherSuites[i]);
+ log.info("using protocols: ");
+ for (int i = 0; i < protocols.length; i++)
+ log.info(" " + protocols[i]);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ protected void setupClient(Map config)
+ {
+ super.setupClient(config);
+ config.put("enabledCipherSuites", cipherSuites);
+ config.put("enabledProtocols", protocols);
+ config.put("enableSessionCreation", "true");
+ }
+
+
+ protected void doSocketTest(Socket s) throws SocketException
+ {
+ assertTrue(s.getKeepAlive());
+ assertEquals(2345, s.getReceiveBufferSize());
+ assertEquals(3456, s.getSendBufferSize());
+ assertEquals(4567, s.getSoLinger());
+ assertEquals(0, s.getTrafficClass());
+
+ assertTrue(s instanceof SSLSocket);
+ SSLSocket ss = (SSLSocket) s;
+ assertTrue(ss.getEnableSessionCreation());
+
+ log.info("actual enabledCipherSuites: ");
+ String[] strings = ss.getEnabledCipherSuites();
+ for (int i = 0; i < strings.length; i++)
+ log.info(" " + strings[i]);
+ assertEquals(cipherSuites, ss.getEnabledCipherSuites());
+ assertEquals(protocols, ss.getEnabledProtocols());
+ }
+
+
+ protected void assertEquals(String[] strings1, String[] strings2)
+ {
+ HashSet set1 = new HashSet();
+ for (int i = 0; i < strings1.length; i++)
+ set1.add(strings1[i]);
+ HashSet set2 = new HashSet();
+ for (int i = 0; i < strings2.length; i++)
+ set2.add(strings2[i]);
+ assertEquals(set1, set2);
+ }
+
+
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config)
+ {
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
+ String trustStoreFilePath =
this.getClass().getResource("../.truststore").getFile();
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
+ config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD,
"unit-tests-client");
+ }
+
+
+ protected void addExtraServerConfig(Map config)
+ {
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
+ String keyStoreFilePath =
this.getClass().getResource("../.keystore").getFile();
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
+ config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD,
"unit-tests-server");
+ }
+}
\ No newline at end of file