[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/config ...
Ron Sigal
ron_sigal at yahoo.com
Fri Oct 19 15:32:22 EDT 2007
User: rsigal
Date: 07/10/19 15:32:22
Added: src/tests/org/jboss/test/remoting/transport/config Tag:
remoting_2_x TestServerInvocationHandler1.java
TestServerInvocationHandler2.java
TestServerSocketFactory.java
POJOConfigurationTestCase.java
AbstractInvocationHandler.java
Log:
JBREM-63: New unit test.
Revision Changes Path
No revision
No revision
1.1.2.1 +44 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/Attic/TestServerInvocationHandler1.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TestServerInvocationHandler1.java
===================================================================
RCS file: TestServerInvocationHandler1.java
diff -N TestServerInvocationHandler1.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TestServerInvocationHandler1.java 19 Oct 2007 19:32:21 -0000 1.1.2.1
@@ -0,0 +1,44 @@
+/*
+* 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.config;
+
+import javax.management.MBeanServer;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+
+/**
+ * Used by POJOConfigurationTestCase.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Oct 19, 2007
+ * </p>
+ */
+public class TestServerInvocationHandler1 extends AbstractInvocationHandler
+{
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(InvocationRequest invocation) throws Throwable {return null;}
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+}
1.1.2.1 +44 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/Attic/TestServerInvocationHandler2.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TestServerInvocationHandler2.java
===================================================================
RCS file: TestServerInvocationHandler2.java
diff -N TestServerInvocationHandler2.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TestServerInvocationHandler2.java 19 Oct 2007 19:32:21 -0000 1.1.2.1
@@ -0,0 +1,44 @@
+/*
+* 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.config;
+
+import javax.management.MBeanServer;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+
+/**
+ * Used by POJOConfigurationTestCase.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Oct 19, 2007
+ * </p>
+ */
+public class TestServerInvocationHandler2 extends AbstractInvocationHandler
+{
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(InvocationRequest invocation) throws Throwable {return null;}
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+}
1.1.2.1 +56 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/Attic/TestServerSocketFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TestServerSocketFactory.java
===================================================================
RCS file: TestServerSocketFactory.java
diff -N TestServerSocketFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TestServerSocketFactory.java 19 Oct 2007 19:32:21 -0000 1.1.2.1
@@ -0,0 +1,56 @@
+/*
+* 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.config;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+
+import javax.net.ServerSocketFactory;
+
+/**
+ * Used by POJOConfigurationTestCase.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Oct 18, 2007
+ * </p>
+ */
+public class TestServerSocketFactory extends ServerSocketFactory
+{
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ return new ServerSocket(port);
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ return new ServerSocket(port, backlog);
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ return new ServerSocket(port, backlog, ifAddress);
+ }
+
+}
1.1.2.1 +199 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/Attic/POJOConfigurationTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: POJOConfigurationTestCase.java
===================================================================
RCS file: POJOConfigurationTestCase.java
diff -N POJOConfigurationTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ POJOConfigurationTestCase.java 19 Oct 2007 19:32:21 -0000 1.1.2.1
@@ -0,0 +1,199 @@
+/*
+* 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.config;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.net.ServerSocketFactory;
+
+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.remoting.InvokerLocator;
+import org.jboss.remoting.ServerConfiguration;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.transport.Connector;
+
+
+
+/**
+ *
+ * POJOConfigurationTestCase verifies that Remoting org.jboss.remoting.transport.Connector's
+ * are properly configured when using the new org.jboss.remoting.ServerConfiguration object.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Oct 16, 2007
+ * </p>
+ */
+public class POJOConfigurationTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(POJOConfigurationTestCase.class);
+
+ private static boolean firstTime = true;
+
+ private Connector connector;
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.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()
+ {
+ if (connector != null)
+ {
+ connector.destroy();
+ }
+ }
+
+
+ public void testConfiguration() throws Throwable
+ {
+ // Create ServerConfiguration
+ ServerConfiguration config = new ServerConfiguration("socket");
+ Map locatorConfig = new HashMap();
+
+ // Add invokerLocatorParameters
+ String address = InetAddress.getLocalHost().getHostAddress();
+ locatorConfig.put("serverBindAddress", address);
+ locatorConfig.put("serverBindPort", "4446");
+ locatorConfig.put("datatype", "test");
+ locatorConfig.put("timeout", "12345");
+ config.setInvokerLocatorParameters(locatorConfig);
+
+ // Add serverParameters
+ Map serverParameters = new HashMap();
+ serverParameters.put("clientLeasePeriod", "2345");
+ serverParameters.put("timeout", "54321");
+ ServerSocketFactory factory = new TestServerSocketFactory();
+ serverParameters.put("customServerSocketFactory", factory);
+ config.setServerParameters(serverParameters);
+
+ // Add invocation handlers
+ Map handlers = new HashMap();
+ handlers.put("system1", "org.jboss.test.remoting.transport.config.TestServerInvocationHandler1");
+ ServerInvocationHandler handler2 = new TestServerInvocationHandler2();
+ handlers.put("system2,system3", handler2);
+ config.setInvocationHandlers(handlers);
+
+ log.info("invokerLocatorParameters: " + config.getInvokerLocatorParameters());
+ log.info("serverParameters: " + config.getServerParameters());
+ log.info("invocationHandlers: " + config.getInvocationHandlers());
+
+ // Create Connector and get ServerInvoker
+ // Get ServerInvoker.
+ connector = new Connector();
+ connector.setServerConfiguration(config);
+ connector.create();
+ connector.start();
+ ServerInvoker invoker = connector.getServerInvoker();
+
+ // Check InvokerLocator.
+ InvokerLocator locator = invoker.getLocator();
+ log.info("constructed InvokerLocator: " + locator);
+ assertEquals("socket://" + address + ":4446/?datatype=test&timeout=12345", locator.getLocatorURI());
+
+ // Test parameter that appears only in invokerLocatorParameters.
+ assertEquals("test", invoker.getDataType());
+
+ // Test parameter that appears only in serverParameters.
+ assertEquals(2345, invoker.getLeasePeriod());
+
+ // Test parameter that appears in both invokerLocatorParameters and
+ // serverParameters. Verify that value in invokerLocatorParameters overrides.
+ assertEquals(12345, invoker.getTimeout());
+
+ // Test object injected into serverParameters.
+ assertTrue(invoker.getServerSocketFactory() instanceof TestServerSocketFactory);
+
+ // Test invocation handlers.
+ assertEquals(3, invoker.getInvocationHandlers().length);
+ assertEquals(3, invoker.getSupportedSubsystems().length);
+
+ ServerInvocationHandler sih1 = invoker.getInvocationHandler("system1");
+ ServerInvocationHandler sih2 = invoker.getInvocationHandler("system2");
+ ServerInvocationHandler sih3 = invoker.getInvocationHandler("system3");
+ assertTrue(sih1 instanceof TestServerInvocationHandler1);
+ assertTrue(sih2 instanceof TestServerInvocationHandler2);
+ assertTrue(sih3 instanceof TestServerInvocationHandler2);
+
+ AbstractInvocationHandler aih1 = (AbstractInvocationHandler) sih1;
+ AbstractInvocationHandler aih2 = (AbstractInvocationHandler) sih2;
+ AbstractInvocationHandler aih3 = (AbstractInvocationHandler) sih3;
+ assertEquals(invoker, aih1.getServerInvoker());
+ assertEquals(invoker, aih2.getServerInvoker());
+ assertEquals(invoker, aih3.getServerInvoker());
+ }
+
+
+ public void testClientConnectParameters() throws Throwable
+ {
+ // Create ServerConfiguration
+ ServerConfiguration config = new ServerConfiguration("socket");
+ Map locatorConfig = new HashMap();
+
+ // Add invokerLocatorParameters
+ String serverBindAddress = "localhost";
+ String serverBindPort = "4446";
+ String clientConnectAddress = InetAddress.getLocalHost().getHostAddress();
+ String clientConnectPort = "4447";
+ locatorConfig.put("serverBindAddress", serverBindAddress);
+ locatorConfig.put("serverBindPort", serverBindPort);
+ locatorConfig.put("clientConnectAddress", clientConnectAddress);
+ locatorConfig.put("clientConnectPort", clientConnectPort);
+ config.setInvokerLocatorParameters(locatorConfig);
+
+ log.info("invokerLocatorParameters: " + config.getInvokerLocatorParameters());
+ log.info("serverParameters: " + config.getServerParameters());
+ log.info("invocationHandlers: " + config.getInvocationHandlers());
+
+ // Create Connector and get ServerInvoker
+ // Get ServerInvoker.
+ connector = new Connector();
+ connector.setServerConfiguration(config);
+ connector.create();
+
+ // Check InvokerLocator.
+ InvokerLocator locator = connector.getLocator();
+ log.info("constructed InvokerLocator: " + locator);
+ assertEquals("socket://" + clientConnectAddress + ":" + clientConnectPort + "/",
+ locator.getLocatorURI());
+ }
+}
\ No newline at end of file
1.1.2.1 +49 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/config/Attic/AbstractInvocationHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractInvocationHandler.java
===================================================================
RCS file: AbstractInvocationHandler.java
diff -N AbstractInvocationHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractInvocationHandler.java 19 Oct 2007 19:32:21 -0000 1.1.2.1
@@ -0,0 +1,49 @@
+/*
+* 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.config;
+
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+
+/**
+ * Used by POJOConfigurationTestCase.
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1.2.1 $
+ * <p>
+ * Copyright Oct 19, 2007
+ * </p>
+ */
+public abstract class AbstractInvocationHandler implements ServerInvocationHandler
+{
+ private ServerInvoker serverInvoker;
+
+ public ServerInvoker getServerInvoker()
+ {
+ return serverInvoker;
+ }
+
+ public void setInvoker(ServerInvoker invoker)
+ {
+ serverInvoker = invoker;
+ }
+}
More information about the jboss-cvs-commits
mailing list