From jboss-remoting-commits at lists.jboss.org Fri Feb 29 03:27:42 2008 Content-Type: multipart/mixed; boundary="===============6796280644373336470==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r3544 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport: bisocket/ssl/config and 2 other directories. Date: Fri, 29 Feb 2008 03:27:41 -0500 Message-ID: --===============6796280644373336470== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/bisoc= ket/configuration/BisocketServerSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisoc= ket/configuration/BisocketSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisoc= ket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisoc= ket/ssl/config/SSLBisocketSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socke= t/configuration/SocketServerSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socke= t/configuration/SocketSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socke= t/ssl/config/SSLSocketServerSocketConfigurationTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socke= t/ssl/config/SSLSocketSocketConfigurationTestCase.java Log: JBREM-703: New unit test. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/b= isocket/configuration/BisocketServerSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/configuration/BisocketServerSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/configuration/BisocketServerSocketConfigurationTestCase.java 2008-02-2= 9 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.SocketServer= SocketConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +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/b= isocket/configuration/BisocketSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/configuration/BisocketSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/configuration/BisocketSocketConfigurationTestCase.java 2008-02-29 08:2= 7: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.SocketSocket= ConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +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/b= isocket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/config/SSLBisocketServerSocketConfigurationTestCase.java 2008-02-2= 9 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.SSLSocketServer= SocketConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +public class SSLBisocketServerSocketConfigurationTestCase +extends SSLSocketServerSocketConfigurationTestCase +{ + protected String getTransport() + { + return "sslbisocket"; + } + = + protected void configureServerInvoker(SocketServerInvoker invoker) + { + super.configureServerInvoker(invoker); + SSLBisocketServerInvoker sslInvoker =3D (SSLBisocketServerInvoker) i= nvoker; + 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/b= isocket/ssl/config/SSLBisocketSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/config/SSLBisocketSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/ssl/config/SSLBisocketSocketConfigurationTestCase.java 2008-02-29 08:2= 7: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.SSLSocketSocket= ConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +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/s= ocket/configuration/SocketServerSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/configuration/SocketServerSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/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 Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +public class SocketServerSocketConfigurationTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(SocketServerSocketConfig= urationTestCase.class); + = + protected static boolean firstTime =3D 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 =3D false; + Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO); + Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO); + String pattern =3D "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n"; + PatternLayout layout =3D new PatternLayout(pattern); + ConsoleAppender consoleAppender =3D 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 =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + Client client =3D 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 =3D (SocketServerInvoker) connector.getS= erverInvoker(); + Field field =3D SocketServerInvoker.class.getDeclaredField("clientpo= ol"); + field.setAccessible(true); + LRUPool pool =3D (LRUPool) field.get(invoker); + Set keys =3D pool.getContents(); + assertEquals(1, keys.size()); + ServerThread t =3D (ServerThread) keys.iterator().next(); + field =3D ServerThread.class.getDeclaredField("socket"); + field.setAccessible(true); + Socket socket =3D (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 =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + Client client =3D 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 =3D (SocketServerInvoker) connector.getS= erverInvoker(); + Field field =3D SocketServerInvoker.class.getDeclaredField("clientpo= ol"); + field.setAccessible(true); + LRUPool pool =3D (LRUPool) field.get(invoker); + Set keys =3D pool.getContents(); + assertEquals(1, keys.size()); + ServerThread t =3D (ServerThread) keys.iterator().next(); + field =3D ServerThread.class.getDeclaredField("socket"); + field.setAccessible(true); + Socket socket =3D (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 =3D InetAddress.getLocalHost().getHostAddress(); + port =3D PortUtil.findFreePort(host); + locatorURI =3D getTransport() + "://" + host + ":" + port; = + serverLocator =3D new InvokerLocator(locatorURI); + log.info("Starting remoting server with locator uri of: " + locatorU= RI); + HashMap config =3D new HashMap(); + config.put(InvokerLocator.FORCE_REMOTE, "true"); + if (useConfigMap) + { + addServerSocketConfig(config); + } + addExtraServerConfig(config); + connector =3D new Connector(serverLocator, config); + connector.create(); + if (!useConfigMap) + { + SocketServerInvoker invoker =3D (SocketServerInvoker) connector.g= etServerInvoker(); + configureServerInvoker(invoker); + } + invocationHandler =3D 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 !=3D null) + connector.stop(); + } + = + = + static class TestInvocationHandler implements ServerInvocationHandler + { + public void addListener(InvokerCallbackHandler callbackHandler) {} + public Object invoke(final InvocationRequest invocation) throws Thro= wable + { + 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/s= ocket/configuration/SocketSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/configuration/SocketSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/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 Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +public class SocketSocketConfigurationTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(SocketSocketConfiguratio= nTestCase.class); + = + protected static boolean firstTime =3D 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 =3D false; + Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO); + Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO); + String pattern =3D "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n"; + PatternLayout layout =3D new PatternLayout(pattern); + ConsoleAppender consoleAppender =3D 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 =3D new InvokerLocator(locatorURI); + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + setupClient(clientConfig); + addExtraClientConfig(clientConfig); + Client client =3D 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 =3D (MicroSocketClientInvoker) clie= nt.getInvoker(); + Field field =3D MicroSocketClientInvoker.class.getDeclaredField("poo= l"); + field.setAccessible(true); + LinkedList pool =3D (LinkedList) field.get(invoker); + assertTrue(pool.size() > 0); + SocketWrapper socketWrapper =3D (SocketWrapper) pool.get(0); + Socket socket =3D 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 =3D InetAddress.getLocalHost().getHostAddress(); + port =3D PortUtil.findFreePort(host); + locatorURI =3D getTransport() + "://" + host + ":" + port; = + serverLocator =3D new InvokerLocator(locatorURI); + log.info("Starting remoting server with locator uri of: " + locatorU= RI); + HashMap config =3D new HashMap(); + config.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraServerConfig(config); + connector =3D new Connector(serverLocator, config); + connector.create(); + invocationHandler =3D new TestInvocationHandler(); + connector.addInvocationHandler("test", invocationHandler); + connector.start(); + } + = + = + protected void shutdownServer() throws Exception + { + if (connector !=3D null) + connector.stop(); + } + = + = + static class TestInvocationHandler implements ServerInvocationHandler + { + public void addListener(InvokerCallbackHandler callbackHandler) {} + public Object invoke(final InvocationRequest invocation) throws Thro= wable + { + 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/s= ocket/ssl/config/SSLSocketServerSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/ssl/config/SSLSocketServerSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/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.SocketServer= SocketConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +public class SSLSocketServerSocketConfigurationTestCase +extends SocketServerSocketConfigurationTestCase +{ + private static Logger log =3D Logger.getLogger(SSLSocketServerSocketCon= figurationTestCase.class); + = + static protected String[] cipherSuites; + static protected String[] protocols; + + = + public void setUp() throws Exception + { = + if (firstTime) + { + super.setUp(); + = + SSLSocket s =3D (SSLSocket) SSLSocketFactory.getDefault().createS= ocket(); + = + String[] strings =3D s.getSupportedCipherSuites(); + log.info("supported cipher suites: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getEnabledCipherSuites(); + log.info("enabled cipher suites: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getSupportedProtocols(); + log.info("supported protocols: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getEnabledProtocols(); + log.info("enabled protocols: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + + strings =3D s.getSupportedCipherSuites(); + int len =3D strings.length - 1; + cipherSuites =3D new String[len]; + for (int i =3D 0; i < len; i++) + cipherSuites[i] =3D strings[i]; + = + strings =3D s.getSupportedProtocols(); + len =3D strings.length - 1; + protocols =3D new String[len]; + for (int i =3D 0; i < len; i++) + protocols[i] =3D strings[i]; + = + log.info("using cipherSuites: "); + for (int i =3D 0; i < cipherSuites.length; i++) + log.info(" " + cipherSuites[i]); + log.info("using protocols: "); + for (int i =3D 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 =3D (SSLSocket) s; + assertTrue(ss.getEnableSessionCreation()); + = + log.info("actual enabledCipherSuites: "); + String[] strings =3D ss.getEnabledCipherSuites(); + for (int i =3D 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 =3D new HashSet(); + for (int i =3D 0; i < strings1.length; i++) + set1.add(strings1[i]); + HashSet set2 =3D new HashSet(); + for (int i =3D 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 =3D this.getClass().getResource("../.trust= store").getFile(); + config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustSto= reFilePath); + config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tes= ts-client"); + } + = + = + protected void addExtraServerConfig(Map config) + { + config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS"); + String keyStoreFilePath =3D this.getClass().getResource("../.keystor= e").getFile(); + config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFi= lePath); + 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 =3D (SSLSocketServerInvoker) in= voker; + sslInvoker.setEnabledCipherSuites(cipherSuites); + sslInvoker.setEnabledProtocols(protocols); + sslInvoker.setEnableSessionCreation(true); + } + } + = + = + protected void shutdownServer() throws Exception + { + if (connector !=3D null) + connector.stop(); + } +} \ No newline at end of file Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/s= ocket/ssl/config/SSLSocketSocketConfigurationTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/ssl/config/SSLSocketSocketConfigurationTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/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.SocketServer= SocketConfigurationTestCase; +import org.jboss.test.remoting.transport.socket.configuration.SocketSocket= ConfigurationTestCase; + + +/** + * Unit test for JBREM-703. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Feb 28, 2008 + *

+ */ +public class SSLSocketSocketConfigurationTestCase +extends SocketSocketConfigurationTestCase +{ + private static Logger log =3D Logger.getLogger(SSLSocketSocketConfigura= tionTestCase.class); + = + static protected String[] cipherSuites; + static protected String[] protocols; + + = + public void setUp() throws Exception + { = + if (firstTime) + { + super.setUp(); + = + SSLSocket s =3D (SSLSocket) SSLSocketFactory.getDefault().createS= ocket(); + = + String[] strings =3D s.getSupportedCipherSuites(); + log.info("supported cipher suites: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getEnabledCipherSuites(); + log.info("enabled cipher suites: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getSupportedProtocols(); + log.info("supported protocols: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + strings =3D s.getEnabledProtocols(); + log.info("enabled protocols: "); + for (int i =3D 0; i < strings.length; i++) + log.info(" " + strings[i]); + + strings =3D s.getSupportedCipherSuites(); + int len =3D strings.length - 1; + cipherSuites =3D new String[len]; + for (int i =3D 0; i < len; i++) + cipherSuites[i] =3D strings[i]; + = + strings =3D s.getSupportedProtocols(); + len =3D strings.length - 1; + protocols =3D new String[len]; + for (int i =3D 0; i < len; i++) + protocols[i] =3D strings[i]; + = + log.info("using cipherSuites: "); + for (int i =3D 0; i < cipherSuites.length; i++) + log.info(" " + cipherSuites[i]); + log.info("using protocols: "); + for (int i =3D 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 =3D (SSLSocket) s; + assertTrue(ss.getEnableSessionCreation()); + = + log.info("actual enabledCipherSuites: "); + String[] strings =3D ss.getEnabledCipherSuites(); + for (int i =3D 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 =3D new HashSet(); + for (int i =3D 0; i < strings1.length; i++) + set1.add(strings1[i]); + HashSet set2 =3D new HashSet(); + for (int i =3D 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 =3D this.getClass().getResource("../.trust= store").getFile(); + config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustSto= reFilePath); + config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tes= ts-client"); + } + = + = + protected void addExtraServerConfig(Map config) + { + config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS"); + String keyStoreFilePath =3D this.getClass().getResource("../.keystor= e").getFile(); + config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFi= lePath); + config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests= -server"); + } +} \ No newline at end of file --===============6796280644373336470==--