Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:23:46 -0500 (Wed, 15 Dec 2010)
New Revision: 6173
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java
Log:
JBREM-1144: New versioning tests.
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java 2010-12-15
23:23:46 UTC (rev 6173)
@@ -0,0 +1,221 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.remoting.versioning.identity;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+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.socket.LRUPool;
+import org.jboss.remoting.transport.socket.ServerSocketWrapper;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Versioning tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityVersionTestServer extends ServerTestCase
+{
+ public static int PORT = 6543;
+
+ private static Logger log = Logger.getLogger(ServerIdentityVersionTestServer.class);
+
+ protected String host;
+ protected int port;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ final ServerIdentityVersionTestServer p = new
ServerIdentityVersionTestServer();
+ Thread.sleep(300000);
+ p.tearDown();
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+
+ public void setUp() throws Exception
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
+
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);
+
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ // Start server.
+ setupServer(true);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Bounce server.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(true);
+ log.info("SET UP NEW SERVER");
+
+ Thread.sleep(15000);
+ shutdownServer();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ }
+
+
+ public void tearDown() throws Exception
+ {
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean useLeasing) throws Exception
+ {
+ String locatorURI = getTransport() + "://" + host + ":" + PORT
+ "/?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ if (useLeasing)
+ {
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE +
"=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD +
"=20000";
+ }
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ 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);
+ if (useLeasing)
+ {
+ connector.addConnectionListener(new TestConnectionListener());
+ }
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ {
+ SocketServerInvoker invoker = (SocketServerInvoker)
connector.getServerInvoker();
+ Field clientpoolField =
SocketServerInvoker.class.getDeclaredField("clientpool");
+ clientpoolField.setAccessible(true);
+ Field socketWrapperField =
ServerThread.class.getDeclaredField("socketWrapper");
+ socketWrapperField.setAccessible(true);
+ LRUPool clientpool = (LRUPool) clientpoolField.get(invoker);
+ Set threads = clientpool.getContents();
+ Iterator it = threads.iterator();
+ while (it.hasNext())
+ {
+ ServerThread t = (ServerThread) it.next();
+ ServerSocketWrapper socketWrapper = (ServerSocketWrapper)
socketWrapperField.get(t);
+ socketWrapper.close();
+ }
+ 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) {}
+ }
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed:
" + connectionFailed);
+ }
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java 2010-12-15
23:23:46 UTC (rev 6173)
@@ -0,0 +1,169 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.test.remoting.versioning.identity;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 29, 2010
+ * </p>
+ */
+public class ServerIdentityWithLeasingVersionTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+
addTestClasses("org.jboss.test.remoting.versioning.identity.ServerIdentityWithLeasingVersionTestClient",
+ 1,
+
"org.jboss.test.remoting.versioning.identity.ServerIdentityVersionTestServer");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedServerClasspath()
+ {
+ return System.getProperty("server.path");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedClientClasspath()
+ {
+ return System.getProperty("client.path");
+ }
+
+ protected String getClientJVMArguments()
+ {
+ String prop = System.getProperty("client.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("client.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("client.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("client arg: " + args);
+ return args;
+ }
+
+
+ protected String getServerJVMArguments()
+ {
+ String prop = System.getProperty("server.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("server.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("server.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ prop = System.getProperty("clientImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DclientImplementsServerIdentity=" + prop;
+ }
+ prop = System.getProperty("serverImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DserverImplementsServerIdentity=" + prop;
+ }
+ System.out.println("server arg: " + args);
+ return args;
+ }
+
+
+ protected Level getTestHarnessLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ protected Level getTestLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ /**
+ * How long to wait for test results to be returned from the client(s). If goes
longer than the
+ * specified limit, will throw an exception and kill the running test cases. Default
value is
+ * RESULTS_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getResultsTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long for the server test case to wait for tear down message. If exceeds
timeout,
+ * will throw exception. The default value is TEARDOWN_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getTearDownTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long to allow each of the test cases to run their tests. If exceeds this
timeout
+ * will throw exception and kill tests. The default value is RUN_TEST_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getRunTestTimeout()
+ {
+ return 60000;
+ }
+
+
+}
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java 2010-12-15
23:23:46 UTC (rev 6173)
@@ -0,0 +1,223 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.test.remoting.versioning.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+
+
+/**
+ * Versioning Unit tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityWithLeasingVersionTestClient extends TestCase
+{
+ private static Logger log =
Logger.getLogger(ServerIdentityWithLeasingVersionTestClient.class);
+ private String host;
+ private boolean clientImplementsServerIdentity;
+ private boolean serverImplementsServerIdentity;
+ protected ByteArrayOutputStream baosOut;
+ protected PrintStream originalOutPrintStream;
+ protected ByteArrayOutputStream baosErr;
+ protected PrintStream originalErrPrintStream;
+
+ public void setUp() throws Exception
+ {
+ clientImplementsServerIdentity =
Boolean.getBoolean("clientImplementsServerIdentity");
+ serverImplementsServerIdentity =
Boolean.getBoolean("serverImplementsServerIdentity");
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ originalOutPrintStream = System.out;
+ baosOut = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baosOut);
+ System.setOut(ps);
+
+ originalErrPrintStream = System.err;
+ baosErr = new ByteArrayOutputStream();
+ ps = new PrintStream(baosErr);
+ System.setErr(ps);
+ }
+
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
+ 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);
+
+ log.info(this + " clientImplementsServerIdentity: " +
clientImplementsServerIdentity);
+ log.info(this + " serverImplementsServerIdentity: " +
serverImplementsServerIdentity);
+ log.info(this + " host: " + host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+ log.info(this + "clientLocator: " + clientLocator);
+ 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 connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Run appropriate test.
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ assertTrue(doServerIdentitySupportedTest(client));
+ }
+ else
+ {
+ assertTrue(doServerIdentityUnsupportedTest(client));
+ }
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + host + ":" +
ServerIdentityVersionTestServer.PORT + "/?" +
Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD +
"=20000";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ return locatorURI;
+ }
+
+
+ protected boolean doServerIdentitySupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity supported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces (assuming the server identity
+ // facility is available.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " +
listener.connectionFailed);
+
+ System.setOut(originalOutPrintStream);
+ String sOut = new String(baosOut.toByteArray());
+ System.out.println(sOut);
+ System.setErr(originalErrPrintStream);
+ String sErr = new String(baosErr.toByteArray());
+ System.out.println(sErr);
+
+ return listener.connectionFailed && (sOut.indexOf("detected new
serverId:") > -1 || sErr.indexOf("detected new serverId:") > -1);
+
+ }
+
+
+ protected boolean doServerIdentityUnsupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity unsupported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "1000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow ConnectionValidator to run for a while.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " +
listener.connectionFailed);
+ return !listener.connectionFailed;
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed:
" + connectionFailed);
+ }
+
+ }
+}
\ No newline at end of file
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java 2010-12-15
23:23:46 UTC (rev 6173)
@@ -0,0 +1,169 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.test.remoting.versioning.identity;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 29, 2010
+ * </p>
+ */
+public class ServerIdentityWithoutLeasingVersionTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+
addTestClasses("org.jboss.test.remoting.versioning.identity.ServerIdentityWithoutLeasingVersionTestClient",
+ 1,
+
"org.jboss.test.remoting.versioning.identity.ServerIdentityVersionTestServer");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedServerClasspath()
+ {
+ return System.getProperty("server.path");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedClientClasspath()
+ {
+ return System.getProperty("client.path");
+ }
+
+ protected String getClientJVMArguments()
+ {
+ String prop = System.getProperty("client.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("client.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("client.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("client arg: " + args);
+ return args;
+ }
+
+
+ protected String getServerJVMArguments()
+ {
+ String prop = System.getProperty("server.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("server.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("server.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ prop = System.getProperty("clientImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DclientImplementsServerIdentity=" + prop;
+ }
+ prop = System.getProperty("serverImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DserverImplementsServerIdentity=" + prop;
+ }
+ System.out.println("server arg: " + args);
+ return args;
+ }
+
+
+ protected Level getTestHarnessLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ protected Level getTestLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ /**
+ * How long to wait for test results to be returned from the client(s). If goes
longer than the
+ * specified limit, will throw an exception and kill the running test cases. Default
value is
+ * RESULTS_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getResultsTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long for the server test case to wait for tear down message. If exceeds
timeout,
+ * will throw exception. The default value is TEARDOWN_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getTearDownTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long to allow each of the test cases to run their tests. If exceeds this
timeout
+ * will throw exception and kill tests. The default value is RUN_TEST_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getRunTestTimeout()
+ {
+ return 60000;
+ }
+
+
+}
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java
(rev 0)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java 2010-12-15
23:23:46 UTC (rev 6173)
@@ -0,0 +1,198 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.test.remoting.versioning.identity;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+
+
+/**
+ * Versioning Unit tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityWithoutLeasingVersionTestClient extends TestCase
+{
+ private static Logger log =
Logger.getLogger(ServerIdentityWithoutLeasingVersionTestClient.class);
+ private static boolean firstTime = true;
+
+ private String host;
+ private boolean clientImplementsServerIdentity;
+ private boolean serverImplementsServerIdentity;
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
+ 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);
+ }
+
+ clientImplementsServerIdentity =
Boolean.getBoolean("clientImplementsServerIdentity");
+ serverImplementsServerIdentity =
Boolean.getBoolean("serverImplementsServerIdentity");
+ host = InetAddress.getLocalHost().getHostAddress();
+ log.info(this + " clientImplementsServerIdentity: " +
clientImplementsServerIdentity);
+ log.info(this + " serverImplementsServerIdentity: " +
serverImplementsServerIdentity);
+ log.info(this + " host: " + host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithoutLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+ log.info(this + "clientLocator: " + clientLocator);
+ 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 connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Run appropriate test.
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ assertTrue(doServerIdentitySupportedTest(client));
+ }
+ else
+ {
+ assertTrue(doServerIdentityUnsupportedTest(client));
+ }
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + host + ":" +
ServerIdentityVersionTestServer.PORT + "/?" +
Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ return locatorURI;
+ }
+
+
+ protected boolean doServerIdentitySupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity supported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces (assuming the server identity
+ // facility is available.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " +
listener.connectionFailed);
+ return listener.connectionFailed;
+ }
+
+
+ protected boolean doServerIdentityUnsupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity unsupported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "1000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow ConnectionValidator to run for a while.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " +
listener.connectionFailed);
+ return !listener.connectionFailed;
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed:
" + connectionFailed);
+ }
+
+ }
+}
\ No newline at end of file