JBoss Remoting SVN: r6180 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 23:05:12 -0500 (Fri, 17 Dec 2010)
New Revision: 6180
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java
Log:
JBREM-1262: Added testConnectionAbortException().
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java 2010-12-18 04:02:56 UTC (rev 6179)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java 2010-12-18 04:05:12 UTC (rev 6180)
@@ -133,7 +133,16 @@
log.info(getName() + " PASSES");
}
+
+ public void testConnectionAbortException() throws Throwable
+ {
+ log.info("entering " + getName());
+ exceptionToThrow = new IOException("Software caused connection abort: socket write error");
+ doTest();
+ log.info(getName() + " PASSES");
+ }
+
protected void doTest() throws Throwable
{
// Start server.
13 years, 11 months
JBoss Remoting SVN: r6179 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 23:02:56 -0500 (Fri, 17 Dec 2010)
New Revision: 6179
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1262: Added IOException("*connection abort*") to set of retriable exceptions.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-12-18 02:23:26 UTC (rev 6178)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-12-18 04:02:56 UTC (rev 6179)
@@ -139,7 +139,7 @@
public static long serializeTime = 0;
public static long deserializeTime = 0;
- private static final String patternString = "^.*(?:connection.*reset|connection.*closed|broken.*pipe|connection.*shutdown).*$";
+ private static final String patternString = "^.*(?:connection.*reset|connection.*closed|connection.*abort|broken.*pipe|connection.*shutdown).*$";
private static final Pattern RETRIABLE_ERROR_MESSAGE = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
/**
13 years, 11 months
JBoss Remoting SVN: r6178 - in remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket: dos and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 21:23:26 -0500 (Fri, 17 Dec 2010)
New Revision: 6178
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
Log:
JBREM-1261: New unit test.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java 2010-12-18 02:23:26 UTC (rev 6178)
@@ -0,0 +1,287 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.dos;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+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.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.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Oct 13, 2010
+ * </p>
+ */
+public class DosTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(DosTestCase.class);
+ private static final String CALLBACK_TEST = "callbackTest";
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected int secondaryPort;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected Object lock = new Object();
+ protected boolean dosAttackThreadRan;
+ protected boolean secondCallbackRan;
+
+
+ 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()
+ {
+ }
+
+ public void testDosAttack() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ final Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("client is connected");
+
+ // Add callback handler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ client.addListener(callbackHandler, metadata);
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.counter);
+ log.info("callback handler is installed");
+
+ // Test DOS attack.
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ Socket s = new Socket(host, secondaryPort);
+ log.info(this + " created socket " + s);
+ synchronized (lock)
+ {
+ dosAttackThreadRan = true;
+ }
+ }
+ catch (IOException e)
+ {
+ log.error("unable to connect to secondaryPort: " + secondaryPort, e);
+ }
+ finally
+ {
+ synchronized (lock)
+ {
+ lock.notifyAll();
+ }
+ }
+ }
+ }.start();
+
+ Thread.sleep(2000);
+
+ synchronized (lock)
+ {
+ if (!dosAttackThreadRan)
+ {
+ long start = System.currentTimeMillis();
+ long end = start + 10000;
+ while (end - System.currentTimeMillis() > 0)
+ {
+ try
+ {
+ lock.wait(end - System.currentTimeMillis());
+ }
+ catch (InterruptedException e){
+
+ }
+ }
+ }
+ }
+
+ if (!dosAttackThreadRan)
+ {
+ fail("DOS attack thread did not run");
+ }
+
+
+ // DOS attack has occurred. Try to add another callback handler.
+ new Thread()
+ {
+ public void run()
+ {
+ TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
+ try
+ {
+
+ HashMap metadata = new HashMap();
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ client.addListener(callbackHandler2, metadata);
+ secondCallbackRan = true;
+ log.info(this + " second callback handler installed after DOS attack");
+ }
+ catch (Throwable e)
+ {
+ log.info(this + " second callback failed", e);
+ }
+ }
+ }.start();
+
+ Thread.sleep(10000);
+ assertTrue(secondCallbackRan);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ connector.stop();
+ }
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ secondaryPort = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?secondaryBindPort=" + secondaryPort;
+ 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);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public Set listeners = new HashSet();
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ listeners.add(callbackHandler);
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ if (CALLBACK_TEST.equals(invocation.getParameter()))
+ {
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ InvokerCallbackHandler handler = (InvokerCallbackHandler) it.next();
+ handler.handleCallback(new Callback("test"));
+ log.info(this + " sent callback");
+ }
+ }
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public int counter;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info(this + " received callback");
+ counter++;
+ }
+ }
+}
\ No newline at end of file
13 years, 11 months
JBoss Remoting SVN: r6177 - remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 21:22:42 -0500 (Fri, 17 Dec 2010)
New Revision: 6177
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
JBREM-1261: Moved new socket processing in SecondaryServerSocketThread to separate thread.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2010-12-18 02:15:15 UTC (rev 6176)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2010-12-18 02:22:42 UTC (rev 6177)
@@ -881,41 +881,7 @@
{
Socket socket = secondaryServerSocket.accept();
if (log.isTraceEnabled()) log.trace("accepted: " + socket);
- DataInputStream dis = new DataInputStream(socket.getInputStream());
- int action = dis.read();
- String listenerId = dis.readUTF();
-
- switch (action)
- {
- case Bisocket.CREATE_CONTROL_SOCKET:
- BisocketClientInvoker.transferSocket(listenerId, socket, true);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: created control socket: (" + socket + ")"+ listenerId);
- break;
-
- case Bisocket.RECREATE_CONTROL_SOCKET:
- BisocketClientInvoker invoker = BisocketClientInvoker.getBisocketCallbackClientInvoker(listenerId);
- if (invoker == null)
- {
- log.debug("received new control socket for unrecognized listenerId: " + listenerId);
- }
- else
- {
- invoker.replaceControlSocket(socket);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: recreated control socket: " + listenerId);
- }
- break;
-
- case Bisocket.CREATE_ORDINARY_SOCKET:
- BisocketClientInvoker.transferSocket(listenerId, socket, false);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: transferred socket: " + listenerId);
- break;
-
- default:
- log.error("unrecognized action on SecondaryServerSocketThread: " + action);
- }
+ processSocket(socket);
}
catch (IOException e)
{
@@ -928,6 +894,71 @@
}
}
+ void processSocket(final Socket socket) throws IOException
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ setName("processSocketThread: " + socket);
+ if (log.isTraceEnabled()) log.trace(this + " processing socket: " + socket);
+ try
+ {
+ DataInputStream dis = new DataInputStream(socket.getInputStream());
+ int action = dis.read();
+ String listenerId = dis.readUTF();
+
+ switch (action)
+ {
+ case Bisocket.CREATE_CONTROL_SOCKET:
+ BisocketClientInvoker.transferSocket(listenerId, socket, true);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: created control socket: (" + socket + ")"+ listenerId);
+ break;
+
+ case Bisocket.RECREATE_CONTROL_SOCKET:
+ BisocketClientInvoker invoker = BisocketClientInvoker.getBisocketCallbackClientInvoker(listenerId);
+ if (invoker == null)
+ {
+ log.debug("received new control socket for unrecognized listenerId: " + listenerId);
+ }
+ else
+ {
+ invoker.replaceControlSocket(socket);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: recreated control socket: " + listenerId);
+ }
+ break;
+
+ case Bisocket.CREATE_ORDINARY_SOCKET:
+ BisocketClientInvoker.transferSocket(listenerId, socket, false);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: transferred socket: " + listenerId);
+ break;
+
+ default:
+ log.error("unrecognized action on SecondaryServerSocketThread: " + action);
+ }
+ }
+ catch (IOException e)
+ {
+ if (running)
+ {
+ log.error(this + " unable to process socket", e);
+ }
+ else
+ {
+ log.debug(this + " unable to process socket", e);
+ }
+ }
+ finally
+ {
+ if (log.isTraceEnabled()) log.trace(this + " processed socket: " + socket);
+ }
+ }
+ }.start();
+ }
+
ServerSocket getServerSocket()
{
return secondaryServerSocket;
13 years, 11 months
JBoss Remoting SVN: r6176 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket: dos and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 21:15:15 -0500 (Fri, 17 Dec 2010)
New Revision: 6176
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
Log:
JBREM-1261: New unit test.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java 2010-12-18 02:15:15 UTC (rev 6176)
@@ -0,0 +1,287 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.dos;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+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.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.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Oct 13, 2010
+ * </p>
+ */
+public class DosTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(DosTestCase.class);
+ private static final String CALLBACK_TEST = "callbackTest";
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected int secondaryPort;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected Object lock = new Object();
+ protected boolean dosAttackThreadRan;
+ protected boolean secondCallbackRan;
+
+
+ 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()
+ {
+ }
+
+ public void testDosAttack() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ final Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("client is connected");
+
+ // Add callback handler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ client.addListener(callbackHandler, metadata);
+ client.invoke(CALLBACK_TEST);
+ assertEquals(1, callbackHandler.counter);
+ log.info("callback handler is installed");
+
+ // Test DOS attack.
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ Socket s = new Socket(host, secondaryPort);
+ log.info(this + " created socket " + s);
+ synchronized (lock)
+ {
+ dosAttackThreadRan = true;
+ }
+ }
+ catch (IOException e)
+ {
+ log.error("unable to connect to secondaryPort: " + secondaryPort, e);
+ }
+ finally
+ {
+ synchronized (lock)
+ {
+ lock.notifyAll();
+ }
+ }
+ }
+ }.start();
+
+ Thread.sleep(2000);
+
+ synchronized (lock)
+ {
+ if (!dosAttackThreadRan)
+ {
+ long start = System.currentTimeMillis();
+ long end = start + 10000;
+ while (end - System.currentTimeMillis() > 0)
+ {
+ try
+ {
+ lock.wait(end - System.currentTimeMillis());
+ }
+ catch (InterruptedException e){
+
+ }
+ }
+ }
+ }
+
+ if (!dosAttackThreadRan)
+ {
+ fail("DOS attack thread did not run");
+ }
+
+
+ // DOS attack has occurred. Try to add another callback handler.
+ new Thread()
+ {
+ public void run()
+ {
+ TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
+ try
+ {
+
+ HashMap metadata = new HashMap();
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ client.addListener(callbackHandler2, metadata);
+ secondCallbackRan = true;
+ log.info(this + " second callback handler installed after DOS attack");
+ }
+ catch (Throwable e)
+ {
+ log.info(this + " second callback failed", e);
+ }
+ }
+ }.start();
+
+ Thread.sleep(10000);
+ assertTrue(secondCallbackRan);
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ connector.stop();
+ }
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ secondaryPort = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?secondaryBindPort=" + secondaryPort;
+ 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);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public Set listeners = new HashSet();
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ listeners.add(callbackHandler);
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ if (CALLBACK_TEST.equals(invocation.getParameter()))
+ {
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ InvokerCallbackHandler handler = (InvokerCallbackHandler) it.next();
+ handler.handleCallback(new Callback("test"));
+ log.info(this + " sent callback");
+ }
+ }
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public int counter;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info(this + " received callback");
+ counter++;
+ }
+ }
+}
\ No newline at end of file
13 years, 11 months
JBoss Remoting SVN: r6175 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-17 21:13:21 -0500 (Fri, 17 Dec 2010)
New Revision: 6175
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
JBREM-1261: Moved new socket processing in SecondaryServerSocketThread to separate thread.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2010-12-15 23:26:35 UTC (rev 6174)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2010-12-18 02:13:21 UTC (rev 6175)
@@ -1127,41 +1127,7 @@
}
if (log.isTraceEnabled()) log.trace("accepted: " + socket);
- DataInputStream dis = new DataInputStream(socket.getInputStream());
- int action = dis.read();
- String listenerId = dis.readUTF();
-
- switch (action)
- {
- case Bisocket.CREATE_CONTROL_SOCKET:
- BisocketClientInvoker.transferSocket(listenerId, socket, true);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: created control socket: (" + socket + ")"+ listenerId);
- break;
-
- case Bisocket.RECREATE_CONTROL_SOCKET:
- BisocketClientInvoker invoker = BisocketClientInvoker.getBisocketCallbackClientInvoker(listenerId);
- if (invoker == null)
- {
- log.debug("received new control socket for unrecognized listenerId: " + listenerId);
- }
- else
- {
- invoker.replaceControlSocket(socket);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: recreated control socket: " + listenerId);
- }
- break;
-
- case Bisocket.CREATE_ORDINARY_SOCKET:
- BisocketClientInvoker.transferSocket(listenerId, socket, false);
- if (log.isTraceEnabled())
- log.trace("SecondaryServerSocketThread: transferred socket: " + listenerId);
- break;
-
- default:
- log.error("unrecognized action on SecondaryServerSocketThread: " + action);
- }
+ processSocket(socket);
}
catch (IOException e)
{
@@ -1174,6 +1140,71 @@
}
}
+ void processSocket(final Socket socket) throws IOException
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ setName("processSocketThread: " + socket);
+ if (log.isTraceEnabled()) log.trace(this + " processing socket: " + socket);
+ try
+ {
+ DataInputStream dis = new DataInputStream(socket.getInputStream());
+ int action = dis.read();
+ String listenerId = dis.readUTF();
+
+ switch (action)
+ {
+ case Bisocket.CREATE_CONTROL_SOCKET:
+ BisocketClientInvoker.transferSocket(listenerId, socket, true);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: created control socket: (" + socket + ")"+ listenerId);
+ break;
+
+ case Bisocket.RECREATE_CONTROL_SOCKET:
+ BisocketClientInvoker invoker = BisocketClientInvoker.getBisocketCallbackClientInvoker(listenerId);
+ if (invoker == null)
+ {
+ log.debug("received new control socket for unrecognized listenerId: " + listenerId);
+ }
+ else
+ {
+ invoker.replaceControlSocket(socket);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: recreated control socket: " + listenerId);
+ }
+ break;
+
+ case Bisocket.CREATE_ORDINARY_SOCKET:
+ BisocketClientInvoker.transferSocket(listenerId, socket, false);
+ if (log.isTraceEnabled())
+ log.trace("SecondaryServerSocketThread: transferred socket: " + listenerId);
+ break;
+
+ default:
+ log.error("unrecognized action on SecondaryServerSocketThread: " + action);
+ }
+ }
+ catch (IOException e)
+ {
+ if (running)
+ {
+ log.error(this + " unable to process socket", e);
+ }
+ else
+ {
+ log.debug(this + " unable to process socket", e);
+ }
+ }
+ finally
+ {
+ if (log.isTraceEnabled()) log.trace(this + " processed socket: " + socket);
+ }
+ }
+ }.start();
+ }
+
ServerSocket getServerSocket()
{
return secondaryServerSocket;
13 years, 11 months
JBoss Remoting SVN: r6174 - remoting2/branches/2.2.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:26:35 -0500 (Wed, 15 Dec 2010)
New Revision: 6174
Modified:
remoting2/branches/2.2/build.xml
Log:
JBREM-1144: Added server identity versioning tests for versions that have a ConnectionValidator.
Modified: remoting2/branches/2.2/build.xml
===================================================================
--- remoting2/branches/2.2/build.xml 2010-12-15 23:23:46 UTC (rev 6173)
+++ remoting2/branches/2.2/build.xml 2010-12-15 23:26:35 UTC (rev 6174)
@@ -1669,6 +1669,8 @@
<param name="jboss-junit-configuration" value="${module.version.extension}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1682,6 +1684,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3_SP2-server"/>
@@ -1692,6 +1696,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1705,6 +1711,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3_SP1-server"/>
@@ -1715,6 +1723,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1728,6 +1738,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3-server"/>
@@ -1738,6 +1750,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1751,6 +1765,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP11-server"/>
@@ -1761,6 +1777,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1774,6 +1792,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP10-server"/>
@@ -1784,6 +1804,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1797,6 +1819,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP9-server"/>
@@ -1807,6 +1831,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1820,6 +1846,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP7-server"/>
@@ -1830,6 +1858,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1843,6 +1873,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP4-server"/>
@@ -1853,6 +1885,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1866,6 +1900,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP2-server"/>
@@ -1876,6 +1912,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1889,6 +1927,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP1-server"/>
@@ -1899,6 +1939,8 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -1912,6 +1954,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_GA-server"/>
@@ -1922,11 +1966,13 @@
<param name="client.version" value="2"/>
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
<!-- Current <- -> 2.2.0.SP4 -->
- <antcall target="tests.versioning.all_transports" inheritrefs="true">
+ <antcall target="tests.versioning.all_transports_but_bisocket" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_0_SP4-client"/>
<param name="client.classpath" value="${etc.dir}/lib/remoting_2_2_0_SP4/jboss-remoting.jar"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar"/>
@@ -1936,7 +1982,7 @@
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
</antcall>
- <antcall target="tests.versioning.all_transports" inheritrefs="true">
+ <antcall target="tests.versioning.all_transports_but_bisocket" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_0_SP4-server"/>
<param name="server.classpath" value="${etc.dir}/lib/remoting_2_2_0_SP4/jboss-remoting.jar"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar"/>
@@ -2167,7 +2213,9 @@
description="Runs remoting fuctional tests with different remoting versions for client and server."
depends="jars, tests.jars">
<mkdir dir="${output.tests.results}"/>
- <echo>Running: ${jboss-junit-configuration}</echo>
+ <echo>Running: ${jboss-junit-configuration}</echo>
+ <echo>clientImplementsServerIdentity: ${clientImplementsServerIdentity}</echo>
+ <echo>serverImplementsServerIdentity: ${serverImplementsServerIdentity}</echo>
<junit printsummary="true" fork="yes" includeantruntime="true">
<classpath>
<path refid="third_party.classpath"/>
@@ -2200,6 +2248,7 @@
<fileset dir="${tests.compile.dir}">
<include name="**/remoting/versioning/transport/**/*TestCase.class"/>
<include name="**/remoting/versioning/lease/**/*TestCase.class"/>
+ <include name="**/remoting/versioning/identity/*TestCase.class"/>
<exclude name="**/remoting/**/multiplex/**/*.class"/>
</fileset>
</batchtest>
13 years, 11 months
JBoss Remoting SVN: r6173 - in remoting2/branches/2.2/src/tests/org/jboss/test/remoting/versioning: identity and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
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
13 years, 11 months
JBoss Remoting SVN: r6172 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:23:21 -0500 (Wed, 15 Dec 2010)
New Revision: 6172
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java
Log:
JBREM-1144: New unit tests.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java 2010-12-15 23:23:21 UTC (rev 6172)
@@ -0,0 +1,291 @@
+/*
+* 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.connection.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 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.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.PortUtil;
+import org.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+import org.jboss.remoting.transport.socket.ServerSocketWrapper;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+
+/**
+ * Unit test for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerIdentityTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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();
+ port = PortUtil.findFreePort(host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithoutLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false);
+
+ // Create client. Adding "dummy=dummy" assures that InvokerRegistry will not create a
+ // LocalClientInvoker for the ConnectionValidator.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI + "&dummy=dummy");
+ 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");
+
+ // 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.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(false);
+ log.info("SET UP NEW SERVER");
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ assertTrue(listener.connectionFailed);
+
+ client.disconnect();
+ shutdownServer();
+
+ log.info(getName() + " PASSES");
+ }
+
+ public void testServerIdentityWithLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client. Adding "dummy=dummy" assures that InvokerRegistry will not create a
+ // LocalClientInvoker for the ConnectionValidator.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI + "&dummy=dummy");
+ 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");
+
+ // 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.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(true);
+ log.info("SET UP NEW SERVER");
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ assertTrue(listener.connectionFailed);
+
+ client.disconnect();
+ shutdownServer();
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean useLeasing) throws Exception
+ {
+ 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)
+ {
+ // Remoting versions 1.x and 2.2.x don't necessarily shut down all of their
+ // ServerThreads, so an exiting connection could connect to a ServerThread
+ // associated with the old ServerInvoker.
+ 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
13 years, 11 months
JBoss Remoting SVN: r6171 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:22:31 -0500 (Wed, 15 Dec 2010)
New Revision: 6171
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1144: Added useServerConnectionIdentity variable, which determines if a unique serverId is created.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java 2010-12-15 23:21:50 UTC (rev 6170)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java 2010-12-15 23:22:31 UTC (rev 6171)
@@ -38,6 +38,7 @@
import org.jboss.remoting.transport.PortUtil;
import org.jboss.remoting.util.LocalHostUtil;
import org.jboss.remoting.serialization.ClassLoaderUtility;
+import org.jboss.util.id.GUID;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.threadpool.ThreadPool;
@@ -265,6 +266,10 @@
protected boolean registerCallbackListeners = true;
protected boolean useClientConnectionIdentity;
+ protected boolean useServerConnectionIdentity;
+
+ /** Used by ConnectionValidator to detect a change of server. **/
+ protected String serverId = new GUID().toString();
// Constructors ---------------------------------------------------------------------------------
@@ -720,6 +725,16 @@
this.useClientConnectionIdentity = useClientConnectionIdentity;
}
+ public boolean isUseServerConnectionIdentity()
+ {
+ return useServerConnectionIdentity;
+ }
+
+ public void setUseServerConnectionIdentity(boolean useServerConnectionIdentity)
+ {
+ this.useServerConnectionIdentity = useServerConnectionIdentity;
+ }
+
public Object invoke(Object invoke) throws IOException
{
InvocationRequest request = null;
@@ -785,8 +800,29 @@
// Comes from ConnectionValidator configured to tie validation with lease.
boolean response = checkForClientLease(invokerSessionId);
if (trace) log.trace(this + " responding " + response + " to $PING$ for invoker sessionId " + invokerSessionId);
- return new Boolean(response);
+ if (metadata.get(Remoting.USE_SERVER_CONNECTION_IDENTITY) != null)
+ {
+ Map responseMap = new HashMap();
+ responseMap.put(Remoting.SERVER_ID, serverId);
+ if (trace) log.trace(this + " returning serverId: " + serverId);
+ return new InvocationResponse(invocation.getSessionId(), new Boolean(response), false, responseMap);
+ }
+ else
+ {
+ if (trace) log.trace(this + " not returning serverId: " + serverId);
+ return new Boolean(response);
+ }
}
+ else
+ {
+ if (metadata.get(Remoting.USE_SERVER_CONNECTION_IDENTITY) != null)
+ {
+ Map responseMap = new HashMap();
+ responseMap.put(Remoting.SERVER_ID, serverId);
+ if (trace) log.trace(this + " returning serverId: " + serverId);
+ return new InvocationResponse(invocation.getSessionId(), null, false, responseMap);
+ }
+ }
}
if (leaseManagement)
@@ -1182,6 +1218,13 @@
useClientConnectionIdentity = Boolean.valueOf(useClientConnectionIdentityString).booleanValue();
}
+ // config for useServerConnectionIdentity
+ String useServerConnectionIdentityString = (String)config.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if(useServerConnectionIdentityString != null)
+ {
+ useServerConnectionIdentity = Boolean.valueOf(useServerConnectionIdentityString).booleanValue();
+ }
+
// Inject ConnectionListener
String connectionListener = (String)config.get(CONNECTION_LISTENER);
if (connectionListener != null)
13 years, 11 months