From jboss-remoting-commits at lists.jboss.org Wed Dec 15 18:10:42 2010 Content-Type: multipart/mixed; boundary="===============0922452435275797980==" 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: r6166 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning: identity and 1 other directory. Date: Wed, 15 Dec 2010 18:10:42 -0500 Message-ID: <201012152310.oBFNAgA5005603@svn01.web.mwc.hst.phx2.redhat.com> --===============0922452435275797980== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2010-12-15 18:10:41 -0500 (Wed, 15 Dec 2010) New Revision: 6166 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityVersionTestClientParent.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityVersionTestServer.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityWithLeasingVersionTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityWithLeasingVersionTestClient.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityWithoutLeasingVersionTestCase.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/iden= tity/ServerIdentityWithoutLeasingVersionTestClient.java Log: JBREM-1144: New versioning tests. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityVersionTestClientParent.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/versioning/ide= ntity/ServerIdentityVersionTestClientParent.java (r= ev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityVersionTestClientParent.java 2010-12-15 23:10:41 UTC (r= ev 6166) @@ -0,0 +1,48 @@ +/* +* 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.PrintStream; + +import junit.framework.TestCase; + +/** + * = + * @author Ron Sigal + * @version $Rev$ + *
+ * Copyright Dec 15, 2010 + *
+ */ +public class ServerIdentityVersionTestClientParent extends TestCase +{ + protected void setOut(final PrintStream ps) + { + System.setOut(ps); + } + = + = + protected void setErr(final PrintStream ps) + { + System.setErr(ps); + } +} Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityVersionTestServer.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/versioning/ide= ntity/ServerIdentityVersionTestServer.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityVersionTestServer.java 2010-12-15 23:10:41 UTC (rev 616= 6) @@ -0,0 +1,226 @@ +/* + * 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.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; +import org.jboss.util.id.GUID; + + +/** + * Versioning tests for JBREM-1144. + * = + * @author Ron Sigal + * @version $Rev$ + *+ * Copyright Nov 17, 2010 + *
+ */ +public class ServerIdentityVersionTestServer extends ServerTestCase +{ + public static int PORT =3D 6543; + + private static Logger log =3D Logger.getLogger(ServerIdentityVersionTes= tServer.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 =3D new ServerIdentityVer= sionTestServer(); + 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(Level.TRACE= ); + 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(lay= out); + Logger.getRootLogger().addAppender(consoleAppender); + + host =3D 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 =3D getTransport() + "://" + host + ":" + PORT + "= /?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=3Dtrue"; + if (useLeasing) + { + locatorURI +=3D "&" + InvokerLocator.CLIENT_LEASE + "=3Dtrue"; + locatorURI +=3D "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=3D20= 000"; + } + String metadata =3D System.getProperty("remoting.metadata"); + if (metadata !=3D null) + { + locatorURI +=3D "&" + metadata; + } + 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); + if (useLeasing) + { + connector.addConnectionListener(new TestConnectionListener()); + } + connector.start(); + } + + + protected void shutdownServer() throws Exception + { + if (connector !=3D null) + { + // Remoting versions 1.x and 2.2.x don't necessarily shut down al= l of their + // ServerThreads, so an exiting connection could connect to a Ser= verThread + // associated with the old ServerInvoker. + SocketServerInvoker invoker =3D (SocketServerInvoker) connector.g= etServerInvoker(); + Field clientpoolField =3D SocketServerInvoker.class.getDeclaredFi= eld("clientpool"); + clientpoolField.setAccessible(true); + Field socketWrapperField =3D ServerThread.class.getDeclaredField(= "socketWrapper"); + socketWrapperField.setAccessible(true); + LRUPool clientpool =3D (LRUPool) clientpoolField.get(invoker); + Set threads =3D clientpool.getContents(); + Iterator it =3D threads.iterator(); + while (it.hasNext()) + { + ServerThread t =3D (ServerThread) it.next(); + ServerSocketWrapper socketWrapper =3D (ServerSocketWrapper) so= cketWrapperField.get(t); + socketWrapper.close(); + log.info(this + " closed " + socketWrapper); + } + = + 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) {} + } + + static class TestConnectionListener implements ConnectionListener + { + public boolean connectionFailed; + public Throwable throwable; + + public void handleConnectionException(Throwable throwable, Client cl= ient) + { + connectionFailed =3D true; + this.throwable =3D throwable; + log.info(this + " received connection notification: connectionFai= led: " + connectionFailed); + } + } +} \ No newline at end of file Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityWithLeasingVersionTestCase.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/versioning/ide= ntity/ServerIdentityWithLeasingVersionTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityWithLeasingVersionTestCase.java 2010-12-15 23:10:41 UTC= (rev 6166) @@ -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 Ron Sigal + * @version $Rev$ + *+ * Copyright Nov 29, 2010 + *
+ */ +public class ServerIdentityWithLeasingVersionTestCase extends InvokerTestD= river +{ + public void declareTestClasses() + { + addTestClasses("org.jboss.test.remoting.versioning.identity.ServerId= entityWithLeasingVersionTestClient", + 1, + "org.jboss.test.remoting.versioning.identity.ServerId= entityVersionTestServer"); + } + = + /** + * 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 =3D System.getProperty("client.pre_2_0_compatible"); + String args =3D ""; + if (prop !=3D null && !"".equals(prop)) + { + args =3D "-Djboss.remoting.pre_2_0_compatible=3D" + prop; + } + else + { + prop =3D System.getProperty("client.version"); + if (prop !=3D null && !"".equals(prop)) + args =3D "-Djboss.remoting.version=3D" + prop; + } + prop =3D System.getProperty("client.check_connection"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -Dremoting.metadata=3Dsocket.check_connection=3D" + p= rop; + } + System.out.println("client arg: " + args); + return args; + } + + + protected String getServerJVMArguments() + { + String prop =3D System.getProperty("server.pre_2_0_compatible"); + String args =3D ""; + if (prop !=3D null && !"".equals(prop)) + { + args =3D "-Djboss.remoting.pre_2_0_compatible=3D" + prop; + } + else + { + prop =3D System.getProperty("server.version"); + if (prop !=3D null && !"".equals(prop)) + args =3D "-Djboss.remoting.version=3D" + prop; + } + prop =3D System.getProperty("server.check_connection"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -Dremoting.metadata=3Dsocket.check_connection=3D" + p= rop; + } + prop =3D System.getProperty("clientImplementsServerIdentity"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -DclientImplementsServerIdentity=3D" + prop; + } + prop =3D System.getProperty("serverImplementsServerIdentity"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -DserverImplementsServerIdentity=3D" + 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 c= ases. 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 exc= eeds 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.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityWithLeasingVersionTestClient.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/versioning/ide= ntity/ServerIdentityWithLeasingVersionTestClient.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityWithLeasingVersionTestClient.java 2010-12-15 23:10:41 U= TC (rev 6166) @@ -0,0 +1,220 @@ +/* +* 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 org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +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 Ron Sigal + * @version $Rev$ + *+ * Copyright Nov 17, 2010 + *
+ */ +public class ServerIdentityWithLeasingVersionTestClient extends ServerIden= tityVersionTestClientParent +{ + private static Logger log =3D Logger.getLogger(ServerIdentityWithLeasin= gVersionTestClient.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 =3D Boolean.getBoolean("clientImpleme= ntsServerIdentity"); + serverImplementsServerIdentity =3D Boolean.getBoolean("serverImpleme= ntsServerIdentity"); + host =3D InetAddress.getLocalHost().getHostAddress(); + + if (clientImplementsServerIdentity && serverImplementsServerIdentity) + { + originalOutPrintStream =3D System.out; + baosOut =3D new ByteArrayOutputStream(); + PrintStream ps =3D new PrintStream(baosOut); + setOut(ps); + = + originalErrPrintStream =3D System.err; + baosErr =3D new ByteArrayOutputStream(); + ps =3D new PrintStream(baosErr); + setErr(ps); + } + = + Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE); + 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); + + log.info(this + " clientImplementsServerIdentity: " + clientImplemen= tsServerIdentity); + log.info(this + " serverImplementsServerIdentity: " + serverImplemen= tsServerIdentity); = + log.info(this + " host: " + host); + } + + = + public void tearDown() + { + } + = + = + public void testServerIdentityWithLeasing() throws Throwable + { + log.info("entering " + getName()); + = + InvokerLocator clientLocator =3D new InvokerLocator(createLocatorURI= ()); + log.info(this + "clientLocator: " + clientLocator); + 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 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 =3D getTransport() + "://" + host + ":" + ServerId= entityVersionTestServer.PORT + "/?" + Remoting.USE_SERVER_CONNECTION_IDENTI= TY + "=3Dtrue"; + locatorURI +=3D "&" + InvokerLocator.CLIENT_LEASE + "=3Dtrue"; + locatorURI +=3D "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=3D20000= "; + String metadata =3D System.getProperty("remoting.metadata"); + if (metadata !=3D null) + { + locatorURI +=3D "&" + metadata; + } + return locatorURI; + } + = + = + protected boolean doServerIdentitySupportedTest(Client client) throws E= xception + { + log.info("running server identity supported test"); + = + // Install connection listener. + TestConnectionListener listener =3D new TestConnectionListener(); + HashMap metadata =3D 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 serve= r identity + // facility is available. + Thread.sleep(10000); + log.info(this + " listener.connectionFailed: " + listener.connection= Failed); + = + setOut(originalOutPrintStream); + String sOut =3D new String(baosOut.toByteArray()); + System.out.println(sOut); + setErr(originalErrPrintStream); + String sErr =3D new String(baosErr.toByteArray()); + System.out.println(sErr); + = + return listener.connectionFailed && (sOut.indexOf("detected new serv= erId:") > -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 =3D new TestConnectionListener(); + HashMap metadata =3D 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.connection= Failed); + return !listener.connectionFailed; + } + = + = + static class TestConnectionListener implements ConnectionListener + { + public boolean connectionFailed; + public Throwable throwable; + = + public void handleConnectionException(Throwable throwable, Client cl= ient) + { + connectionFailed =3D true; + this.throwable =3D throwable; + log.info(this + " received connection notification: connectionFai= led: " + connectionFailed); + } + = + } +} \ No newline at end of file Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityWithoutLeasingVersionTestCase.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/versioning/ide= ntity/ServerIdentityWithoutLeasingVersionTestCase.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityWithoutLeasingVersionTestCase.java 2010-12-15 23:10:41 = UTC (rev 6166) @@ -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 Ron Sigal + * @version $Rev$ + *+ * Copyright Nov 29, 2010 + *
+ */ +public class ServerIdentityWithoutLeasingVersionTestCase extends InvokerTe= stDriver +{ + public void declareTestClasses() + { + addTestClasses("org.jboss.test.remoting.versioning.identity.ServerId= entityWithoutLeasingVersionTestClient", + 1, + "org.jboss.test.remoting.versioning.identity.ServerId= entityVersionTestServer"); + } + = + /** + * 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 =3D System.getProperty("client.pre_2_0_compatible"); + String args =3D ""; + if (prop !=3D null && !"".equals(prop)) + { + args =3D "-Djboss.remoting.pre_2_0_compatible=3D" + prop; + } + else + { + prop =3D System.getProperty("client.version"); + if (prop !=3D null && !"".equals(prop)) + args =3D "-Djboss.remoting.version=3D" + prop; + } + prop =3D System.getProperty("client.check_connection"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -Dremoting.metadata=3Dsocket.check_connection=3D" + p= rop; + } + System.out.println("client arg: " + args); + return args; + } + + + protected String getServerJVMArguments() + { + String prop =3D System.getProperty("server.pre_2_0_compatible"); + String args =3D ""; + if (prop !=3D null && !"".equals(prop)) + { + args =3D "-Djboss.remoting.pre_2_0_compatible=3D" + prop; + } + else + { + prop =3D System.getProperty("server.version"); + if (prop !=3D null && !"".equals(prop)) + args =3D "-Djboss.remoting.version=3D" + prop; + } + prop =3D System.getProperty("server.check_connection"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -Dremoting.metadata=3Dsocket.check_connection=3D" + p= rop; + } + prop =3D System.getProperty("clientImplementsServerIdentity"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -DclientImplementsServerIdentity=3D" + prop; + } + prop =3D System.getProperty("serverImplementsServerIdentity"); + if (prop !=3D null && !"".equals(prop)) + { + args +=3D " -DserverImplementsServerIdentity=3D" + 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 c= ases. 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 exc= eeds 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.x/src/tests/org/jboss/test/remoting/versioning/= identity/ServerIdentityWithoutLeasingVersionTestClient.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/versioning/ide= ntity/ServerIdentityWithoutLeasingVersionTestClient.java = (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/ide= ntity/ServerIdentityWithoutLeasingVersionTestClient.java 2010-12-15 23:10:4= 1 UTC (rev 6166) @@ -0,0 +1,218 @@ +/* +* 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 org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +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 Ron Sigal + * @version $Rev$ + *+ * Copyright Nov 17, 2010 + *
+ */ +public class ServerIdentityWithoutLeasingVersionTestClient extends ServerI= dentityVersionTestClientParent +{ + private static Logger log =3D Logger.getLogger(ServerIdentityWithoutLea= singVersionTestClient.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 =3D Boolean.getBoolean("clientImpleme= ntsServerIdentity"); + serverImplementsServerIdentity =3D Boolean.getBoolean("serverImpleme= ntsServerIdentity"); + host =3D InetAddress.getLocalHost().getHostAddress(); + + if (clientImplementsServerIdentity && serverImplementsServerIdentity) + { + originalOutPrintStream =3D System.out; + baosOut =3D new ByteArrayOutputStream(); + PrintStream ps =3D new PrintStream(baosOut); + setOut(ps); + = + originalErrPrintStream =3D System.err; + baosErr =3D new ByteArrayOutputStream(); + ps =3D new PrintStream(baosErr); + setErr(ps); + } + = + Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE); + 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); + + log.info(this + " clientImplementsServerIdentity: " + clientImplemen= tsServerIdentity); + log.info(this + " serverImplementsServerIdentity: " + serverImplemen= tsServerIdentity); = + log.info(this + " host: " + host); + } + + = + public void tearDown() + { + } + = + = + public void testServerIdentityWithoutLeasing() throws Throwable + { + log.info("entering " + getName()); + = + InvokerLocator clientLocator =3D new InvokerLocator(createLocatorURI= ()); + log.info(this + "clientLocator: " + clientLocator); + 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 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 =3D getTransport() + "://" + host + ":" + ServerId= entityVersionTestServer.PORT + "/?" + Remoting.USE_SERVER_CONNECTION_IDENTI= TY + "=3Dtrue"; + String metadata =3D System.getProperty("remoting.metadata"); + if (metadata !=3D null) + { + locatorURI +=3D "&" + metadata; + } + return locatorURI; + } + = + = + protected boolean doServerIdentitySupportedTest(Client client) throws E= xception + { + log.info("running server identity supported test"); + = + // Install connection listener. + TestConnectionListener listener =3D new TestConnectionListener(); + HashMap metadata =3D 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 serve= r identity + // facility is available. + Thread.sleep(10000); + log.info(this + " listener.connectionFailed: " + listener.connection= Failed); + = + setOut(originalOutPrintStream); + String sOut =3D new String(baosOut.toByteArray()); + System.out.println(sOut); + setErr(originalErrPrintStream); + String sErr =3D new String(baosErr.toByteArray()); + System.out.println(sErr); + = + return listener.connectionFailed && (sOut.indexOf("detected new serv= erId:") > -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 =3D new TestConnectionListener(); + HashMap metadata =3D 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.connection= Failed); + return !listener.connectionFailed; + } + = + = + static class TestConnectionListener implements ConnectionListener + { + public boolean connectionFailed; + public Throwable throwable; + = + public void handleConnectionException(Throwable throwable, Client cl= ient) + { + connectionFailed =3D true; + this.throwable =3D throwable; + log.info(this + " received connection notification: connectionFai= led: " + connectionFailed); + } + = + } +} \ No newline at end of file --===============0922452435275797980==--