JBoss Remoting SVN: r5990 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:13:36 -0400 (Wed, 04 Aug 2010)
New Revision: 5990
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress/NewCompressingMarshallerTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress/NewCompressingMarshallerTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress/NewCompressingMarshallerTestCase.java 2010-08-05 01:12:41 UTC (rev 5989)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress/NewCompressingMarshallerTestCase.java 2010-08-05 01:13:36 UTC (rev 5990)
@@ -1,198 +1,198 @@
-/*
-* 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.marshall.compress;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.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.marshal.MarshalFactory;
-import org.jboss.remoting.marshal.compress.CompressingMarshaller;
-import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit test for JBREM-1077.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Jul 27, 2009
- * </p>
- */
-public class NewCompressingMarshallerTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(NewCompressingMarshallerTestCase.class);
-
- private static boolean firstTime = true;
- private static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
- private static int COUNT = 10000;
-
- 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(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);
-
- MarshalFactory.addMarshaller(CompressingMarshaller.DATATYPE,
- new CompressingMarshaller(),
- new CompressingUnMarshaller());
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testCompression() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < COUNT; i++)
- {
- String msg = sb.append(digits[i % 10]).toString();
- Object response = client.invoke(msg);
- assertEquals("error on invocation " + i, msg, response);
- if (i % (COUNT / 10) == 0)
- {
- log.info("OK: " + i);
- }
- }
-
- 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() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port + "/?datatype=" + CompressingMarshaller.DATATYPE;
- 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 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 TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* 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.marshall.compress;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.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.marshal.MarshalFactory;
+import org.jboss.remoting.marshal.compress.CompressingMarshaller;
+import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1077.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Jul 27, 2009
+ * </p>
+ */
+public class NewCompressingMarshallerTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(NewCompressingMarshallerTestCase.class);
+
+ private static boolean firstTime = true;
+ private static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+ private static int COUNT = 10000;
+
+ 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(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);
+
+ MarshalFactory.addMarshaller(CompressingMarshaller.DATATYPE,
+ new CompressingMarshaller(),
+ new CompressingUnMarshaller());
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCompression() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < COUNT; i++)
+ {
+ String msg = sb.append(digits[i % 10]).toString();
+ Object response = client.invoke(msg);
+ assertEquals("error on invocation " + i, msg, response);
+ if (i % (COUNT / 10) == 0)
+ {
+ log.info("OK: " + i);
+ }
+ }
+
+ 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() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?datatype=" + CompressingMarshaller.DATATYPE;
+ 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 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 TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/marshall/compress/NewCompressingMarshallerTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5989 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:12:41 -0400 (Wed, 04 Aug 2010)
New Revision: 5989
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/ExtraneousEqualsTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/ExtraneousEqualsTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/ExtraneousEqualsTestCase.java 2010-08-05 01:11:53 UTC (rev 5988)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/ExtraneousEqualsTestCase.java 2010-08-05 01:12:41 UTC (rev 5989)
@@ -1,81 +1,81 @@
-/*
-* 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.locator;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.remoting.InvokerLocator;
-
-
-public class ExtraneousEqualsTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ExtraneousEqualsTestCase.class);
-
- private static boolean firstTime = true;
-
- 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 testExtraneousEquals() throws Throwable
- {
- log.info("entering " + getName());
-
- // Create client.
- String locatorURI = "socket://localhost:8080/abc?xyz";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- log.info(locator.getLocatorURI());
- assertEquals(locator.getLocatorURI(), locatorURI);
-
- locatorURI = "socket://localhost:8080/abc?pqr=123&xyz";
- locator = new InvokerLocator(locatorURI);
- log.info(locator.getLocatorURI());
- assertEquals(locator.getLocatorURI(), locatorURI);
-
- locatorURI = "socket://localhost:8080/abc?pqr&xyz=123";
- locator = new InvokerLocator(locatorURI);
- log.info(locator.getLocatorURI());
- assertEquals(locator.getLocatorURI(), locatorURI);
-
- log.info(getName() + " PASSES");
- }
+/*
+* 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.locator;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.InvokerLocator;
+
+
+public class ExtraneousEqualsTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ExtraneousEqualsTestCase.class);
+
+ private static boolean firstTime = true;
+
+ 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 testExtraneousEquals() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ String locatorURI = "socket://localhost:8080/abc?xyz";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ log.info(locator.getLocatorURI());
+ assertEquals(locator.getLocatorURI(), locatorURI);
+
+ locatorURI = "socket://localhost:8080/abc?pqr=123&xyz";
+ locator = new InvokerLocator(locatorURI);
+ log.info(locator.getLocatorURI());
+ assertEquals(locator.getLocatorURI(), locatorURI);
+
+ locatorURI = "socket://localhost:8080/abc?pqr&xyz=123";
+ locator = new InvokerLocator(locatorURI);
+ log.info(locator.getLocatorURI());
+ assertEquals(locator.getLocatorURI(), locatorURI);
+
+ log.info(getName() + " PASSES");
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/ExtraneousEqualsTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java 2010-08-05 01:11:53 UTC (rev 5988)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java 2010-08-05 01:12:41 UTC (rev 5989)
@@ -1,133 +1,133 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.locator;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.remoting.InvokerLocator;
-
-
-/**
- * Unit tests for JBREM-1180.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Feb 17, 2010
- */
-public class MalformedLocatorTestCase extends TestCase
-{
- private ByteArrayOutputStream baos;
- private PrintStream originalPrintStream;
- private Logger log;
-
- public void setUp() throws Exception
- {
- originalPrintStream = System.out;
- baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- System.setOut(ps);
-
- 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);
- log = Logger.getLogger(MalformedLocatorTestCase.class);
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testMalformedLocatorDefaultLogging() throws Throwable
- {
- log.info("entering " + getName());
- String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- System.out.println(locatorURI + " -> " + locator);
- System.setOut(originalPrintStream);
- String s = new String(baos.toByteArray());
- System.out.println(s);
- assertTrue(s.indexOf("WARN") >= 0);
- assertTrue(s.indexOf("Host resolves to null") >= 0);
- System.out.println(getName() + " PASSES");
- }
-
-
- public void testMalformedLocatorLoggingTurnedOff() throws Throwable
- {
- log.info("entering " + getName());
- System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "true");
- String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- System.out.println(locatorURI + " -> " + locator);
- System.setOut(originalPrintStream);
- String s = new String(baos.toByteArray());
- System.out.println(s);
- assertTrue(s.indexOf("WARN") == -1);
- assertTrue(s.indexOf("Host resolves to null") == -1);
- System.out.println(getName() + " PASSES");
- }
-
-
- public void testMalformedLocatorLoggingTurnedOn() throws Throwable
- {
- log.info("entering " + getName());
- System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "false");
- String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- System.out.println(locatorURI + " -> " + locator);
- System.setOut(originalPrintStream);
- String s = new String(baos.toByteArray());
- System.out.println(s);
- assertTrue(s.indexOf("WARN") >= 0);
- assertTrue(s.indexOf("Host resolves to null") >= 0);
- System.out.println(getName() + " PASSES");
- }
-
-
- public void testWellformedLocator() throws Throwable
- {
- log.info("entering " + getName());
- String locatorURI = "bisocket://UNDERSCORE:4457//?JBM_clientMaxPoolSize=200";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- System.out.println(locatorURI + " -> " + locator);
- System.setOut(originalPrintStream);
- String s = new String(baos.toByteArray());
- System.out.println(s);
- assertTrue(s.indexOf("WARN") == -1);
- assertTrue(s.indexOf("Host resolves to null") == -1);
- System.out.println(getName() + " PASSES");
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.locator;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.InvokerLocator;
+
+
+/**
+ * Unit tests for JBREM-1180.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 17, 2010
+ */
+public class MalformedLocatorTestCase extends TestCase
+{
+ private ByteArrayOutputStream baos;
+ private PrintStream originalPrintStream;
+ private Logger log;
+
+ public void setUp() throws Exception
+ {
+ originalPrintStream = System.out;
+ baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ System.setOut(ps);
+
+ 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);
+ log = Logger.getLogger(MalformedLocatorTestCase.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testMalformedLocatorDefaultLogging() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOff() throws Throwable
+ {
+ log.info("entering " + getName());
+ System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "true");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOn() throws Throwable
+ {
+ log.info("entering " + getName());
+ System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "false");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testWellformedLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDERSCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5988 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:11:53 -0400 (Wed, 04 Aug 2010)
New Revision: 5988
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/InjectedConnectionListenerTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationFailureTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationTimeoutTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/InjectedConnectionListenerTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/InjectedConnectionListenerTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/InjectedConnectionListenerTestCase.java 2010-08-05 01:11:53 UTC (rev 5988)
@@ -1,225 +1,225 @@
-package org.jboss.test.remoting.lease;
-
-import java.io.ByteArrayInputStream;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-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.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.w3c.dom.Document;
-
-
-/**
- *
- * Unit test for JBREM-1010.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jul 18, 2008
- * </p>
- */
-public class InjectedConnectionListenerTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(InjectedConnectionListenerTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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);
- }
-
- TestConnectionListener.gotException = false;
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testInjectionWithClassName() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
- setupServer(TestConnectionListener.class.getName(), mbeanServer);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify ConnectionListener is notified.
- log.info("client disconnecting");
- client.disconnect();
- log.info("client disconnected");
- Thread.sleep(2000);
- assertTrue(TestConnectionListener.gotException);
-
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
-
- public void testInjectionWithMBean() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- String connectionListenerName = "jboss:type=connectionlistener";
- ObjectName objName = new ObjectName(connectionListenerName);
- MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
- TestConnectionListener listener = new TestConnectionListener();
- mbeanServer.registerMBean(listener, objName);
- setupServer(connectionListenerName, mbeanServer);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify ConnectionListener is notified.
- log.info("client disconnecting");
- client.disconnect();
- log.info("client disconnected");
- Thread.sleep(2000);
- assertTrue(TestConnectionListener.gotException);
-
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(String listener, MBeanServer mbeanServer) throws Exception
- {
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- Connector connector = new Connector(config);
- mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
-
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\"?>\n");
- buf.append("<config>");
- buf.append(" <invoker transport=\"" + getTransport() + "\">");
- buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>");
- buf.append(" <attribute name=\"serverBindPort\">" + port + "</attribute>");
- buf.append(" <attribute name=\"" + ServerInvoker.CONNECTION_LISTENER + "\">" + listener + "</attribute>");
- buf.append(" <attribute name=\"" + ServerInvoker.CLIENT_LEASE_PERIOD + "\">5000</attribute>");
- buf.append(" </invoker>");
- buf.append("</config>");
- ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
- Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
- connector.setConfiguration(xml.getDocumentElement());
- connector.create();
- connector.addInvocationHandler("test", new TestInvocationHandler());
- connector.start();
- locatorURI = connector.getInvokerLocator();
- log.info("Started remoting server with locator uri of: " + locatorURI);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- 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) {}
- }
-
-
- public interface TestConnectionListenerMBean extends ConnectionListener
- {
- }
-
- public static class TestConnectionListener implements TestConnectionListenerMBean
- {
- public static boolean gotException;
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- gotException = true;
- log.info("TestConnectionListener got exception");
- }
- }
+package org.jboss.test.remoting.lease;
+
+import java.io.ByteArrayInputStream;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+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.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.w3c.dom.Document;
+
+
+/**
+ *
+ * Unit test for JBREM-1010.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class InjectedConnectionListenerTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(InjectedConnectionListenerTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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);
+ }
+
+ TestConnectionListener.gotException = false;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testInjectionWithClassName() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
+ setupServer(TestConnectionListener.class.getName(), mbeanServer);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify ConnectionListener is notified.
+ log.info("client disconnecting");
+ client.disconnect();
+ log.info("client disconnected");
+ Thread.sleep(2000);
+ assertTrue(TestConnectionListener.gotException);
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+
+ public void testInjectionWithMBean() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ String connectionListenerName = "jboss:type=connectionlistener";
+ ObjectName objName = new ObjectName(connectionListenerName);
+ MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
+ TestConnectionListener listener = new TestConnectionListener();
+ mbeanServer.registerMBean(listener, objName);
+ setupServer(connectionListenerName, mbeanServer);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify ConnectionListener is notified.
+ log.info("client disconnecting");
+ client.disconnect();
+ log.info("client disconnected");
+ Thread.sleep(2000);
+ assertTrue(TestConnectionListener.gotException);
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(String listener, MBeanServer mbeanServer) throws Exception
+ {
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ Connector connector = new Connector(config);
+ mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
+
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<config>");
+ buf.append(" <invoker transport=\"" + getTransport() + "\">");
+ buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>");
+ buf.append(" <attribute name=\"serverBindPort\">" + port + "</attribute>");
+ buf.append(" <attribute name=\"" + ServerInvoker.CONNECTION_LISTENER + "\">" + listener + "</attribute>");
+ buf.append(" <attribute name=\"" + ServerInvoker.CLIENT_LEASE_PERIOD + "\">5000</attribute>");
+ buf.append(" </invoker>");
+ buf.append("</config>");
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ connector.setConfiguration(xml.getDocumentElement());
+ connector.create();
+ connector.addInvocationHandler("test", new TestInvocationHandler());
+ connector.start();
+ locatorURI = connector.getInvokerLocator();
+ log.info("Started remoting server with locator uri of: " + locatorURI);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ 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) {}
+ }
+
+
+ public interface TestConnectionListenerMBean extends ConnectionListener
+ {
+ }
+
+ public static class TestConnectionListener implements TestConnectionListenerMBean
+ {
+ public static boolean gotException;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ gotException = true;
+ log.info("TestConnectionListener got exception");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/InjectedConnectionListenerTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationFailureTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationFailureTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationFailureTestCase.java 2010-08-05 01:11:53 UTC (rev 5988)
@@ -1,361 +1,361 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.lease;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.net.SocketFactory;
-
-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.CannotConnectException;
-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.PortUtil;
-
-
-/**
- * Unit test for JBREM-1154.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Sep 11, 2009
- * </p>
- */
-public class LeaseCreationFailureTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(LeaseCreationFailureTestCase.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.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 testLeaseCreationFailure() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.SOCKET_FACTORY_NAME, TestSocketFactory.class.getName());
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
-
- // Verify that Client.connect() throws Exception if LeasePinger.addClient() fails.
- try
- {
- client.connect();
- fail("expected exception");
- }
- catch (CannotConnectException e)
- {
- log.info("got exception", e);
- assertEquals("got wrong exception", "Error setting up client lease upon performing connect.", e.getMessage());
- }
- catch (Throwable t)
- {
- log.info("got wrong exception", t);
- fail("got wrong exception");
- }
- assertFalse(client.isConnected());
-
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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");
- config.put("clientLeasePeriod", "1000");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.addConnectionListener(new TestConnectionListener());
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- 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 void handleConnectionException(Throwable throwable, Client client)
- {
- }
- }
-
-
- public static class TestSocketFactory extends SocketFactory
- {
- int initialSuccesses = 2;
-
- public TestSocketFactory()
- {
- }
- public TestSocketFactory(int initialSuccesses)
- {
- this.initialSuccesses = initialSuccesses;
- }
- public Socket createSocket()
- {
- Socket s = new TestSocket(initialSuccesses);
- log.info("returning " + s);
- return s;
- }
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- Socket s = new TestSocket(arg0, arg1, initialSuccesses);
- log.info("returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- Socket s = new TestSocket(arg0, arg1, initialSuccesses);
- log.info("returning " + s);
- return s;
- }
-
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
- {
- Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
- log.info("returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
- log.info("returning " + s);
- return s;
- }
- }
-
-
- static class TestSocket extends Socket
- {
- int initialSuccesses;
-
- public TestSocket(int initialWrites)
- {
- this.initialSuccesses = initialWrites;
- }
- public TestSocket(String host, int port, int initialWrites) throws UnknownHostException, IOException
- {
- super(host, port);
- this.initialSuccesses = initialWrites;
- }
- public TestSocket(InetAddress address, int port, int initialWrites) throws IOException
- {
- super(address, port);
- this.initialSuccesses = initialWrites;
- }
- public TestSocket(String host, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
- {
- super(host, port, localAddr, localPort);
- this.initialSuccesses = initialWrites;
- }
- public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
- {
- super(address, port, localAddr, localPort);
- this.initialSuccesses = initialWrites;
- }
- public OutputStream getOutputStream() throws IOException
- {
- return new TestOutputStream(super.getOutputStream(), initialSuccesses);
- }
- public String toString()
- {
- return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
- }
- }
-
-
- static class TestOutputStream extends OutputStream
- {
- OutputStream os;
- boolean closed;
- int initialWrites;
- boolean doThrow = true;
- public static int counter;
-
- public TestOutputStream(OutputStream os, int initialWrites)
- {
- this.os = os;
- this.initialWrites = initialWrites;
- }
- public void close()throws IOException
- {
- closed = true;
- super.close();
- log.info(this + " closed");
- }
- public void write(int b) throws IOException
- {
- System.out.print("b: " + b);
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- if (doThrow && ++counter > initialWrites)
- {
- log.info("throwing exception");
- throw new IOException("");
- }
- os.write(b);
- }
- public void write(byte b[], int off, int len) throws IOException
- {
- System.out.print("b: ");
- for (int i = 0; i < len; i++)
- {
- System.out.print(b[i] + " ");
- }
- System.out.println("");
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- log.info("TestOutputStream: counter = " + ++counter + ", initialWrites = " + initialWrites);
- if (counter > initialWrites)
- {
- log.info("throwing exception");
- throw new IOException("");
- }
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- try
- {
- log.info(this + " calling write()");
- doThrow = false;
- os.write(b, off, len);
- os.flush();
- doThrow = true;
- log.info(this + " back from write()");
- }
- catch (IOException e)
- {
- log.info("exception: ", e);
- throw e;
- }
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.lease;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.SocketFactory;
+
+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.CannotConnectException;
+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.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1154.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Sep 11, 2009
+ * </p>
+ */
+public class LeaseCreationFailureTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(LeaseCreationFailureTestCase.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.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 testLeaseCreationFailure() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.SOCKET_FACTORY_NAME, TestSocketFactory.class.getName());
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+
+ // Verify that Client.connect() throws Exception if LeasePinger.addClient() fails.
+ try
+ {
+ client.connect();
+ fail("expected exception");
+ }
+ catch (CannotConnectException e)
+ {
+ log.info("got exception", e);
+ assertEquals("got wrong exception", "Error setting up client lease upon performing connect.", e.getMessage());
+ }
+ catch (Throwable t)
+ {
+ log.info("got wrong exception", t);
+ fail("got wrong exception");
+ }
+ assertFalse(client.isConnected());
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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");
+ config.put("clientLeasePeriod", "1000");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.addConnectionListener(new TestConnectionListener());
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ 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 void handleConnectionException(Throwable throwable, Client client)
+ {
+ }
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int initialSuccesses = 2;
+
+ public TestSocketFactory()
+ {
+ }
+ public TestSocketFactory(int initialSuccesses)
+ {
+ this.initialSuccesses = initialSuccesses;
+ }
+ public Socket createSocket()
+ {
+ Socket s = new TestSocket(initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ Socket s = new TestSocket(arg0, arg1, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ Socket s = new TestSocket(arg0, arg1, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+ }
+
+
+ static class TestSocket extends Socket
+ {
+ int initialSuccesses;
+
+ public TestSocket(int initialWrites)
+ {
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(String host, int port, int initialWrites) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, int initialWrites) throws IOException
+ {
+ super(address, port);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.initialSuccesses = initialWrites;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), initialSuccesses);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ boolean closed;
+ int initialWrites;
+ boolean doThrow = true;
+ public static int counter;
+
+ public TestOutputStream(OutputStream os, int initialWrites)
+ {
+ this.os = os;
+ this.initialWrites = initialWrites;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ System.out.print("b: " + b);
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ if (doThrow && ++counter > initialWrites)
+ {
+ log.info("throwing exception");
+ throw new IOException("");
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ log.info("TestOutputStream: counter = " + ++counter + ", initialWrites = " + initialWrites);
+ if (counter > initialWrites)
+ {
+ log.info("throwing exception");
+ throw new IOException("");
+ }
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info(this + " calling write()");
+ doThrow = false;
+ os.write(b, off, len);
+ os.flush();
+ doThrow = true;
+ log.info(this + " back from write()");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationFailureTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationTimeoutTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationTimeoutTestCase.java 2010-08-05 01:11:53 UTC (rev 5988)
@@ -1,785 +1,785 @@
-/*
- * 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.lease;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.net.ServerSocketFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.Logger;
-import org.jboss.logging.Log4jLoggerPlugin;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.CannotConnectException;
-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.PortUtil;
-
-
-/**
- * Unit test for JBREM-1238.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright July 28, 2010
- * </p>
- */
-public class LeaseCreationTimeoutTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(LeaseCreationTimeoutTestCase.class);
-
- protected static int breakServer;
- protected static int counter;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected PrintStream originalPrintStream;
- protected ByteArrayOutputStream baos;
-
-
- public void setUp() throws Exception
- {
- baos = new ByteArrayOutputStream();
- originalPrintStream = System.out;
- PrintStream ps = new PrintStream(baos, true);
- System.setOut(ps);
-
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- consoleAppender.setTarget(ConsoleAppender.SYSTEM_OUT);
-
- Log4jLoggerPlugin loggerPlugin = (Log4jLoggerPlugin) Logger.getLogger("org.jboss.remoting").getLoggerPlugin();
- org.apache.log4j.Logger logger = loggerPlugin.getLogger();
- logger.setLevel(XLevel.TRACE);
- logger.addAppender(consoleAppender);
- loggerPlugin = (Log4jLoggerPlugin) Logger.getLogger("org.jboss.test.remoting").getLoggerPlugin();
- logger = loggerPlugin.getLogger();
- logger.setLevel(XLevel.TRACE);
- logger.addAppender(consoleAppender);
-
- breakServer = -1;
- counter = 0;
- }
-
-
- public void tearDown()
- {
- }
-
-
- /**
- * Verifies that default value of leaseCreationTimeout is set properly.
- */
- public void testLeaseCreationTimeoutDefault() throws Throwable
- {
- log.info("entering " + getName());
- Client client = null;
-
- try
- {
- // Start server.
- setupServer(-1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- String s = baos.toString();
- assertTrue(s.indexOf("setting timeout to 30000 for this invocation") > -1);
- assertTrue(s.indexOf("starting lease timer with ping period of") > -1);
- log.info(getName() + " PASSES");
- }
- finally
- {
- client.disconnect();
- shutdownServer();
- originalPrintStream.flush();
- System.setOut(originalPrintStream);
- System.out.println("starting to write log");
- String s = baos.toString();
- System.out.println(s);
- }
- }
-
-
- /**
- * Verifies that value of leaseCreationTimeout is set properly from configuration map.
- */
- public void testLeaseCreationTimeoutConfig() throws Throwable
- {
- log.info("entering " + getName());
- Client client = null;
-
- try
- {
- // Start server.
- setupServer(-1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "12345");
- clientConfig.put(ServerInvoker.TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- String s = baos.toString();
- assertTrue(s.indexOf("setting timeout to 12345 for this invocation") > -1);
- assertTrue(s.indexOf("starting lease timer with ping period of") > -1);
- log.info(getName() + " PASSES");
- }
- finally
- {
- client.disconnect();
- shutdownServer();
- originalPrintStream.flush();
- System.setOut(originalPrintStream);
- System.out.println("starting to write log");
- String s = baos.toString();
- System.out.println(s);
- }
- }
-
-
- /**
- * Verifies that MicroRemotingClientInvoker.establishLease() is terminated according to
- * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
- * set up a lease.
- */
- public void testLeaseCreationWithBrokenEstablishLease() throws Throwable
- {
- log.info("entering " + getName());
- Client client1 = null;
- Client client2 = null;
-
- try
- {
- // Start server.
- setupServer(1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(ServerInvoker.TIMEOUT, "0");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
- addExtraClientConfig(clientConfig);
- client1 = new Client(clientLocator, clientConfig);
-
- // Should not connect.
- BrokenEstablisthLeaseTestThread btt = new BrokenEstablisthLeaseTestThread(client1);
- btt.run();
-
- // Should connect.
- Thread.sleep(10000);
- client2 = new Client(clientLocator, clientConfig);
- WorkingTestThread ttt = new WorkingTestThread(client2);
- ttt.run();
-
- // Test lease creation.
- Thread.sleep(5000);
- assertTrue(btt.ok);
- assertTrue(ttt.ok);
-
- log.info(getName() + " PASSES");
- }
- finally
- {
- client1.disconnect();
- client2.disconnect();
- shutdownServer();
- originalPrintStream.flush();
- System.setOut(originalPrintStream);
- System.out.println("starting to write log");
- String s = baos.toString();
- System.out.println(s);
- Thread.sleep(10000);
- }
- }
-
-
- /**
- * Verifies that MicroRemotingClientInvoker.terminateLease() is terminated according to
- * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
- * set up a lease. In this test the hang up is in LeasePinger.removeClient().
- */
- public void testLeaseTerminationWithBrokenRemoveClient() throws Throwable
- {
- log.info("entering " + getName());
- Client client1 = null;
- Client client2 = null;
-
- try
- {
- // Start server.
- setupServer(4);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(ServerInvoker.TIMEOUT, "0");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
- addExtraClientConfig(clientConfig);
- client1 = new Client(clientLocator, clientConfig);
-
- // Should not terminate properly in call to LeasePinger.removeClient().
- BrokenTerminateLeaseRemoveClientTestThread btt = new BrokenTerminateLeaseRemoveClientTestThread(client1, baos);
- btt.start();
-
- // Should connect.
- Thread.sleep(10000);
- client2 = new Client(clientLocator, clientConfig);
- WorkingTestThread ttt = new WorkingTestThread(client2);
- ttt.start();
-
- // Test lease creation.
- Thread.sleep(5000);
- assertTrue(btt.ok);
- assertTrue(ttt.ok);
-
- log.info(getName() + " PASSES");
- }
- finally
- {
- shutdownServer();
- originalPrintStream.flush();
- System.setOut(originalPrintStream);
- System.out.println("starting to write log");
- String s = baos.toString();
- System.out.println(s);
- Thread.sleep(10000);
- }
- }
-
-
- /**
- * Verifies that MicroRemotingClientInvoker.terminateLease() is terminated according to
- * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
- * set up a lease. In this test the hang up is in LeasePinger.stopPing().
- */
- public void testLeaseTerminationWithBrokenStopPing() throws Throwable
- {
- log.info("entering " + getName());
-
- try
- {
- // Start server.
- setupServer(5);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(ServerInvoker.TIMEOUT, "0");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator, clientConfig);
-
- // Should not terminate properly in call to LeasePinger.stopPing().
- BrokenTerminateLeaseStopPingTestThread btt = new BrokenTerminateLeaseStopPingTestThread(client1, baos);
- btt.start();
-
- // Should connect.
- Thread.sleep(10000);
- Client client2 = new Client(clientLocator, clientConfig);
- WorkingTestThread ttt = new WorkingTestThread(client2);
- ttt.start();
-
- // Test lease creation.
- Thread.sleep(5000);
- assertTrue(btt.ok);
- assertTrue(ttt.ok);
-
- shutdownServer();
- log.info(getName() + " PASSES");
-
- }
- finally
- {
- originalPrintStream.flush();
- System.setOut(originalPrintStream);
- System.out.println("starting to write log");
- String s = baos.toString();
- System.out.println(s);
- }
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(int breakServer) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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");
- config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, "true");
- config.put("clientLeasePeriod", "10000");
- if (breakServer > -1)
- {
- LeaseCreationTimeoutTestCase.breakServer = breakServer;
- config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, new TestServerSocketFactory());
- }
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.addConnectionListener(new TestConnectionListener());
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- 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 void handleConnectionException(Throwable throwable, Client client)
- {
- }
- }
-
-
- static public class TestServerSocketFactory extends ServerSocketFactory
- {
- public TestServerSocketFactory()
- {
- }
- public ServerSocket createServerSocket() throws IOException
- {
- ServerSocket ss = new TestServerSocket();
- log.info(this + " returning: " + ss);
- return ss;
- }
- public ServerSocket createServerSocket(int port) throws IOException
- {
- ServerSocket ss = new TestServerSocket(port);
- log.info(this + " returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog) throws IOException
- {
- ServerSocket ss = new TestServerSocket(port, backlog);
- log.info(this + " returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
- {
- ServerSocket ss = new TestServerSocket(port, backlog, ifAddress);
- log.info(this + " returning: " + ss);
- return ss;
- }
- }
-
-
- static class TestServerSocket extends ServerSocket
- {
- public TestServerSocket() throws IOException
- {
- super();
- }
- public TestServerSocket(int port) throws IOException
- {
- super(port);
- }
- public TestServerSocket(int port, int backlog) throws IOException
- {
- super(port, backlog);
- }
- public TestServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException
- {
- super(port, backlog, bindAddr);
- }
- public Socket accept() throws IOException
- {
- Socket s = super.accept();
- TestSocket ts = new TestSocket(s);
- log.info(this + " returning: " + ts);
- return ts;
- }
- public String toString()
- {
- return "TestServerSocket[" + getLocalPort() + "]";
- }
- }
-
-
- static class TestSocket extends Socket
- {
- Socket s;
-
- public TestSocket(Socket s)
- {
- this.s = s;
- }
- public void close() throws IOException
- {
- s.close();
- }
- public InputStream getInputStream() throws IOException
- {
- return s.getInputStream();
- }
- public OutputStream getOutputStream() throws IOException
- {
- return new TestOutputStream(s.getOutputStream());
- }
- public InetAddress getInetAddress()
- {
- return s.getInetAddress();
- }
- public String toString()
- {
- return "TestSocket[" + s.getLocalPort() + "->" + s.getPort() + "]";
- }
- }
-
-
- static class TestOutputStream extends OutputStream
- {
- OutputStream os;
- boolean closed;
- boolean doThrow = true;
-
- public TestOutputStream(OutputStream os)
- {
- this.os = os;
- }
- public void close()throws IOException
- {
- closed = true;
- super.close();
- log.info(this + " closed");
- }
- public void write(int b) throws IOException
- {
- System.out.print("b: " + b);
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- if (doThrow && counter++ == breakServer)
- {
- log.info("sleeping");
- while (true)
- {
- try
- {
- Thread.sleep(30000);
- }
- catch (InterruptedException e)
- {
- }
- }
- }
- os.write(b);
- }
- public void write(byte b[], int off, int len) throws IOException
- {
- System.out.print("b: ");
- for (int i = 0; i < len; i++)
- {
- System.out.print(b[i] + " ");
- }
- System.out.println("");
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- log.info("TestOutputStream: counter = " + counter + ", broken = " + breakServer);
- if (counter++ == breakServer)
- {
- log.info(this + " sleeping");
- try
- {
- Thread.sleep(20000);
- }
- catch (InterruptedException e)
- {
- }
- log.info(this + " woke up");
- }
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- try
- {
- log.info(this + " calling write()");
- doThrow = false;
- os.write(b, off, len);
- os.flush();
- doThrow = true;
- log.info(this + " back from write()");
- }
- catch (IOException e)
- {
- log.info("exception: ", e);
- throw e;
- }
- }
- public void flush() throws IOException
- {
- os.flush();
- }
- }
-
-
- static class BrokenEstablisthLeaseTestThread extends Thread
- {
- public boolean ok;
- Client client;
-
- public BrokenEstablisthLeaseTestThread(Client client)
- {
- this.client = client;
- setName("BrokenEstablisthLeaseTestThread[" + client + "]");
- }
- public void run()
- {
- try
- {
- log.info(this + " STARTING");
- log.info(this + " trying to connect " + client);
- client.connect();
- }
- catch (CannotConnectException e)
- {
- if ("Error setting up client lease upon performing connect.".equals(e.getMessage()))
- {
- ok = true;
- log.info(this + " got expected exception");
- }
- else
- {
- log.info(this + " got expected exception with unexpected message: " + e.getMessage());
- }
- }
- catch (Exception e)
- {
- log.error(this + " got unexpected exception: " + e);
- }
- }
- public String toString()
- {
- return getName();
- }
- }
-
-
- static class BrokenTerminateLeaseRemoveClientTestThread extends Thread
- {
- public boolean ok;
- Client client;
- ByteArrayOutputStream baos;
-
- public BrokenTerminateLeaseRemoveClientTestThread(Client client, ByteArrayOutputStream baos)
- {
- this.client = client;
- this.baos = baos;
- setName("BrokenTerminateLeaseRemoveClientTestThread[" + client + "]");
- }
- public void run()
- {
- try
- {
- log.info(this + " STARTING");
- log.info(this + " trying to connect " + client);
- client.connect();
- assertEquals("def", client.invoke("def"));
- client.disconnect();
- String s = baos.toString();
- assertTrue(s.indexOf("Terminating individual lease for session id") > -1);
- assertTrue(s.indexOf("failed sending disconnect for client lease") > -1);
- ok = true;
- }
- catch (Throwable t)
- {
- log.error(this + " got unexpected exception: " + t);
- }
- }
- public String toString()
- {
- return getName();
- }
- }
-
-
- static class BrokenTerminateLeaseStopPingTestThread extends Thread
- {
- public boolean ok;
- Client client;
- ByteArrayOutputStream baos;
-
- public BrokenTerminateLeaseStopPingTestThread(Client client, ByteArrayOutputStream baos)
- {
- this.client = client;
- this.baos = baos;
- setName("BrokenTerminateLeaseStopPingTestThread[" + client + "]");
- }
- public void run()
- {
- try
- {
- log.info(this + " STARTING");
- log.info(this + " trying to connect " + client);
- client.connect();
- assertEquals("def", client.invoke("def"));
- client.disconnect();
- String s = baos.toString();
- assertTrue(s.indexOf("Terminating individual lease for session id") > -1);
- assertFalse(s.indexOf("failed sending disconnect for client lease") > -1);
- assertTrue(s.indexOf(": disconnectTimeout: 5000") > -1);
- assertTrue(s.indexOf("error shutting down lease pinger") > -1);
- ok = true;
- }
- catch (Throwable t)
- {
- log.error(this + " got unexpected exception: " + t);
- }
- }
- public String toString()
- {
- return getName();
- }
- }
-
-
- static class WorkingTestThread extends Thread
- {
- public boolean ok;
- Client client;
-
- public WorkingTestThread(Client client)
- {
- this.client = client;
- setName("WorkingTestThread[" + client + "]");
- }
- public void run()
- {
- log.info(this + " STARTING");
- try
- {
- log.info(this + " trying to connect " + client);
- client.connect();
- assertEquals("abc", client.invoke("abc"));
- log.info(this + " connection is good");
- ok = true;
- }
- catch (Throwable t)
- {
- log.error(this + " got unexpected exception: " + t);
- }
- }
- public String toString()
- {
- return getName();
- }
- }
+/*
+ * 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.lease;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.Logger;
+import org.jboss.logging.Log4jLoggerPlugin;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.CannotConnectException;
+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.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1238.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright July 28, 2010
+ * </p>
+ */
+public class LeaseCreationTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(LeaseCreationTimeoutTestCase.class);
+
+ protected static int breakServer;
+ protected static int counter;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected PrintStream originalPrintStream;
+ protected ByteArrayOutputStream baos;
+
+
+ public void setUp() throws Exception
+ {
+ baos = new ByteArrayOutputStream();
+ originalPrintStream = System.out;
+ PrintStream ps = new PrintStream(baos, true);
+ System.setOut(ps);
+
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ consoleAppender.setTarget(ConsoleAppender.SYSTEM_OUT);
+
+ Log4jLoggerPlugin loggerPlugin = (Log4jLoggerPlugin) Logger.getLogger("org.jboss.remoting").getLoggerPlugin();
+ org.apache.log4j.Logger logger = loggerPlugin.getLogger();
+ logger.setLevel(XLevel.TRACE);
+ logger.addAppender(consoleAppender);
+ loggerPlugin = (Log4jLoggerPlugin) Logger.getLogger("org.jboss.test.remoting").getLoggerPlugin();
+ logger = loggerPlugin.getLogger();
+ logger.setLevel(XLevel.TRACE);
+ logger.addAppender(consoleAppender);
+
+ breakServer = -1;
+ counter = 0;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ /**
+ * Verifies that default value of leaseCreationTimeout is set properly.
+ */
+ public void testLeaseCreationTimeoutDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+ Client client = null;
+
+ try
+ {
+ // Start server.
+ setupServer(-1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ String s = baos.toString();
+ assertTrue(s.indexOf("setting timeout to 30000 for this invocation") > -1);
+ assertTrue(s.indexOf("starting lease timer with ping period of") > -1);
+ log.info(getName() + " PASSES");
+ }
+ finally
+ {
+ client.disconnect();
+ shutdownServer();
+ originalPrintStream.flush();
+ System.setOut(originalPrintStream);
+ System.out.println("starting to write log");
+ String s = baos.toString();
+ System.out.println(s);
+ }
+ }
+
+
+ /**
+ * Verifies that value of leaseCreationTimeout is set properly from configuration map.
+ */
+ public void testLeaseCreationTimeoutConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+ Client client = null;
+
+ try
+ {
+ // Start server.
+ setupServer(-1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "12345");
+ clientConfig.put(ServerInvoker.TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ String s = baos.toString();
+ assertTrue(s.indexOf("setting timeout to 12345 for this invocation") > -1);
+ assertTrue(s.indexOf("starting lease timer with ping period of") > -1);
+ log.info(getName() + " PASSES");
+ }
+ finally
+ {
+ client.disconnect();
+ shutdownServer();
+ originalPrintStream.flush();
+ System.setOut(originalPrintStream);
+ System.out.println("starting to write log");
+ String s = baos.toString();
+ System.out.println(s);
+ }
+ }
+
+
+ /**
+ * Verifies that MicroRemotingClientInvoker.establishLease() is terminated according to
+ * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
+ * set up a lease.
+ */
+ public void testLeaseCreationWithBrokenEstablishLease() throws Throwable
+ {
+ log.info("entering " + getName());
+ Client client1 = null;
+ Client client2 = null;
+
+ try
+ {
+ // Start server.
+ setupServer(1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(ServerInvoker.TIMEOUT, "0");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
+ addExtraClientConfig(clientConfig);
+ client1 = new Client(clientLocator, clientConfig);
+
+ // Should not connect.
+ BrokenEstablisthLeaseTestThread btt = new BrokenEstablisthLeaseTestThread(client1);
+ btt.run();
+
+ // Should connect.
+ Thread.sleep(10000);
+ client2 = new Client(clientLocator, clientConfig);
+ WorkingTestThread ttt = new WorkingTestThread(client2);
+ ttt.run();
+
+ // Test lease creation.
+ Thread.sleep(5000);
+ assertTrue(btt.ok);
+ assertTrue(ttt.ok);
+
+ log.info(getName() + " PASSES");
+ }
+ finally
+ {
+ client1.disconnect();
+ client2.disconnect();
+ shutdownServer();
+ originalPrintStream.flush();
+ System.setOut(originalPrintStream);
+ System.out.println("starting to write log");
+ String s = baos.toString();
+ System.out.println(s);
+ Thread.sleep(10000);
+ }
+ }
+
+
+ /**
+ * Verifies that MicroRemotingClientInvoker.terminateLease() is terminated according to
+ * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
+ * set up a lease. In this test the hang up is in LeasePinger.removeClient().
+ */
+ public void testLeaseTerminationWithBrokenRemoveClient() throws Throwable
+ {
+ log.info("entering " + getName());
+ Client client1 = null;
+ Client client2 = null;
+
+ try
+ {
+ // Start server.
+ setupServer(4);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(ServerInvoker.TIMEOUT, "0");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
+ addExtraClientConfig(clientConfig);
+ client1 = new Client(clientLocator, clientConfig);
+
+ // Should not terminate properly in call to LeasePinger.removeClient().
+ BrokenTerminateLeaseRemoveClientTestThread btt = new BrokenTerminateLeaseRemoveClientTestThread(client1, baos);
+ btt.start();
+
+ // Should connect.
+ Thread.sleep(10000);
+ client2 = new Client(clientLocator, clientConfig);
+ WorkingTestThread ttt = new WorkingTestThread(client2);
+ ttt.start();
+
+ // Test lease creation.
+ Thread.sleep(5000);
+ assertTrue(btt.ok);
+ assertTrue(ttt.ok);
+
+ log.info(getName() + " PASSES");
+ }
+ finally
+ {
+ shutdownServer();
+ originalPrintStream.flush();
+ System.setOut(originalPrintStream);
+ System.out.println("starting to write log");
+ String s = baos.toString();
+ System.out.println(s);
+ Thread.sleep(10000);
+ }
+ }
+
+
+ /**
+ * Verifies that MicroRemotingClientInvoker.terminateLease() is terminated according to
+ * the value of Remoting.LEASE_CREATION_TIMEOUT so that another new connection can
+ * set up a lease. In this test the hang up is in LeasePinger.stopPing().
+ */
+ public void testLeaseTerminationWithBrokenStopPing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ try
+ {
+ // Start server.
+ setupServer(5);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(ServerInvoker.TIMEOUT, "0");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(Remoting.LEASE_CREATION_TIMEOUT, "5000");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+
+ // Should not terminate properly in call to LeasePinger.stopPing().
+ BrokenTerminateLeaseStopPingTestThread btt = new BrokenTerminateLeaseStopPingTestThread(client1, baos);
+ btt.start();
+
+ // Should connect.
+ Thread.sleep(10000);
+ Client client2 = new Client(clientLocator, clientConfig);
+ WorkingTestThread ttt = new WorkingTestThread(client2);
+ ttt.start();
+
+ // Test lease creation.
+ Thread.sleep(5000);
+ assertTrue(btt.ok);
+ assertTrue(ttt.ok);
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+
+ }
+ finally
+ {
+ originalPrintStream.flush();
+ System.setOut(originalPrintStream);
+ System.out.println("starting to write log");
+ String s = baos.toString();
+ System.out.println(s);
+ }
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(int breakServer) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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");
+ config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, "true");
+ config.put("clientLeasePeriod", "10000");
+ if (breakServer > -1)
+ {
+ LeaseCreationTimeoutTestCase.breakServer = breakServer;
+ config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, new TestServerSocketFactory());
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.addConnectionListener(new TestConnectionListener());
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ 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 void handleConnectionException(Throwable throwable, Client client)
+ {
+ }
+ }
+
+
+ static public class TestServerSocketFactory extends ServerSocketFactory
+ {
+ public TestServerSocketFactory()
+ {
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = new TestServerSocket();
+ log.info(this + " returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = new TestServerSocket(port);
+ log.info(this + " returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = new TestServerSocket(port, backlog);
+ log.info(this + " returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = new TestServerSocket(port, backlog, ifAddress);
+ log.info(this + " returning: " + ss);
+ return ss;
+ }
+ }
+
+
+ static class TestServerSocket extends ServerSocket
+ {
+ public TestServerSocket() throws IOException
+ {
+ super();
+ }
+ public TestServerSocket(int port) throws IOException
+ {
+ super(port);
+ }
+ public TestServerSocket(int port, int backlog) throws IOException
+ {
+ super(port, backlog);
+ }
+ public TestServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ }
+ public Socket accept() throws IOException
+ {
+ Socket s = super.accept();
+ TestSocket ts = new TestSocket(s);
+ log.info(this + " returning: " + ts);
+ return ts;
+ }
+ public String toString()
+ {
+ return "TestServerSocket[" + getLocalPort() + "]";
+ }
+ }
+
+
+ static class TestSocket extends Socket
+ {
+ Socket s;
+
+ public TestSocket(Socket s)
+ {
+ this.s = s;
+ }
+ public void close() throws IOException
+ {
+ s.close();
+ }
+ public InputStream getInputStream() throws IOException
+ {
+ return s.getInputStream();
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(s.getOutputStream());
+ }
+ public InetAddress getInetAddress()
+ {
+ return s.getInetAddress();
+ }
+ public String toString()
+ {
+ return "TestSocket[" + s.getLocalPort() + "->" + s.getPort() + "]";
+ }
+ }
+
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ boolean closed;
+ boolean doThrow = true;
+
+ public TestOutputStream(OutputStream os)
+ {
+ this.os = os;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ System.out.print("b: " + b);
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ if (doThrow && counter++ == breakServer)
+ {
+ log.info("sleeping");
+ while (true)
+ {
+ try
+ {
+ Thread.sleep(30000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ log.info("TestOutputStream: counter = " + counter + ", broken = " + breakServer);
+ if (counter++ == breakServer)
+ {
+ log.info(this + " sleeping");
+ try
+ {
+ Thread.sleep(20000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ log.info(this + " woke up");
+ }
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info(this + " calling write()");
+ doThrow = false;
+ os.write(b, off, len);
+ os.flush();
+ doThrow = true;
+ log.info(this + " back from write()");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ public void flush() throws IOException
+ {
+ os.flush();
+ }
+ }
+
+
+ static class BrokenEstablisthLeaseTestThread extends Thread
+ {
+ public boolean ok;
+ Client client;
+
+ public BrokenEstablisthLeaseTestThread(Client client)
+ {
+ this.client = client;
+ setName("BrokenEstablisthLeaseTestThread[" + client + "]");
+ }
+ public void run()
+ {
+ try
+ {
+ log.info(this + " STARTING");
+ log.info(this + " trying to connect " + client);
+ client.connect();
+ }
+ catch (CannotConnectException e)
+ {
+ if ("Error setting up client lease upon performing connect.".equals(e.getMessage()))
+ {
+ ok = true;
+ log.info(this + " got expected exception");
+ }
+ else
+ {
+ log.info(this + " got expected exception with unexpected message: " + e.getMessage());
+ }
+ }
+ catch (Exception e)
+ {
+ log.error(this + " got unexpected exception: " + e);
+ }
+ }
+ public String toString()
+ {
+ return getName();
+ }
+ }
+
+
+ static class BrokenTerminateLeaseRemoveClientTestThread extends Thread
+ {
+ public boolean ok;
+ Client client;
+ ByteArrayOutputStream baos;
+
+ public BrokenTerminateLeaseRemoveClientTestThread(Client client, ByteArrayOutputStream baos)
+ {
+ this.client = client;
+ this.baos = baos;
+ setName("BrokenTerminateLeaseRemoveClientTestThread[" + client + "]");
+ }
+ public void run()
+ {
+ try
+ {
+ log.info(this + " STARTING");
+ log.info(this + " trying to connect " + client);
+ client.connect();
+ assertEquals("def", client.invoke("def"));
+ client.disconnect();
+ String s = baos.toString();
+ assertTrue(s.indexOf("Terminating individual lease for session id") > -1);
+ assertTrue(s.indexOf("failed sending disconnect for client lease") > -1);
+ ok = true;
+ }
+ catch (Throwable t)
+ {
+ log.error(this + " got unexpected exception: " + t);
+ }
+ }
+ public String toString()
+ {
+ return getName();
+ }
+ }
+
+
+ static class BrokenTerminateLeaseStopPingTestThread extends Thread
+ {
+ public boolean ok;
+ Client client;
+ ByteArrayOutputStream baos;
+
+ public BrokenTerminateLeaseStopPingTestThread(Client client, ByteArrayOutputStream baos)
+ {
+ this.client = client;
+ this.baos = baos;
+ setName("BrokenTerminateLeaseStopPingTestThread[" + client + "]");
+ }
+ public void run()
+ {
+ try
+ {
+ log.info(this + " STARTING");
+ log.info(this + " trying to connect " + client);
+ client.connect();
+ assertEquals("def", client.invoke("def"));
+ client.disconnect();
+ String s = baos.toString();
+ assertTrue(s.indexOf("Terminating individual lease for session id") > -1);
+ assertFalse(s.indexOf("failed sending disconnect for client lease") > -1);
+ assertTrue(s.indexOf(": disconnectTimeout: 5000") > -1);
+ assertTrue(s.indexOf("error shutting down lease pinger") > -1);
+ ok = true;
+ }
+ catch (Throwable t)
+ {
+ log.error(this + " got unexpected exception: " + t);
+ }
+ }
+ public String toString()
+ {
+ return getName();
+ }
+ }
+
+
+ static class WorkingTestThread extends Thread
+ {
+ public boolean ok;
+ Client client;
+
+ public WorkingTestThread(Client client)
+ {
+ this.client = client;
+ setName("WorkingTestThread[" + client + "]");
+ }
+ public void run()
+ {
+ log.info(this + " STARTING");
+ try
+ {
+ log.info(this + " trying to connect " + client);
+ client.connect();
+ assertEquals("abc", client.invoke("abc"));
+ log.info(this + " connection is good");
+ ok = true;
+ }
+ catch (Throwable t)
+ {
+ log.error(this + " got unexpected exception: " + t);
+ }
+ }
+ public String toString()
+ {
+ return getName();
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/lease/LeaseCreationTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5987 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:11:08 -0400 (Wed, 04 Aug 2010)
New Revision: 5987
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6HostWithNoBracketsTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6InvokerLocatorTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6TestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/ObjectNameWithIPv6AddressTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/PercentEncodingTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6HostWithNoBracketsTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6HostWithNoBracketsTestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6HostWithNoBracketsTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
@@ -1,261 +1,261 @@
-/*
- * 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.ipv6;
-
-import java.io.ByteArrayInputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import javax.management.MBeanServer;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-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.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-/**
- * Unit tests for JBREM-1164.
- *
- * @author <a href="mailto:bclare@tpg.com.au">Ben Clare</a>
- * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
- *
- * @version $Rev$
- * <p>
- * Copyright Dec 20, 2009
- * </p>
- */
-public class IPv6HostWithNoBracketsTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(IPv6HostWithNoBracketsTestCase.class);
- private static boolean firstTime = true;
- private static int port = 8080;
-
-
- 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 testXMLWithoutBrackets() throws Throwable
- {
- log.info("entering " + getName());
-
- assertTrue(doXMLTest("::", ++port));
- assertTrue(doXMLTest("::1", ++port));
- assertTrue(doXMLTest("0:0:0:0:0:0:0:1", ++port));
- assertTrue(doXMLTest("0:0:0:0:0:0:127.0.0.1", ++port));
- assertTrue(doXMLTest("3ffe:1900:4545:3:200:f8ff:fe21:67cf", ++port));
- String version = System.getProperty("java.version");
- if (version.startsWith("1.4"))
- {
- log.info("java version is " + version + ". Skipping test");
- }
- else
- {
- assertTrue(doXMLTest("3ffe:1900:4545:3:200:f8ff:fe21:67cf%5", ++port));
- }
-
- log.info(getName() + " PASSES");
- }
-
-
- public void testXMLWithBrackets() throws Throwable
- {
- log.info("entering " + getName());
-
- assertTrue(doXMLTest("[::]", ++port));
- assertTrue(doXMLTest("[::1]", ++port));
- assertTrue(doXMLTest("[0:0:0:0:0:0:0:1]", ++port));
- assertTrue(doXMLTest("[0:0:0:0:0:0:127.0.0.1]", ++port));
- assertTrue(doXMLTest("[3ffe:1900:4545:3:200:f8ff:fe21:67cf]", ++port));
- String version = System.getProperty("java.version");
- if (version.startsWith("1.4"))
- {
- log.info("java version is " + version + ". Skipping test");
- }
- else
- {
- assertTrue(doXMLTest("[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]", ++port));
- }
-
- log.info(getName() + " PASSES");
- }
-
-
- public void testXMLWithoutHost() throws Exception
- {
- log.info("entering " + getName());
-
- String xml = new StringBuffer()
- .append("<mbean code=\"org.jboss.remoting.transport.Connector\"\n")
- .append(" name=\"jboss.messaging:service=Connector,transport=socket\"\n")
- .append(" display-name=\"Connector\">\n")
- .append(" <attribute name=\"Configuration\">\n")
- .append(" <config>\n")
- .append(" <invoker transport=\"socket\">\n")
- .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_PORT_KEY + "\">" + port + "</attribute>\n")
- .append(" <attribute name=\"timeout\" isParam=\"true\">10000</attribute>\n")
- .append(" </invoker>\n")
- .append(" <handlers>\n")
- .append(" <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
- .append(" </handlers>\n")
- .append(" </config>\n")
- .append(" </attribute>\n")
- .append("</mbean>\n").toString();
- Connector connector = new Connector();
- ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
- Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
- Element element = doc.getDocumentElement();
- connector.setConfiguration(element);
- try
- {
- connector.create();
- InvokerLocator expected = new InvokerLocator("socket://" + getLocalHost() + ":" + port + "/?timeout=10000");
- InvokerLocator actual = connector.getLocator();
- log.info("Expected: " + expected);
- log.info("Actual: " + actual);InetAddress.getLocalHost();
- assertEquals(expected, actual);
- }
- catch (Exception e)
- {
- log.error("Exception caught " + e.getMessage());
- }
- finally
- {
- connector.stop();
- }
-
- log.info(getName() + " PASSES");
- }
-
-
- protected boolean doXMLTest(String host, int port) throws Exception
- {
- String xml = new StringBuffer()
- .append("<mbean code=\"org.jboss.remoting.transport.Connector\"\n")
- .append(" name=\"jboss.messaging:service=Connector,transport=socket\"\n")
- .append(" display-name=\"Connector\">\n")
- .append(" <attribute name=\"Configuration\">\n")
- .append(" <config>\n")
- .append(" <invoker transport=\"socket\">\n")
- .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_ADDRESS_KEY + "\">" + host + "</attribute>\n")
- .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_PORT_KEY + "\">" + port + "</attribute>\n")
- .append(" <attribute name=\"timeout\" isParam=\"true\">10000</attribute>\n")
- .append(" </invoker>\n")
- .append(" <handlers>\n")
- .append(" <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
- .append(" </handlers>\n")
- .append(" </config>\n")
- .append(" </attribute>\n")
- .append("</mbean>\n").toString();
- Connector connector = new Connector();
- ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
- Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
- Element element = doc.getDocumentElement();
- connector.setConfiguration(element);
- try
- {
- connector.create();
- InvokerLocator expected = new InvokerLocator("socket://" + fixHostnameForURL(host) + ":" + port + "/?timeout=10000");
- InvokerLocator actual = connector.getLocator();
- log.info("Expected: " + expected);
- log.info("Actual: " + actual);
- assertEquals(expected, actual);
- return true;
- }
- catch (Exception e)
- {
- log.error("Exception caught ", e);
- return false;
- }
- finally
- {
- connector.stop();
- }
- }
-
-
- static protected String fixHostnameForURL(String host)
- {
- if (host == null)
- return host ;
-
- // if the hostname is an IPv6 literal, enclose it in brackets
- if (host.indexOf(':') != -1 && host.indexOf("[") == -1)
- {
- System.out.println("HOST: [" + host + "]");
- return "[" + host + "]" ;
- }
- else
- {
- return host;
- }
- }
-
-
- static protected String getLocalHost() throws UnknownHostException
- {
- System.setProperty("java.net.preferIPv6Addresses", "true");
- return InetAddress.getLocalHost().getHostAddress();
- }
-
-
- public static class SampleInvocationHandler implements ServerInvocationHandler
- {
- public Object invoke(InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
-
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
+/*
+ * 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.ipv6;
+
+import java.io.ByteArrayInputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import javax.management.MBeanServer;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+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.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+/**
+ * Unit tests for JBREM-1164.
+ *
+ * @author <a href="mailto:bclare@tpg.com.au">Ben Clare</a>
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ *
+ * @version $Rev$
+ * <p>
+ * Copyright Dec 20, 2009
+ * </p>
+ */
+public class IPv6HostWithNoBracketsTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(IPv6HostWithNoBracketsTestCase.class);
+ private static boolean firstTime = true;
+ private static int port = 8080;
+
+
+ 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 testXMLWithoutBrackets() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ assertTrue(doXMLTest("::", ++port));
+ assertTrue(doXMLTest("::1", ++port));
+ assertTrue(doXMLTest("0:0:0:0:0:0:0:1", ++port));
+ assertTrue(doXMLTest("0:0:0:0:0:0:127.0.0.1", ++port));
+ assertTrue(doXMLTest("3ffe:1900:4545:3:200:f8ff:fe21:67cf", ++port));
+ String version = System.getProperty("java.version");
+ if (version.startsWith("1.4"))
+ {
+ log.info("java version is " + version + ". Skipping test");
+ }
+ else
+ {
+ assertTrue(doXMLTest("3ffe:1900:4545:3:200:f8ff:fe21:67cf%5", ++port));
+ }
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testXMLWithBrackets() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ assertTrue(doXMLTest("[::]", ++port));
+ assertTrue(doXMLTest("[::1]", ++port));
+ assertTrue(doXMLTest("[0:0:0:0:0:0:0:1]", ++port));
+ assertTrue(doXMLTest("[0:0:0:0:0:0:127.0.0.1]", ++port));
+ assertTrue(doXMLTest("[3ffe:1900:4545:3:200:f8ff:fe21:67cf]", ++port));
+ String version = System.getProperty("java.version");
+ if (version.startsWith("1.4"))
+ {
+ log.info("java version is " + version + ". Skipping test");
+ }
+ else
+ {
+ assertTrue(doXMLTest("[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]", ++port));
+ }
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testXMLWithoutHost() throws Exception
+ {
+ log.info("entering " + getName());
+
+ String xml = new StringBuffer()
+ .append("<mbean code=\"org.jboss.remoting.transport.Connector\"\n")
+ .append(" name=\"jboss.messaging:service=Connector,transport=socket\"\n")
+ .append(" display-name=\"Connector\">\n")
+ .append(" <attribute name=\"Configuration\">\n")
+ .append(" <config>\n")
+ .append(" <invoker transport=\"socket\">\n")
+ .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_PORT_KEY + "\">" + port + "</attribute>\n")
+ .append(" <attribute name=\"timeout\" isParam=\"true\">10000</attribute>\n")
+ .append(" </invoker>\n")
+ .append(" <handlers>\n")
+ .append(" <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
+ .append(" </handlers>\n")
+ .append(" </config>\n")
+ .append(" </attribute>\n")
+ .append("</mbean>\n").toString();
+ Connector connector = new Connector();
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ Element element = doc.getDocumentElement();
+ connector.setConfiguration(element);
+ try
+ {
+ connector.create();
+ InvokerLocator expected = new InvokerLocator("socket://" + getLocalHost() + ":" + port + "/?timeout=10000");
+ InvokerLocator actual = connector.getLocator();
+ log.info("Expected: " + expected);
+ log.info("Actual: " + actual);InetAddress.getLocalHost();
+ assertEquals(expected, actual);
+ }
+ catch (Exception e)
+ {
+ log.error("Exception caught " + e.getMessage());
+ }
+ finally
+ {
+ connector.stop();
+ }
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected boolean doXMLTest(String host, int port) throws Exception
+ {
+ String xml = new StringBuffer()
+ .append("<mbean code=\"org.jboss.remoting.transport.Connector\"\n")
+ .append(" name=\"jboss.messaging:service=Connector,transport=socket\"\n")
+ .append(" display-name=\"Connector\">\n")
+ .append(" <attribute name=\"Configuration\">\n")
+ .append(" <config>\n")
+ .append(" <invoker transport=\"socket\">\n")
+ .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_ADDRESS_KEY + "\">" + host + "</attribute>\n")
+ .append(" <attribute name=\"" + ServerInvoker.SERVER_BIND_PORT_KEY + "\">" + port + "</attribute>\n")
+ .append(" <attribute name=\"timeout\" isParam=\"true\">10000</attribute>\n")
+ .append(" </invoker>\n")
+ .append(" <handlers>\n")
+ .append(" <handler subsystem=\"test\">" + SampleInvocationHandler.class.getName() + "</handler>\n")
+ .append(" </handlers>\n")
+ .append(" </config>\n")
+ .append(" </attribute>\n")
+ .append("</mbean>\n").toString();
+ Connector connector = new Connector();
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ Element element = doc.getDocumentElement();
+ connector.setConfiguration(element);
+ try
+ {
+ connector.create();
+ InvokerLocator expected = new InvokerLocator("socket://" + fixHostnameForURL(host) + ":" + port + "/?timeout=10000");
+ InvokerLocator actual = connector.getLocator();
+ log.info("Expected: " + expected);
+ log.info("Actual: " + actual);
+ assertEquals(expected, actual);
+ return true;
+ }
+ catch (Exception e)
+ {
+ log.error("Exception caught ", e);
+ return false;
+ }
+ finally
+ {
+ connector.stop();
+ }
+ }
+
+
+ static protected String fixHostnameForURL(String host)
+ {
+ if (host == null)
+ return host ;
+
+ // if the hostname is an IPv6 literal, enclose it in brackets
+ if (host.indexOf(':') != -1 && host.indexOf("[") == -1)
+ {
+ System.out.println("HOST: [" + host + "]");
+ return "[" + host + "]" ;
+ }
+ else
+ {
+ return host;
+ }
+ }
+
+
+ static protected String getLocalHost() throws UnknownHostException
+ {
+ System.setProperty("java.net.preferIPv6Addresses", "true");
+ return InetAddress.getLocalHost().getHostAddress();
+ }
+
+
+ public static class SampleInvocationHandler implements ServerInvocationHandler
+ {
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6HostWithNoBracketsTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6InvokerLocatorTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6InvokerLocatorTestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6InvokerLocatorTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
@@ -1,137 +1,137 @@
-/*
-* 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.ipv6;
-
-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.remoting.InvokerLocator;
-import org.jboss.remoting.transport.Connector;
-
-
-/**
- * Unit tests for JBREM-1175.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jan 8, 2010
- */
-public class IPv6InvokerLocatorTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(IPv6InvokerLocatorTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testHostWithBrackets()
- {
- log.info("entering " + getName());
-
- Map params = new HashMap();
- params.put("x", "y");
- assertTrue(doTest("socket", "[::]", 1234, "a/b", params, "socket://[::]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "[::1]", 1234, "a/b", params, "socket://[::1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "[0:0:0:0:0:0:0:1]", 1234, "a/b", params, "socket://[0:0:0:0:0:0:0:1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "[0:0:0:0:0:0:127.0.0.1]", 1234, "a/b", params, "socket://[0:0:0:0:0:0:127.0.0.1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "[3ffe:1900:4545:3:200:f8ff:fe21:67cf]", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:1234/a/b?x=y"));
-
- String version = System.getProperty("java.version");
- if (version.startsWith("1.4"))
- {
- log.info("java version is " + version + ". Skipping test");
- }
- else
- {
- assertTrue(doTest("socket", "[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]:1234/a/b?x=y"));
- }
-
- log.info(getName() + " PASSES");
- }
-
-
- public void testHostWithoutBrackets()
- {
- log.info("entering " + getName());
-
- Map params = new HashMap();
- params.put("x", "y");
- assertTrue(doTest("socket", "::", 1234, "a/b", params, "socket://[::]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "::1", 1234, "a/b", params, "socket://[::1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "0:0:0:0:0:0:0:1", 1234, "a/b", params, "socket://[0:0:0:0:0:0:0:1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "0:0:0:0:0:0:127.0.0.1", 1234, "a/b", params, "socket://[0:0:0:0:0:0:127.0.0.1]:1234/a/b?x=y"));
- assertTrue(doTest("socket", "3ffe:1900:4545:3:200:f8ff:fe21:67cf", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:1234/a/b?x=y"));
-
- String version = System.getProperty("java.version");
- if (version.startsWith("1.4"))
- {
- log.info("java version is " + version + ". Skipping test");
- }
- else
- {
- assertTrue(doTest("socket", "3ffe:1900:4545:3:200:f8ff:fe21:67cf%5", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]:1234/a/b?x=y"));
- }
-
- log.info(getName() + " PASSES");
- }
-
-
- protected boolean doTest(String protocol, String host, int port, String path, Map params, String expected)
- {
-
- InvokerLocator locator = new InvokerLocator(protocol, host, port, path, params);
- log.info(host + " -> " + locator.getLocatorURI());
- return expected.equals(locator.getLocatorURI());
- }
+/*
+* 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.ipv6;
+
+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.remoting.InvokerLocator;
+import org.jboss.remoting.transport.Connector;
+
+
+/**
+ * Unit tests for JBREM-1175.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jan 8, 2010
+ */
+public class IPv6InvokerLocatorTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(IPv6InvokerLocatorTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testHostWithBrackets()
+ {
+ log.info("entering " + getName());
+
+ Map params = new HashMap();
+ params.put("x", "y");
+ assertTrue(doTest("socket", "[::]", 1234, "a/b", params, "socket://[::]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "[::1]", 1234, "a/b", params, "socket://[::1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "[0:0:0:0:0:0:0:1]", 1234, "a/b", params, "socket://[0:0:0:0:0:0:0:1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "[0:0:0:0:0:0:127.0.0.1]", 1234, "a/b", params, "socket://[0:0:0:0:0:0:127.0.0.1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "[3ffe:1900:4545:3:200:f8ff:fe21:67cf]", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:1234/a/b?x=y"));
+
+ String version = System.getProperty("java.version");
+ if (version.startsWith("1.4"))
+ {
+ log.info("java version is " + version + ". Skipping test");
+ }
+ else
+ {
+ assertTrue(doTest("socket", "[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]:1234/a/b?x=y"));
+ }
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testHostWithoutBrackets()
+ {
+ log.info("entering " + getName());
+
+ Map params = new HashMap();
+ params.put("x", "y");
+ assertTrue(doTest("socket", "::", 1234, "a/b", params, "socket://[::]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "::1", 1234, "a/b", params, "socket://[::1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "0:0:0:0:0:0:0:1", 1234, "a/b", params, "socket://[0:0:0:0:0:0:0:1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "0:0:0:0:0:0:127.0.0.1", 1234, "a/b", params, "socket://[0:0:0:0:0:0:127.0.0.1]:1234/a/b?x=y"));
+ assertTrue(doTest("socket", "3ffe:1900:4545:3:200:f8ff:fe21:67cf", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]:1234/a/b?x=y"));
+
+ String version = System.getProperty("java.version");
+ if (version.startsWith("1.4"))
+ {
+ log.info("java version is " + version + ". Skipping test");
+ }
+ else
+ {
+ assertTrue(doTest("socket", "3ffe:1900:4545:3:200:f8ff:fe21:67cf%5", 1234, "a/b", params, "socket://[3ffe:1900:4545:3:200:f8ff:fe21:67cf%5]:1234/a/b?x=y"));
+ }
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected boolean doTest(String protocol, String host, int port, String path, Map params, String expected)
+ {
+
+ InvokerLocator locator = new InvokerLocator(protocol, host, port, path, params);
+ log.info(host + " -> " + locator.getLocatorURI());
+ return expected.equals(locator.getLocatorURI());
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6InvokerLocatorTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6TestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6TestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6TestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
@@ -1,227 +1,227 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.remoting.ipv6;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.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;
-
-
-/**
- *
- * Unit test for JBREM-852.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Dec 4, 2007
- * </p>
- */
-public class IPv6TestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(IPv6TestCase.class);
-
- private static boolean firstTime = true;
-
- // remoting server connector
- private Connector connector;
- private InvokerLocator serverLocator;
- private TestInvocationHandler invocationHandler;
-
-
- 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 testRawIPv6() throws Throwable
- {
- log.info("entering " + getName());
- final InetAddress addr = InetAddress.getByName("[::1]");
-
- new Thread()
- {
- public void run()
- {
- try
- {
- ServerSocket ss = new ServerSocket(4446, 200, addr);
- log.info("ss address: " + ss.getInetAddress());
- Socket s = ss.accept();
- InputStream is = s.getInputStream();
- log.info("read: " + is.read());
- s.close();
- ss.close();
- }
- catch (Exception e)
- {
- log.error("error", e);
- }
- }
- }.start();
-
-
- Thread.sleep(2000);
-
- Socket s = new Socket(addr, 4446);
- log.info("s address: " + s.getInetAddress());
- log.info("s local address: " + s.getLocalAddress());
- OutputStream os = s.getOutputStream();
- os.write(17);
- log.info("wrote 17");
- s.close();
- log.info(getName() + " PASSES");
-
- }
-
-
- public void testRemotingIPv6Loopback() throws Throwable
- {
- log.info("entering " + getName());
- doRemotingTest("[::1]");
- log.info(getName() + " PASSES");
- }
-
-
- public void testRemotingIPv6Any() throws Throwable
- {
- log.info("entering " + getName());
- doRemotingTest("[::]");
- log.info(getName() + " PASSES");
- }
-
-
- public void testRemotingIPv4Mapped() throws Throwable
- {
- doRemotingTest("[::ffff:127.0.0.1]");
- }
-
-
- protected void doRemotingTest(String host) throws Throwable
- {
- // Start server.
- InetAddress[] addresses = InetAddress.getAllByName("localhost");
- for (int i = 0; i < addresses.length; i++)
- {
- log.info("addresses[" + i + "]: " + addresses[i]);
- }
-
- int port = PortUtil.findFreePort(host);
- String locatorURI = "socket://" + host + ":" + port + "/?timeout=10000";
- 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("sample", invocationHandler);
- connector.start();
-
- // Create client.
- InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator1, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- client.disconnect();
- connector.stop();
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- 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 TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.ipv6;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.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;
+
+
+/**
+ *
+ * Unit test for JBREM-852.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Dec 4, 2007
+ * </p>
+ */
+public class IPv6TestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(IPv6TestCase.class);
+
+ private static boolean firstTime = true;
+
+ // remoting server connector
+ private Connector connector;
+ private InvokerLocator serverLocator;
+ private TestInvocationHandler invocationHandler;
+
+
+ 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 testRawIPv6() throws Throwable
+ {
+ log.info("entering " + getName());
+ final InetAddress addr = InetAddress.getByName("[::1]");
+
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ ServerSocket ss = new ServerSocket(4446, 200, addr);
+ log.info("ss address: " + ss.getInetAddress());
+ Socket s = ss.accept();
+ InputStream is = s.getInputStream();
+ log.info("read: " + is.read());
+ s.close();
+ ss.close();
+ }
+ catch (Exception e)
+ {
+ log.error("error", e);
+ }
+ }
+ }.start();
+
+
+ Thread.sleep(2000);
+
+ Socket s = new Socket(addr, 4446);
+ log.info("s address: " + s.getInetAddress());
+ log.info("s local address: " + s.getLocalAddress());
+ OutputStream os = s.getOutputStream();
+ os.write(17);
+ log.info("wrote 17");
+ s.close();
+ log.info(getName() + " PASSES");
+
+ }
+
+
+ public void testRemotingIPv6Loopback() throws Throwable
+ {
+ log.info("entering " + getName());
+ doRemotingTest("[::1]");
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testRemotingIPv6Any() throws Throwable
+ {
+ log.info("entering " + getName());
+ doRemotingTest("[::]");
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testRemotingIPv4Mapped() throws Throwable
+ {
+ doRemotingTest("[::ffff:127.0.0.1]");
+ }
+
+
+ protected void doRemotingTest(String host) throws Throwable
+ {
+ // Start server.
+ InetAddress[] addresses = InetAddress.getAllByName("localhost");
+ for (int i = 0; i < addresses.length; i++)
+ {
+ log.info("addresses[" + i + "]: " + addresses[i]);
+ }
+
+ int port = PortUtil.findFreePort(host);
+ String locatorURI = "socket://" + host + ":" + port + "/?timeout=10000";
+ 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("sample", invocationHandler);
+ connector.start();
+
+ // Create client.
+ InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator1, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ client.disconnect();
+ connector.stop();
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ 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 TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/IPv6TestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/ObjectNameWithIPv6AddressTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/ObjectNameWithIPv6AddressTestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/ObjectNameWithIPv6AddressTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
@@ -1,206 +1,206 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.remoting.ipv6;
-
-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 javax.management.MBeanServerFactory;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-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.network.NetworkRegistry;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-public class ObjectNameWithIPv6AddressTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ObjectNameWithIPv6AddressTestCase.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(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 testIPv6Loopback() throws Throwable
- {
- log.info("entering " + getName());
- doTest("[::1]");
- log.info(getName() + " PASSES");
- }
-
-
- public void testIPv6Any() throws Throwable
- {
- log.info("entering " + getName());
- doTest("[::]");
- log.info(getName() + " PASSES");
- }
-
-
- public void testIPv4Mapped() throws Throwable
- {
- log.info("entering " + getName());
- doTest("[::ffff:127.0.0.1]");
- log.info(getName() + " PASSES");
- }
-
-
- protected void doTest(String host) throws Throwable
- {
- MBeanServer server = MBeanServerFactory.createMBeanServer();
-
- Connector connector = new Connector();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- serverLocator = new InvokerLocator(locatorURI);
- connector.setInvokerLocator(locatorURI);
- ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + getTransport());
- server.registerMBean(connector, obj);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
-
- ServerInvoker serverInvoker = connector.getServerInvoker();
- ObjectName objectName = new ObjectName(serverInvoker.getMBeanObjectName());
- assertTrue(objectName.getCanonicalName().indexOf(host) >= 0);
- assertTrue(server.isRegistered(objectName));
- log.info(objectName + " is registered");
-
- // Create client.
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(serverLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- client.disconnect();
- shutdownServer();
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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 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 TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.ipv6;
+
+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 javax.management.MBeanServerFactory;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+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.network.NetworkRegistry;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+public class ObjectNameWithIPv6AddressTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ObjectNameWithIPv6AddressTestCase.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(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 testIPv6Loopback() throws Throwable
+ {
+ log.info("entering " + getName());
+ doTest("[::1]");
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIPv6Any() throws Throwable
+ {
+ log.info("entering " + getName());
+ doTest("[::]");
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIPv4Mapped() throws Throwable
+ {
+ log.info("entering " + getName());
+ doTest("[::ffff:127.0.0.1]");
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void doTest(String host) throws Throwable
+ {
+ MBeanServer server = MBeanServerFactory.createMBeanServer();
+
+ Connector connector = new Connector();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ connector.setInvokerLocator(locatorURI);
+ ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + getTransport());
+ server.registerMBean(connector, obj);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+
+ ServerInvoker serverInvoker = connector.getServerInvoker();
+ ObjectName objectName = new ObjectName(serverInvoker.getMBeanObjectName());
+ assertTrue(objectName.getCanonicalName().indexOf(host) >= 0);
+ assertTrue(server.isRegistered(objectName));
+ log.info(objectName + " is registered");
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ client.disconnect();
+ shutdownServer();
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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 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 TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/ObjectNameWithIPv6AddressTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/PercentEncodingTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/PercentEncodingTestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/PercentEncodingTestCase.java 2010-08-05 01:11:08 UTC (rev 5987)
@@ -1,92 +1,92 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.remoting.ipv6;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.remoting.InvokerLocator;
-
-
-/**
- *
- * Unit test for JBREM-1003.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jan 23, 2008
- * </p>
- */
-public class PercentEncodingTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(PercentEncodingTestCase.class);
- private static boolean firstTime = true;
-
-
- 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);
- log.info("java.version: " + System.getProperty("java.version"));
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testPercentEncoding() throws Throwable
- {
- log.info("entering " + getName());
-
- String version = System.getProperty("java.version");
- if (version.startsWith("1.4"))
- {
- log.info("java version is " + version + ". Skipping test");
- }
- else
- {
- String locatorURI = "socket://[fe80::205:9aff:fe3c:7800%7]:7777/";
- InvokerLocator locator = new InvokerLocator(locatorURI);
- assertEquals(locatorURI, locator.getLocatorURI());
-
- locatorURI = "socket://multihome/?homes=[fe80::205:9aff:fe3c:7800%7]:7777![fe80::214:22ff:feef:68bb%4]:8888";
- locator = new InvokerLocator(locatorURI);
- assertEquals(locatorURI, locator.getLocatorURI());
- }
- log.info(getName() + " PASSES");
-
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.ipv6;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.InvokerLocator;
+
+
+/**
+ *
+ * Unit test for JBREM-1003.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jan 23, 2008
+ * </p>
+ */
+public class PercentEncodingTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PercentEncodingTestCase.class);
+ private static boolean firstTime = true;
+
+
+ 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);
+ log.info("java.version: " + System.getProperty("java.version"));
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testPercentEncoding() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ String version = System.getProperty("java.version");
+ if (version.startsWith("1.4"))
+ {
+ log.info("java version is " + version + ". Skipping test");
+ }
+ else
+ {
+ String locatorURI = "socket://[fe80::205:9aff:fe3c:7800%7]:7777/";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ assertEquals(locatorURI, locator.getLocatorURI());
+
+ locatorURI = "socket://multihome/?homes=[fe80::205:9aff:fe3c:7800%7]:7777![fe80::214:22ff:feef:68bb%4]:8888";
+ locator = new InvokerLocator(locatorURI);
+ assertEquals(locatorURI, locator.getLocatorURI());
+ }
+ log.info(getName() + " PASSES");
+
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ipv6/PercentEncodingTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5986 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:10:03 -0400 (Wed, 04 Aug 2010)
New Revision: 5986
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker/ClientInvokerDelayedDestructionTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker/ClientInvokerDelayedDestructionTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker/ClientInvokerDelayedDestructionTestCase.java 2010-08-05 01:09:12 UTC (rev 5985)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker/ClientInvokerDelayedDestructionTestCase.java 2010-08-05 01:10:03 UTC (rev 5986)
@@ -1,436 +1,436 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.remoting.invoker;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Timer;
-
-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.InvokerRegistry;
-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.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit tests from JBREM-877.
- * Adjusted for JBREM-1176.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Feb 22, 2008
- * </p>
- */
-public class ClientInvokerDelayedDestructionTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ClientInvokerDelayedDestructionTestCase.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(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 testNoDelayedDestruction() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker1 = client.getInvoker();
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for first client");
- client.disconnect();
-
- client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker2 = client.getInvoker();
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for second client");
- assertNotSame(invoker2, invoker1);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testZeroDelay() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "0");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker1 = client.getInvoker();
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for first client");
- client.disconnect();
-
- client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker2 = client.getInvoker();
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for second client");
- assertNotSame(invoker2, invoker1);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testDelayThenGetNewInvoker() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker1 = client.getInvoker();
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for first client");
- client.disconnect();
-
- Thread.sleep(10000);
- client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker2 = client.getInvoker();
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for second client");
- assertNotSame(invoker2, invoker1);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testDelayThenReuseInvoker() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "10000");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker1 = client.getInvoker();
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for first client");
- client.disconnect();
-
- Thread.sleep(5000);
- client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker2 = client.getInvoker();
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for second client");
- assertSame(invoker2, invoker1);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testEventualDestruction() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
- addExtraClientConfig(clientConfig);
-
- for (int i = 0; i < 50; i++)
- {
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- assertEquals("abc", client.invoke("abc"));
- client.disconnect();
- }
-
- Thread.sleep(10000);
- assertEquals(0, InvokerRegistry.getClientInvokers().length);
-
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testStaticTimer() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
-
- // Verify Timer hasn't been created.
- Field field = Client.class.getDeclaredField("invokerDestructionTimer");
- field.setAccessible(true);
- Timer invokerDestructionTimer = (Timer) field.get(null);
- assertNull(invokerDestructionTimer);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
- addExtraClientConfig(clientConfig);
- Client[] clients = new Client[50];
-
- for (int i = 0; i < 50; i++)
- {
- clients[i] = new Client(clientLocator, clientConfig);
- clients[i].connect();
- assertEquals("abc", clients[i].invoke("abc"));
- clients[i].disconnect();
- }
-
- // Verify Timer has been created.
- invokerDestructionTimer = (Timer) field.get(null);
- assertNotNull(invokerDestructionTimer);
-
- // Verify all Clients are using the same Timer.
- for (int i = 0; i < 50; i++)
- {
- assertEquals("Should be the same Timer", invokerDestructionTimer, field.get(clients[i]));
- }
-
- Thread.sleep(10000);
- assertEquals(0, InvokerRegistry.getClientInvokers().length);
-
- // Verify Timer has been destroyed.
- invokerDestructionTimer = (Timer) field.get(null);
- assertNull(invokerDestructionTimer);
-
- // Recreate Clients to verify that a new Timer is created.
- for (int i = 0; i < 50; i++)
- {
- clients[i] = new Client(clientLocator, clientConfig);
- clients[i].connect();
- assertEquals("abc", clients[i].invoke("abc"));
- clients[i].disconnect();
- }
-
- // Verify Timer has been created.
- invokerDestructionTimer = (Timer) field.get(null);
- assertNotNull(invokerDestructionTimer);
-
- // Verify all Clients are using the same Timer.
- for (int i = 0; i < 50; i++)
- {
- assertEquals("Should be the same Timer", invokerDestructionTimer, field.get(clients[i]));
- }
-
- Thread.sleep(10000);
- assertEquals(0, InvokerRegistry.getClientInvokers().length);
-
- // Verify Timer has been destroyed.
- invokerDestructionTimer = (Timer) field.get(null);
- assertNull(invokerDestructionTimer);
-
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testConfigByInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "/?invokerDestructionDelay=10000";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker1 = client.getInvoker();
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for first client");
- client.disconnect();
-
- Thread.sleep(5000);
- client = new Client(clientLocator, clientConfig);
- client.connect();
- ClientInvoker invoker2 = client.getInvoker();
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good for second client");
- assertSame(invoker2, invoker1);
-
- 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() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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 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 TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.invoker;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+
+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.InvokerRegistry;
+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.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit tests from JBREM-877.
+ * Adjusted for JBREM-1176.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 22, 2008
+ * </p>
+ */
+public class ClientInvokerDelayedDestructionTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ClientInvokerDelayedDestructionTestCase.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(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 testNoDelayedDestruction() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker1 = client.getInvoker();
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for first client");
+ client.disconnect();
+
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker2 = client.getInvoker();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for second client");
+ assertNotSame(invoker2, invoker1);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testZeroDelay() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "0");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker1 = client.getInvoker();
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for first client");
+ client.disconnect();
+
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker2 = client.getInvoker();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for second client");
+ assertNotSame(invoker2, invoker1);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testDelayThenGetNewInvoker() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker1 = client.getInvoker();
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for first client");
+ client.disconnect();
+
+ Thread.sleep(10000);
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker2 = client.getInvoker();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for second client");
+ assertNotSame(invoker2, invoker1);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testDelayThenReuseInvoker() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "10000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker1 = client.getInvoker();
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for first client");
+ client.disconnect();
+
+ Thread.sleep(5000);
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker2 = client.getInvoker();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for second client");
+ assertSame(invoker2, invoker1);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testEventualDestruction() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
+ addExtraClientConfig(clientConfig);
+
+ for (int i = 0; i < 50; i++)
+ {
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ assertEquals("abc", client.invoke("abc"));
+ client.disconnect();
+ }
+
+ Thread.sleep(10000);
+ assertEquals(0, InvokerRegistry.getClientInvokers().length);
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testStaticTimer() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+
+ // Verify Timer hasn't been created.
+ Field field = Client.class.getDeclaredField("invokerDestructionTimer");
+ field.setAccessible(true);
+ Timer invokerDestructionTimer = (Timer) field.get(null);
+ assertNull(invokerDestructionTimer);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.INVOKER_DESTRUCTION_DELAY, "5000");
+ addExtraClientConfig(clientConfig);
+ Client[] clients = new Client[50];
+
+ for (int i = 0; i < 50; i++)
+ {
+ clients[i] = new Client(clientLocator, clientConfig);
+ clients[i].connect();
+ assertEquals("abc", clients[i].invoke("abc"));
+ clients[i].disconnect();
+ }
+
+ // Verify Timer has been created.
+ invokerDestructionTimer = (Timer) field.get(null);
+ assertNotNull(invokerDestructionTimer);
+
+ // Verify all Clients are using the same Timer.
+ for (int i = 0; i < 50; i++)
+ {
+ assertEquals("Should be the same Timer", invokerDestructionTimer, field.get(clients[i]));
+ }
+
+ Thread.sleep(10000);
+ assertEquals(0, InvokerRegistry.getClientInvokers().length);
+
+ // Verify Timer has been destroyed.
+ invokerDestructionTimer = (Timer) field.get(null);
+ assertNull(invokerDestructionTimer);
+
+ // Recreate Clients to verify that a new Timer is created.
+ for (int i = 0; i < 50; i++)
+ {
+ clients[i] = new Client(clientLocator, clientConfig);
+ clients[i].connect();
+ assertEquals("abc", clients[i].invoke("abc"));
+ clients[i].disconnect();
+ }
+
+ // Verify Timer has been created.
+ invokerDestructionTimer = (Timer) field.get(null);
+ assertNotNull(invokerDestructionTimer);
+
+ // Verify all Clients are using the same Timer.
+ for (int i = 0; i < 50; i++)
+ {
+ assertEquals("Should be the same Timer", invokerDestructionTimer, field.get(clients[i]));
+ }
+
+ Thread.sleep(10000);
+ assertEquals(0, InvokerRegistry.getClientInvokers().length);
+
+ // Verify Timer has been destroyed.
+ invokerDestructionTimer = (Timer) field.get(null);
+ assertNull(invokerDestructionTimer);
+
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConfigByInvokerLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "/?invokerDestructionDelay=10000";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker1 = client.getInvoker();
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for first client");
+ client.disconnect();
+
+ Thread.sleep(5000);
+ client = new Client(clientLocator, clientConfig);
+ client.connect();
+ ClientInvoker invoker2 = client.getInvoker();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good for second client");
+ assertSame(invoker2, invoker1);
+
+ 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() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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 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 TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/invoker/ClientInvokerDelayedDestructionTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5985 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:09:12 -0400 (Wed, 04 Aug 2010)
New Revision: 5985
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype/DataTypeRaceTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype/DataTypeRaceTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype/DataTypeRaceTestCase.java 2010-08-05 01:08:36 UTC (rev 5984)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype/DataTypeRaceTestCase.java 2010-08-05 01:09:12 UTC (rev 5985)
@@ -1,252 +1,252 @@
-/*
-* 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.datatype;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.MicroRemoteClientInvoker;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
-
-
-/**
- * Unit test for JBREM-1109.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Apr 8, 2009
- * </p>
- */
-public class DataTypeRaceTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(DataTypeRaceTestCase.class);
-
- private static boolean firstTime = true;
- protected static String dataType;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected Object lock = new Object();
-
-
- 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 testDataTypeRace() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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 datatype race.
- MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
-
- int THREADS = 1000;
- TestThread[] threads = new TestThread[THREADS];
- Rendezvous startBarrier = new Rendezvous(THREADS);
- Rendezvous stopBarrier = new Rendezvous(THREADS + 1);
-
- log.info(getName() + " creating " + THREADS + " threads");
- for (int i = 0; i < THREADS; i++)
- {
- threads[i] = new TestThread(clientInvoker, startBarrier, stopBarrier, i);
- threads[i].start();
- }
-
- log.info(getName() + " waiting on stopBarrier");
- rendezvous(stopBarrier);
- log.info(getName() + " checking threads");
-
- for (int i = 0; i < THREADS; i++)
- {
- assertTrue("failure in " + threads[i], threads[i].ok);
- }
-
- 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() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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();
- }
-
-
- protected static void rendezvous(Rendezvous barrier)
- {
- while (true)
- {
- try
- {
- barrier.rendezvous(null);
- break;
- }
- catch (InterruptedException e1)
- {
-
- }
- }
- }
-
-
- 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 TestThread extends Thread
- {
- String name;
- ClientInvoker clientInvoker;
- Rendezvous startBarrier;
- Rendezvous stopBarrier;
- InvocationRequest request = new InvocationRequest(null, null, "abc", null, null, null);
- boolean ok;
-
- public TestThread(ClientInvoker clientInvoker, Rendezvous startBarrier, Rendezvous stopBarrier, int number)
- {
- this.clientInvoker = clientInvoker;
- this.startBarrier = startBarrier;
- this.stopBarrier = stopBarrier;
- name = "TestThread[" + number + "]";
- }
-
- public void run()
- {
-// log.debug(this + " waiting on startBarrier");
- rendezvous(startBarrier);
-// log.debug(this + " executing");
- try
- {
- clientInvoker.invoke(request);
-// log.debug(this + " waiting on stopBarrier");
- ok = true;
- rendezvous(stopBarrier);
-// log.debug(this + " done");
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- rendezvous(stopBarrier);
- }
- }
-
- public String toString()
- {
- return name;
- }
- }
+/*
+* 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.datatype;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
+
+
+/**
+ * Unit test for JBREM-1109.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Apr 8, 2009
+ * </p>
+ */
+public class DataTypeRaceTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(DataTypeRaceTestCase.class);
+
+ private static boolean firstTime = true;
+ protected static String dataType;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected Object lock = new Object();
+
+
+ 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 testDataTypeRace() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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 datatype race.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+
+ int THREADS = 1000;
+ TestThread[] threads = new TestThread[THREADS];
+ Rendezvous startBarrier = new Rendezvous(THREADS);
+ Rendezvous stopBarrier = new Rendezvous(THREADS + 1);
+
+ log.info(getName() + " creating " + THREADS + " threads");
+ for (int i = 0; i < THREADS; i++)
+ {
+ threads[i] = new TestThread(clientInvoker, startBarrier, stopBarrier, i);
+ threads[i].start();
+ }
+
+ log.info(getName() + " waiting on stopBarrier");
+ rendezvous(stopBarrier);
+ log.info(getName() + " checking threads");
+
+ for (int i = 0; i < THREADS; i++)
+ {
+ assertTrue("failure in " + threads[i], threads[i].ok);
+ }
+
+ 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() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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();
+ }
+
+
+ protected static void rendezvous(Rendezvous barrier)
+ {
+ while (true)
+ {
+ try
+ {
+ barrier.rendezvous(null);
+ break;
+ }
+ catch (InterruptedException e1)
+ {
+
+ }
+ }
+ }
+
+
+ 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 TestThread extends Thread
+ {
+ String name;
+ ClientInvoker clientInvoker;
+ Rendezvous startBarrier;
+ Rendezvous stopBarrier;
+ InvocationRequest request = new InvocationRequest(null, null, "abc", null, null, null);
+ boolean ok;
+
+ public TestThread(ClientInvoker clientInvoker, Rendezvous startBarrier, Rendezvous stopBarrier, int number)
+ {
+ this.clientInvoker = clientInvoker;
+ this.startBarrier = startBarrier;
+ this.stopBarrier = stopBarrier;
+ name = "TestThread[" + number + "]";
+ }
+
+ public void run()
+ {
+// log.debug(this + " waiting on startBarrier");
+ rendezvous(startBarrier);
+// log.debug(this + " executing");
+ try
+ {
+ clientInvoker.invoke(request);
+// log.debug(this + " waiting on stopBarrier");
+ ok = true;
+ rendezvous(stopBarrier);
+// log.debug(this + " done");
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ rendezvous(stopBarrier);
+ }
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/datatype/DataTypeRaceTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5984 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:08:36 -0400 (Wed, 04 Aug 2010)
New Revision: 5984
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params/ConnectionValidatorConfigurationTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params/ConnectionValidatorConfigurationTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params/ConnectionValidatorConfigurationTestCase.java 2010-08-05 01:07:56 UTC (rev 5983)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params/ConnectionValidatorConfigurationTestCase.java 2010-08-05 01:08:36 UTC (rev 5984)
@@ -1,692 +1,692 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.params;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit test for JBREM-1082.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Jan 17, 2009
- * </p>
- */
-public class ConnectionValidatorConfigurationTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionValidatorConfigurationTestCase.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.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 testUseLocatorParamsDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsFalseInLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsFalseInConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- clientConfig.put(Client.USE_ALL_PARAMS, "false");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsFalseInMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- metadata.put(Client.USE_ALL_PARAMS, "false");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsTrueInLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, false);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsTrueInConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- clientConfig.put(Client.USE_ALL_PARAMS, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, false);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsTrueInMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "333");
- clientConfig.put("validatorPingTimeout", "444");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- metadata.put("validatorPingTimeout", "555");
- metadata.put(Client.USE_ALL_PARAMS, "true");
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 555, false);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseLocatorParamsTrueInLocatorAllParamsInLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
- clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- 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 connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- HashMap metadata = new HashMap();
- client.addConnectionListener(listener, metadata);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 111, 222, false);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testExplicitPingPeriodOverridesLocatorAndConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.USE_ALL_PARAMS, "true");
- clientConfig.put("validatorPingPeriod", "222");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener, 333);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 333, 1000, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUnaryLocatorOverridesWithUseAllParams() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.USE_ALL_PARAMS, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 111, 1000, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUnaryLocatorDoesntOverrideWithoutUseAllParams() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&validatorPingPeriod=111";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- 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 connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 2000, 1000, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
-
- public void testUnaryConfigOverrides() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("validatorPingPeriod", "111");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 111, 1000, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUnaryDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- 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 connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Configure ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener);
-
- // Test setting of parameters in ConnectionListener.
- doTestParameters(client, 2000, 1000, true);
-
- client.removeConnectionListener(listener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
-
- protected void doTestParameters(Client client,
- int pingPeriodExpected,
- int pingTimeoutExpected,
- boolean tieToLeaseExpected)
- throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
- {
- Field field = Client.class.getDeclaredField("connectionValidator");
- field.setAccessible(true);
- ConnectionValidator validator = (ConnectionValidator) field.get(client);
- field = ConnectionValidator.class.getDeclaredField("pingPeriod");
- field.setAccessible(true);
- long pingPeriod = ((Long)field.get(validator)).longValue();
- field = ConnectionValidator.class.getDeclaredField("pingTimeout");
- field.setAccessible(true);
- int pingTimeout = ((Integer) field.get(validator)).intValue();
- field = ConnectionValidator.class.getDeclaredField("tieToLease");
- field.setAccessible(true);
- boolean tieToLease = ((Boolean) field.get(validator)).booleanValue();
- log.info("pingPeriod: " + pingPeriod);
- log.info("pingTimeout: " + pingTimeout);
- log.info("tieToLease: " + tieToLease);
- assertEquals(pingPeriodExpected, pingPeriod);
- assertEquals(pingTimeoutExpected, pingTimeout);
- assertEquals(tieToLeaseExpected, tieToLease);
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- else
- {
- locatorURI += "/?" + "x=y";
- }
- 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 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 void handleConnectionException(Throwable throwable, Client client)
- {
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.params;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1082.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Jan 17, 2009
+ * </p>
+ */
+public class ConnectionValidatorConfigurationTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionValidatorConfigurationTestCase.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.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 testUseLocatorParamsDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsFalseInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsFalseInConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ clientConfig.put(Client.USE_ALL_PARAMS, "false");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsFalseInMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ metadata.put(Client.USE_ALL_PARAMS, "false");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsTrueInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, false);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsTrueInConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ clientConfig.put(Client.USE_ALL_PARAMS, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, false);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsTrueInMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "333");
+ clientConfig.put("validatorPingTimeout", "444");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put("validatorPingTimeout", "555");
+ metadata.put(Client.USE_ALL_PARAMS, "true");
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 555, false);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseLocatorParamsTrueInLocatorAllParamsInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111&validatorPingTimeout=222&tieToLease=false";
+ clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ 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 connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ client.addConnectionListener(listener, metadata);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 111, 222, false);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testExplicitPingPeriodOverridesLocatorAndConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.USE_ALL_PARAMS, "true");
+ clientConfig.put("validatorPingPeriod", "222");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener, 333);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 333, 1000, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUnaryLocatorOverridesWithUseAllParams() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.USE_ALL_PARAMS, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 111, 1000, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUnaryLocatorDoesntOverrideWithoutUseAllParams() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&validatorPingPeriod=111";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ 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 connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 2000, 1000, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+
+ public void testUnaryConfigOverrides() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("validatorPingPeriod", "111");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 111, 1000, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUnaryDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ 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 connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Configure ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Test setting of parameters in ConnectionListener.
+ doTestParameters(client, 2000, 1000, true);
+
+ client.removeConnectionListener(listener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+
+ protected void doTestParameters(Client client,
+ int pingPeriodExpected,
+ int pingTimeoutExpected,
+ boolean tieToLeaseExpected)
+ throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
+ {
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator validator = (ConnectionValidator) field.get(client);
+ field = ConnectionValidator.class.getDeclaredField("pingPeriod");
+ field.setAccessible(true);
+ long pingPeriod = ((Long)field.get(validator)).longValue();
+ field = ConnectionValidator.class.getDeclaredField("pingTimeout");
+ field.setAccessible(true);
+ int pingTimeout = ((Integer) field.get(validator)).intValue();
+ field = ConnectionValidator.class.getDeclaredField("tieToLease");
+ field.setAccessible(true);
+ boolean tieToLease = ((Boolean) field.get(validator)).booleanValue();
+ log.info("pingPeriod: " + pingPeriod);
+ log.info("pingTimeout: " + pingTimeout);
+ log.info("tieToLease: " + tieToLease);
+ assertEquals(pingPeriodExpected, pingPeriod);
+ assertEquals(pingTimeoutExpected, pingTimeout);
+ assertEquals(tieToLeaseExpected, tieToLease);
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ else
+ {
+ locatorURI += "/?" + "x=y";
+ }
+ 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 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 void handleConnectionException(Throwable throwable, Client client)
+ {
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/params/ConnectionValidatorConfigurationTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5983 - 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-08-04 21:07:56 -0400 (Wed, 04 Aug 2010)
New Revision: 5983
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java 2010-08-05 01:06:23 UTC (rev 5982)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java 2010-08-05 01:07:56 UTC (rev 5983)
@@ -1,508 +1,508 @@
-/*
-* 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.connection.identity;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.InvokerRegistry;
-import org.jboss.remoting.LeasePinger;
-import org.jboss.remoting.MicroRemoteClientInvoker;
-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.ClientFactory;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.remoting.transport.ServerFactory;
-import org.jboss.remoting.transport.socket.SocketClientInvoker;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
-/**
- * Unit test for JBREM-1128.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright May 08, 2009
- * </p>
- */
-public class ConnectionIdentityTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionIdentityTestCase.class);
-
- private static boolean firstTime = true;
-
- protected static final int LEASE_PERIOD = 2000;
- protected static final int VALIDATOR_PING_TIMEOUT = 1000;
- protected static final int VALIDATOR_PING_PERIOD = 2000;
- protected static final int PING_PERIODS_TO_WAIT = 2;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected TestConnectionListener serverConnectionListener;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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);
- }
- InvokerRegistry.registerInvokerFactories(getTransport(), TestClientFactory.class, TestServerFactory.class);
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testIdentityTrueOneClientRestarts() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "true");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener = new TestConnectionListener("clientConnectionListener");
- client.connect(clientConnectionListener, null);
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger leasePinger1 = (LeasePinger) field.get(client.getInvoker());
- log.info("client is connected");
-
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Test client side connection failure notifications.
- int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
- log.info(getName() + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- log.info("checking connection failure notifications");
- assertEquals(1, clientConnectionListener.calledCounter);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener.throwable.getMessage());
-
- // Test server side connection failure notifications.
- wait = 2 * LEASE_PERIOD;
- log.info(getName() + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- assertEquals(1, serverConnectionListener.calledCounter);
- assertNull(serverConnectionListener.throwable);
-
- // Verify new LeasePinger is created if Client reconnects.
- client.connect(clientConnectionListener, null);
- assertNotSame(leasePinger1, field.get(client.getInvoker()));
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testIdentityTrueTwoClientsOneConnectionValidator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "true");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
- client1.connect(clientConnectionListener1, null);
- Client client2 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
- client2.connect(clientConnectionListener2, null);
- log.info("clients are connected");
-
- // Test connection.
- assertEquals("abc", client1.invoke("abc"));
- assertEquals("abc", client2.invoke("abc"));
- log.info("connections are good");
-
- // Verify Clients share ConnectionValidator.
- Field field = Client.class.getDeclaredField("connectionValidator");
- field.setAccessible(true);
- ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
- ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
- assertSame(connectionValidator1, connectionValidator2);
-
- // Test client side connection failure notifications.
- int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
- log.info(getName() + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- log.info("checking connection failure notifications");
- assertEquals(1, clientConnectionListener1.calledCounter);
- assertTrue(clientConnectionListener1.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
- assertEquals(1, clientConnectionListener2.calledCounter);
- assertTrue(clientConnectionListener2.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
-
- client1.removeConnectionListener(clientConnectionListener1);
- client1.disconnect();
- client2.removeConnectionListener(clientConnectionListener2);
- client2.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testIdentityTrueTwoClientsTwoConnectionValidators() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "true");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
- Map metadata = new HashMap();
- metadata.put("abc", "xyz");
- client1.connect(clientConnectionListener1, metadata);
- Client client2 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
- metadata.put("abc", "123");
- client2.connect(clientConnectionListener2, metadata);
- log.info("clients are connected");
-
- // Test connection.
- assertEquals("abc", client1.invoke("abc"));
- assertEquals("abc", client2.invoke("abc"));
- log.info("connections are good");
-
- // Verify Clients have distinct ConnectionValidators.
- Field field = Client.class.getDeclaredField("connectionValidator");
- field.setAccessible(true);
- ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
- ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
- assertNotSame(connectionValidator1, connectionValidator2);
-
- // Test client side connection failure notifications.
- int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
- log.info(getName() + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- log.info("checking connection failure notifications");
- assertEquals(1, clientConnectionListener1.calledCounter);
- assertTrue(clientConnectionListener1.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
- assertEquals(1, clientConnectionListener2.calledCounter);
- assertTrue(clientConnectionListener2.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
-
- client1.removeConnectionListener(clientConnectionListener1);
- client1.disconnect();
- client2.removeConnectionListener(clientConnectionListener2);
- client2.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testIdentityTrueTwoClientsTwoConnectionValidatorsFourConnectionListeners() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "true");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener1a = new TestConnectionListener("clientConnectionListener1a");
- TestConnectionListener clientConnectionListener1b = new TestConnectionListener("clientConnectionListener1b");
- Map metadata = new HashMap();
- metadata.put("abc", "xyz");
- client1.connect(clientConnectionListener1a, metadata);
- client1.addConnectionListener(clientConnectionListener1b);
- Client client2 = new Client(clientLocator, clientConfig);
- TestConnectionListener clientConnectionListener2a = new TestConnectionListener("clientConnectionListener2a");
- TestConnectionListener clientConnectionListener2b = new TestConnectionListener("clientConnectionListener2b");
- metadata.put("abc", "123");
- client2.connect(clientConnectionListener2a, metadata);
- client2.addConnectionListener(clientConnectionListener2b);
- log.info("clients are connected");
-
- // Test connection.
- assertEquals("abc", client1.invoke("abc"));
- assertEquals("abc", client2.invoke("abc"));
- log.info("connections are good");
-
- // Verify Clients have distinct ConnectionValidators.
- Field field = Client.class.getDeclaredField("connectionValidator");
- field.setAccessible(true);
- ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
- ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
- assertNotSame(connectionValidator1, connectionValidator2);
-
- // Test client side connection failure notifications.
- int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
- log.info(getName() + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- log.info("checking connection failure notifications");
- assertEquals(1, clientConnectionListener1a.calledCounter);
- assertTrue(clientConnectionListener1a.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener1a.throwable.getMessage());
- assertEquals(1, clientConnectionListener1b.calledCounter);
- assertTrue(clientConnectionListener1b.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener1b.throwable.getMessage());
- assertEquals(1, clientConnectionListener2a.calledCounter);
- assertTrue(clientConnectionListener2a.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener2a.throwable.getMessage());
- assertEquals(1, clientConnectionListener2b.calledCounter);
- assertTrue(clientConnectionListener2b.throwable instanceof Exception);
- assertEquals("Could not connect to server!", clientConnectionListener2b.throwable.getMessage());
-
- client1.removeConnectionListener(clientConnectionListener1a);
- client1.removeConnectionListener(clientConnectionListener1b);
- client1.disconnect();
- client2.removeConnectionListener(clientConnectionListener2a);
- client2.removeConnectionListener(clientConnectionListener2b);
- client2.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "test";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(boolean addUseClientConnectionIdentity, String useClientConnectionIdentity) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "&" + metadata;
- }
- if (addUseClientConnectionIdentity)
- {
- locatorURI += "&" + Remoting.USE_CLIENT_CONNECTION_IDENTITY + "=" + useClientConnectionIdentity;
- }
- 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.setLeasePeriod(LEASE_PERIOD);
- serverConnectionListener = new TestConnectionListener("serverConnectionListener");
- connector.addConnectionListener(serverConnectionListener);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- 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
- {
- String name;
- Throwable throwable;
- int calledCounter;
-
- public TestConnectionListener(String name)
- {
- this.name = name;
- }
- public void handleConnectionException(Throwable throwable, Client client)
- {
- calledCounter++;
- this.throwable = throwable;
- log.info(name + " notified: throwable = " + throwable);
- }
- }
-
-
- static class TestServerInvoker extends SocketServerInvoker
- {
- int counter;
-
- public TestServerInvoker(InvokerLocator locator, Map configuration)
- {
- super(locator, configuration);
- }
- public TestServerInvoker(InvokerLocator locator)
- {
- super(locator);
- }
-
- public Object invoke(InvocationRequest invocation) throws Throwable
- {
- Object param = invocation.getParameter();
-// log.info("TestServerInvoker.invoke() entered: " + param);
- if ("$PING$".equals(param))
- {
- Map metadata = invocation.getRequestPayload();
- if (metadata != null)
- {
-// log.info("metadata: " + metadata);
- String invokerSessionId = (String) metadata.get(INVOKER_SESSION_ID);
- if (invokerSessionId != null)
- {
- log.info(this + " got a ConnectionValidator $PING$");
- if (++counter > PING_PERIODS_TO_WAIT)
- {
- int wait = 2 * VALIDATOR_PING_TIMEOUT;
- log.info(this + " going to sleep for " + wait + " ms");
- Thread.sleep(wait);
- }
- }
- }
- }
- return super.invoke(invocation);
- }
-
- public String toString()
- {
- String s = super.toString();
- int i = s.indexOf('[');
- return "TestServerInvoker" + s.substring(i);
- }
- }
-
-
- public static class TestClientFactory implements ClientFactory
- {
- public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
- {
- log.info("TestClientFaotory.createClientInvoker() called");
- return new SocketClientInvoker(locator, config);
- }
- public boolean supportsSSL()
- {
- return false;
- }
- }
-
-
- public static class TestServerFactory implements ServerFactory
- {
- public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
- {
- log.info("TestServerFactory.createServerInvoker() called");
- return new TestServerInvoker(locator, config);
- }
- public boolean supportsSSL()
- {
- return false;
- }
- }
+/*
+* 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.connection.identity;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+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.ClientFactory;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.ServerFactory;
+import org.jboss.remoting.transport.socket.SocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+/**
+ * Unit test for JBREM-1128.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class ConnectionIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionIdentityTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected static final int LEASE_PERIOD = 2000;
+ protected static final int VALIDATOR_PING_TIMEOUT = 1000;
+ protected static final int VALIDATOR_PING_PERIOD = 2000;
+ protected static final int PING_PERIODS_TO_WAIT = 2;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener serverConnectionListener;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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);
+ }
+ InvokerRegistry.registerInvokerFactories(getTransport(), TestClientFactory.class, TestServerFactory.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testIdentityTrueOneClientRestarts() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("clientConnectionListener");
+ client.connect(clientConnectionListener, null);
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger leasePinger1 = (LeasePinger) field.get(client.getInvoker());
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener.calledCounter);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener.throwable.getMessage());
+
+ // Test server side connection failure notifications.
+ wait = 2 * LEASE_PERIOD;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ assertEquals(1, serverConnectionListener.calledCounter);
+ assertNull(serverConnectionListener.throwable);
+
+ // Verify new LeasePinger is created if Client reconnects.
+ client.connect(clientConnectionListener, null);
+ assertNotSame(leasePinger1, field.get(client.getInvoker()));
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsOneConnectionValidator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
+ client1.connect(clientConnectionListener1, null);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
+ client2.connect(clientConnectionListener2, null);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients share ConnectionValidator.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1.calledCounter);
+ assertTrue(clientConnectionListener1.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2.calledCounter);
+ assertTrue(clientConnectionListener2.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsTwoConnectionValidators() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
+ Map metadata = new HashMap();
+ metadata.put("abc", "xyz");
+ client1.connect(clientConnectionListener1, metadata);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
+ metadata.put("abc", "123");
+ client2.connect(clientConnectionListener2, metadata);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients have distinct ConnectionValidators.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertNotSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1.calledCounter);
+ assertTrue(clientConnectionListener1.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2.calledCounter);
+ assertTrue(clientConnectionListener2.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsTwoConnectionValidatorsFourConnectionListeners() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1a = new TestConnectionListener("clientConnectionListener1a");
+ TestConnectionListener clientConnectionListener1b = new TestConnectionListener("clientConnectionListener1b");
+ Map metadata = new HashMap();
+ metadata.put("abc", "xyz");
+ client1.connect(clientConnectionListener1a, metadata);
+ client1.addConnectionListener(clientConnectionListener1b);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2a = new TestConnectionListener("clientConnectionListener2a");
+ TestConnectionListener clientConnectionListener2b = new TestConnectionListener("clientConnectionListener2b");
+ metadata.put("abc", "123");
+ client2.connect(clientConnectionListener2a, metadata);
+ client2.addConnectionListener(clientConnectionListener2b);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients have distinct ConnectionValidators.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertNotSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1a.calledCounter);
+ assertTrue(clientConnectionListener1a.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1a.throwable.getMessage());
+ assertEquals(1, clientConnectionListener1b.calledCounter);
+ assertTrue(clientConnectionListener1b.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1b.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2a.calledCounter);
+ assertTrue(clientConnectionListener2a.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2a.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2b.calledCounter);
+ assertTrue(clientConnectionListener2b.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2b.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1a);
+ client1.removeConnectionListener(clientConnectionListener1b);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2a);
+ client2.removeConnectionListener(clientConnectionListener2b);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "test";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean addUseClientConnectionIdentity, String useClientConnectionIdentity) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ if (addUseClientConnectionIdentity)
+ {
+ locatorURI += "&" + Remoting.USE_CLIENT_CONNECTION_IDENTITY + "=" + useClientConnectionIdentity;
+ }
+ 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.setLeasePeriod(LEASE_PERIOD);
+ serverConnectionListener = new TestConnectionListener("serverConnectionListener");
+ connector.addConnectionListener(serverConnectionListener);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ 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
+ {
+ String name;
+ Throwable throwable;
+ int calledCounter;
+
+ public TestConnectionListener(String name)
+ {
+ this.name = name;
+ }
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ calledCounter++;
+ this.throwable = throwable;
+ log.info(name + " notified: throwable = " + throwable);
+ }
+ }
+
+
+ static class TestServerInvoker extends SocketServerInvoker
+ {
+ int counter;
+
+ public TestServerInvoker(InvokerLocator locator, Map configuration)
+ {
+ super(locator, configuration);
+ }
+ public TestServerInvoker(InvokerLocator locator)
+ {
+ super(locator);
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ Object param = invocation.getParameter();
+// log.info("TestServerInvoker.invoke() entered: " + param);
+ if ("$PING$".equals(param))
+ {
+ Map metadata = invocation.getRequestPayload();
+ if (metadata != null)
+ {
+// log.info("metadata: " + metadata);
+ String invokerSessionId = (String) metadata.get(INVOKER_SESSION_ID);
+ if (invokerSessionId != null)
+ {
+ log.info(this + " got a ConnectionValidator $PING$");
+ if (++counter > PING_PERIODS_TO_WAIT)
+ {
+ int wait = 2 * VALIDATOR_PING_TIMEOUT;
+ log.info(this + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ }
+ }
+ }
+ }
+ return super.invoke(invocation);
+ }
+
+ public String toString()
+ {
+ String s = super.toString();
+ int i = s.indexOf('[');
+ return "TestServerInvoker" + s.substring(i);
+ }
+ }
+
+
+ public static class TestClientFactory implements ClientFactory
+ {
+ public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ log.info("TestClientFaotory.createClientInvoker() called");
+ return new SocketClientInvoker(locator, config);
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
+
+
+ public static class TestServerFactory implements ServerFactory
+ {
+ public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ log.info("TestServerFactory.createServerInvoker() called");
+ return new TestServerInvoker(locator, config);
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java 2010-08-05 01:06:23 UTC (rev 5982)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java 2010-08-05 01:07:56 UTC (rev 5983)
@@ -1,302 +1,302 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.LeasePinger;
-import org.jboss.remoting.MicroRemoteClientInvoker;
-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.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.util.id.GUID;
-
-
-/**
- * Unit test for JBREM-1128.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright May 08, 2009
- * </p>
- */
-public class LeaseIdentityTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(LeaseIdentityTestCase.class);
-
- protected static long LEASE_PERIOD = 2000;
- protected static String LEASE_PERIOD_STRING = "2000";
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected TestConnectionListener listener;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(false, null);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "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");
-
- // Test lease behavior.
- MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
- clientInvoker.terminateLease(client.getSessionId(), 0);
- TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
- leasePinger.setLeasePingerId(new GUID().toString());
- leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
- leasePinger.startPing();
- Thread.sleep(LEASE_PERIOD * 4);
- assertFalse(listener.called);
-
- leasePinger.stopPing();
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testClientConnectionIdentityFalse() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "false");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "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");
-
- // Test lease behavior.
- MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
- clientInvoker.terminateLease(client.getSessionId(), 0);
- TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
- leasePinger.setLeasePingerId(new GUID().toString());
- leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
- leasePinger.startPing();
- Thread.sleep(LEASE_PERIOD * 4);
- assertFalse(listener.called);
-
- leasePinger.stopPing();
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testClientConnectionIdentityTrue() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, "true");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "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");
-
- // Test lease behavior.
- MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
- clientInvoker.terminateLease(client.getSessionId(), 0);
- TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
- leasePinger.setLeasePingerId(new GUID().toString());
- leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
- leasePinger.startPing();
- Thread.sleep(LEASE_PERIOD * 4);
- assertTrue(listener.called);
- assertNull(listener.throwable);
-
- leasePinger.stopPing();
- 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 setUseClientIdentity, String useClientIdentity) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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");
- config.put("leasePeriod", LEASE_PERIOD_STRING);
- if (setUseClientIdentity)
- {
- config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, useClientIdentity);
- }
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- listener = new TestConnectionListener();
- connector.addConnectionListener(listener);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- 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 called;
- public Throwable throwable;
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- called = true;
- this.throwable = throwable;
- log.info("called: throwable = " + throwable);
- }
- }
-
-
- static class TestLeasePinger extends LeasePinger
- {
- public TestLeasePinger(ClientInvoker invoker, String invokerSessionID, long defaultLeasePeriod)
- {
- super(invoker, invokerSessionID, defaultLeasePeriod);
- }
-
- public void setLeasePingerId(String leasePingerId)
- {
- super.setLeasePingerId(leasePingerId);
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+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.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.util.id.GUID;
+
+
+/**
+ * Unit test for JBREM-1128.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(LeaseIdentityTestCase.class);
+
+ protected static long LEASE_PERIOD = 2000;
+ protected static String LEASE_PERIOD_STRING = "2000";
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener listener;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "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");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertFalse(listener.called);
+
+ leasePinger.stopPing();
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientConnectionIdentityFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "false");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "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");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertFalse(listener.called);
+
+ leasePinger.stopPing();
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientConnectionIdentityTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "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");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertTrue(listener.called);
+ assertNull(listener.throwable);
+
+ leasePinger.stopPing();
+ 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 setUseClientIdentity, String useClientIdentity) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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");
+ config.put("leasePeriod", LEASE_PERIOD_STRING);
+ if (setUseClientIdentity)
+ {
+ config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, useClientIdentity);
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ listener = new TestConnectionListener();
+ connector.addConnectionListener(listener);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ 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 called;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ called = true;
+ this.throwable = throwable;
+ log.info("called: throwable = " + throwable);
+ }
+ }
+
+
+ static class TestLeasePinger extends LeasePinger
+ {
+ public TestLeasePinger(ClientInvoker invoker, String invokerSessionID, long defaultLeasePeriod)
+ {
+ super(invoker, invokerSessionID, defaultLeasePeriod);
+ }
+
+ public void setLeasePingerId(String leasePingerId)
+ {
+ super.setLeasePingerId(leasePingerId);
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5982 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:06:23 -0400 (Wed, 04 Aug 2010)
New Revision: 5982
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java 2010-08-05 01:04:38 UTC (rev 5981)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java 2010-08-05 01:06:23 UTC (rev 5982)
@@ -1,154 +1,154 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.deadlock;
-
-import java.net.InetAddress;
-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.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvokerLocator;
-
-/**
- * Unit test for JBREM-1070.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Nov 29, 2008
- * </p>
- */
-public class DeadlockTestClient extends TestCase
-{
- private static Logger log = Logger.getLogger(DeadlockTestClient.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port = 7777;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
-
-
- 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 testForDeadlock() throws Throwable
- {
- log.info("entering " + getName());
- for (int i = 0; i < 10; i++)
- {
- assertTrue("failed execution: " + i, doTest());
- log.info("execution " + i + " PASSES\n");
- }
- log.info(getName() + " PASSES");
- }
-
-
- public boolean doTest() throws Throwable
- {
- // Create client.
- host = InetAddress.getLocalHost().getHostAddress();
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "5000");
- clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Add ConnectionListener.
- TestConnectionListener listener = new TestConnectionListener();
- client.addConnectionListener(listener);
-
- // Wait for notification.
- for (int i = 0; i < 20; i++)
- {
- if (listener.ok)
- {
- break;
- }
- Thread.sleep(1000);
- }
-
- client.disconnect();
- return listener.ok;
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
-
-
- static class TestConnectionListener implements ConnectionListener
- {
- public boolean ok;
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- ok = true;
- log.info("handleConnectionException() called");
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deadlock;
+
+import java.net.InetAddress;
+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.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * Unit test for JBREM-1070.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Nov 29, 2008
+ * </p>
+ */
+public class DeadlockTestClient extends TestCase
+{
+ private static Logger log = Logger.getLogger(DeadlockTestClient.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port = 7777;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+
+
+ 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 testForDeadlock() throws Throwable
+ {
+ log.info("entering " + getName());
+ for (int i = 0; i < 10; i++)
+ {
+ assertTrue("failed execution: " + i, doTest());
+ log.info("execution " + i + " PASSES\n");
+ }
+ log.info(getName() + " PASSES");
+ }
+
+
+ public boolean doTest() throws Throwable
+ {
+ // Create client.
+ host = InetAddress.getLocalHost().getHostAddress();
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "5000");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Add ConnectionListener.
+ TestConnectionListener listener = new TestConnectionListener();
+ client.addConnectionListener(listener);
+
+ // Wait for notification.
+ for (int i = 0; i < 20; i++)
+ {
+ if (listener.ok)
+ {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+
+ client.disconnect();
+ return listener.ok;
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean ok;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ ok = true;
+ log.info("handleConnectionException() called");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.java 2010-08-05 01:04:38 UTC (rev 5981)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.java 2010-08-05 01:06:23 UTC (rev 5982)
@@ -1,193 +1,193 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.deadlock;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-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.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- * Unit test for JBREM-1070.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Nov 29, 2008
- * </p>
- */
-public class DeadlockTestServer extends ServerTestCase
-{
- private static Logger log = Logger.getLogger(DeadlockTestServer.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port = 7777;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected TestServerInvoker serverInvoker;
- protected TestInvocationHandler invocationHandler;
-
-
- public static void main(String[] args)
- {
- try
- {
- DeadlockTestServer server = new DeadlockTestServer();
- server.setUp();
- Thread.sleep(600000);
- server.shutdownServer();
- }
- catch (Throwable t)
- {
- log.error("error", t);
- }
- }
-
-
- 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);
- }
-
- setupServer();
- }
-
-
- public void tearDown() throws Exception
- {
- shutdownServer();
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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);
-
- serverInvoker = new TestServerInvoker(serverLocator, config);
- serverInvoker.create();
- invocationHandler = new TestInvocationHandler();
- serverInvoker.addInvocationHandler("test", invocationHandler);
- serverInvoker.start();
- log.info("TestServerInvoker(" + locatorURI + ") started");
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (serverInvoker != null)
- serverInvoker.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 TestServerInvoker extends SocketServerInvoker
- {
- public TestServerInvoker(InvokerLocator locator, Map config)
- {
- super(locator, config);
- log.info("TestServerInvoker: " + locator);
- }
- public Object invoke(InvocationRequest invocation) throws Throwable
- {
- if ("$PING$".equals(invocation.getParameter()))
- {
- log.info("TestServerInvoker received $PING$");
- Thread.sleep(10000);
- throw new Exception("got $PING$");
- }
- else
- {
- return super.invoke(invocation);
- }
- }
- }
-
- static class TestConnectionListener implements ConnectionListener
- {
- public boolean ok;
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- ok = true;
- log.info("handleConnectionException() called");
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deadlock;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+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.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit test for JBREM-1070.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Nov 29, 2008
+ * </p>
+ */
+public class DeadlockTestServer extends ServerTestCase
+{
+ private static Logger log = Logger.getLogger(DeadlockTestServer.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port = 7777;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected TestServerInvoker serverInvoker;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ DeadlockTestServer server = new DeadlockTestServer();
+ server.setUp();
+ Thread.sleep(600000);
+ server.shutdownServer();
+ }
+ catch (Throwable t)
+ {
+ log.error("error", t);
+ }
+ }
+
+
+ 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);
+ }
+
+ setupServer();
+ }
+
+
+ public void tearDown() throws Exception
+ {
+ shutdownServer();
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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);
+
+ serverInvoker = new TestServerInvoker(serverLocator, config);
+ serverInvoker.create();
+ invocationHandler = new TestInvocationHandler();
+ serverInvoker.addInvocationHandler("test", invocationHandler);
+ serverInvoker.start();
+ log.info("TestServerInvoker(" + locatorURI + ") started");
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (serverInvoker != null)
+ serverInvoker.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 TestServerInvoker extends SocketServerInvoker
+ {
+ public TestServerInvoker(InvokerLocator locator, Map config)
+ {
+ super(locator, config);
+ log.info("TestServerInvoker: " + locator);
+ }
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ if ("$PING$".equals(invocation.getParameter()))
+ {
+ log.info("TestServerInvoker received $PING$");
+ Thread.sleep(10000);
+ throw new Exception("got $PING$");
+ }
+ else
+ {
+ return super.invoke(invocation);
+ }
+ }
+ }
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean ok;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ ok = true;
+ log.info("handleConnectionException() called");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months
JBoss Remoting SVN: r5981 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:04:38 -0400 (Wed, 04 Aug 2010)
New Revision: 5981
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorNPETestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTiedToLeaseTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java 2010-08-05 01:03:23 UTC (rev 5980)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java 2010-08-05 01:04:38 UTC (rev 5981)
@@ -1,594 +1,594 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ClientDisconnectedException;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.InvokerRegistry;
-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.ServerFactory;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- * Unit test for JBREM-1112.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Apr 3, 2009
- * </p>
- */
-public class ConnectionValidatorDisconnectTimeoutTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionValidatorDisconnectTimeoutTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected TestConnectionListener serverConnectionListener;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testDefaultUnary() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener);
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testDefaultFirstBinary() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, 500);
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testDefaultSecondBinary() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testZeroInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
- clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=0";
- log.info("clientLocatorURI: " + clientLocatorURI);
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(8000);
- assertTrue(serverConnectionListener.notified);
- assertNull(serverConnectionListener.throwable);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.removeConnectionListener(clientConnectionListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNonZeroInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
- clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=10000";
- log.info("clientLocatorURI: " + clientLocatorURI);
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testZeroConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(8000);
- assertTrue(serverConnectionListener.notified);
- assertNull(serverConnectionListener.throwable);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNonZeroConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "10000");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- client.addConnectionListener(clientConnectionListener, new HashMap());
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testZeroMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- HashMap metadata = new HashMap();
- metadata.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
- client.addConnectionListener(clientConnectionListener, metadata);
-
- // Wait for broken connection and test.
- Thread.sleep(8000);
- assertTrue(serverConnectionListener.notified);
- assertNull(serverConnectionListener.throwable);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNonZeroMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Client.ENABLE_LEASE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Install ConnectionListener.
- TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
- HashMap metadata = new HashMap();
- metadata.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "10000");
- client.addConnectionListener(clientConnectionListener, metadata);
-
- // Wait for broken connection and test.
- Thread.sleep(4000);
- assertTrue(serverConnectionListener.notified);
- assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
- assertTrue(clientConnectionListener.notified);
- assertTrue(clientConnectionListener.throwable instanceof Exception);
- assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
-
- 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() throws Exception
- {
- InvokerRegistry.registerInvokerFactories("socket", org.jboss.remoting.transport.socket.TransportClientFactory.class, TestServerInvokerFactory.class);
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
- 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");
- config.put("leasePeriod", "1000");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- serverConnectionListener = new TestConnectionListener("SERVER");
- connector.addConnectionListener(serverConnectionListener);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestServerInvoker extends SocketServerInvoker
- {
- public TestServerInvoker(InvokerLocator locator, Map configuration)
- {
- super(locator, configuration);
- }
-
- public Object invoke(InvocationRequest invocation) throws Throwable
- {
- Object param = invocation.getParameter();
-
- // check to see if this is a is alive ping
- if ("$PING$".equals(param))
- {
- Map metadata = invocation.getRequestPayload();
- if (metadata != null)
- {
- String invokerSessionId = (String) metadata.get(INVOKER_SESSION_ID);
- if (invokerSessionId != null)
- {
- // Comes from ConnectionValidator configured to tie validation with lease.
- log.info(this + " responding FALSE to $PING$ for invoker sessionId " + invokerSessionId);
- return Boolean.FALSE;
- }
- }
- }
-
- return super.invoke(invocation);
- }
- }
-
-
- public static class TestServerInvokerFactory implements ServerFactory
- {
- public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
- {
- return new TestServerInvoker(locator, config);
- }
-
- public boolean supportsSSL()
- {
- return false;
- }
- }
-
-
- 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 notified;
- public Throwable throwable;
- String name;
-
- TestConnectionListener(String name)
- {
- this.name = name;
- }
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- notified = true;
- this.throwable = throwable;
- log.info(this + " NOTIFIED, throwable = " + throwable);
- }
-
- public String toString()
- {
- return "TestConnectionListener[" + name + "]";
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ClientDisconnectedException;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+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.ServerFactory;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit test for JBREM-1112.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Apr 3, 2009
+ * </p>
+ */
+public class ConnectionValidatorDisconnectTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionValidatorDisconnectTimeoutTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener serverConnectionListener;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testDefaultUnary() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener);
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testDefaultFirstBinary() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, 500);
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testDefaultSecondBinary() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, new HashMap());
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testZeroInvokerLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
+ clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=0";
+ log.info("clientLocatorURI: " + clientLocatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, new HashMap());
+
+ // Wait for broken connection and test.
+ Thread.sleep(8000);
+ assertTrue(serverConnectionListener.notified);
+ assertNull(serverConnectionListener.throwable);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNonZeroInvokerLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&" + Client.USE_ALL_PARAMS + "=true";
+ clientLocatorURI += "&" + ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT + "=10000";
+ log.info("clientLocatorURI: " + clientLocatorURI);
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, new HashMap());
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testZeroConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, new HashMap());
+
+ // Wait for broken connection and test.
+ Thread.sleep(8000);
+ assertTrue(serverConnectionListener.notified);
+ assertNull(serverConnectionListener.throwable);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNonZeroConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "10000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ client.addConnectionListener(clientConnectionListener, new HashMap());
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testZeroMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ HashMap metadata = new HashMap();
+ metadata.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ client.addConnectionListener(clientConnectionListener, metadata);
+
+ // Wait for broken connection and test.
+ Thread.sleep(8000);
+ assertTrue(serverConnectionListener.notified);
+ assertNull(serverConnectionListener.throwable);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNonZeroMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install ConnectionListener.
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("CLIENT");
+ HashMap metadata = new HashMap();
+ metadata.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "10000");
+ client.addConnectionListener(clientConnectionListener, metadata);
+
+ // Wait for broken connection and test.
+ Thread.sleep(4000);
+ assertTrue(serverConnectionListener.notified);
+ assertTrue(serverConnectionListener.throwable instanceof ClientDisconnectedException);
+ assertTrue(clientConnectionListener.notified);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", ((Exception)clientConnectionListener.throwable).getMessage());
+
+ 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() throws Exception
+ {
+ InvokerRegistry.registerInvokerFactories("socket", org.jboss.remoting.transport.socket.TransportClientFactory.class, TestServerInvokerFactory.class);
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
+ 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");
+ config.put("leasePeriod", "1000");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ serverConnectionListener = new TestConnectionListener("SERVER");
+ connector.addConnectionListener(serverConnectionListener);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestServerInvoker extends SocketServerInvoker
+ {
+ public TestServerInvoker(InvokerLocator locator, Map configuration)
+ {
+ super(locator, configuration);
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ Object param = invocation.getParameter();
+
+ // check to see if this is a is alive ping
+ if ("$PING$".equals(param))
+ {
+ Map metadata = invocation.getRequestPayload();
+ if (metadata != null)
+ {
+ String invokerSessionId = (String) metadata.get(INVOKER_SESSION_ID);
+ if (invokerSessionId != null)
+ {
+ // Comes from ConnectionValidator configured to tie validation with lease.
+ log.info(this + " responding FALSE to $PING$ for invoker sessionId " + invokerSessionId);
+ return Boolean.FALSE;
+ }
+ }
+ }
+
+ return super.invoke(invocation);
+ }
+ }
+
+
+ public static class TestServerInvokerFactory implements ServerFactory
+ {
+ public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ return new TestServerInvoker(locator, config);
+ }
+
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
+
+
+ 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 notified;
+ public Throwable throwable;
+ String name;
+
+ TestConnectionListener(String name)
+ {
+ this.name = name;
+ }
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ notified = true;
+ this.throwable = throwable;
+ log.info(this + " NOTIFIED, throwable = " + throwable);
+ }
+
+ public String toString()
+ {
+ return "TestConnectionListener[" + name + "]";
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorDisconnectTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorNPETestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorNPETestCase.java 2010-08-05 01:03:23 UTC (rev 5980)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorNPETestCase.java 2010-08-05 01:04:38 UTC (rev 5981)
@@ -1,239 +1,239 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionValidator;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
-import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
-
-
-/**
- * Unit test for JBREM-1166.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Dec 13, 2009
- */
-public class ConnectionValidatorNPETestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionValidatorNPETestCase.class);
- private static boolean firstTime = true;
- private static int COUNT = 2000;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected SynchronizedInt errors = new SynchronizedInt(0);
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testNPE() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(config);
- Client client = new Client(serverLocator, config);
- client.connect();
-
- // Start busy thread.
- new Thread()
- {
- public void run()
- {
- int i = 0;
- while (true)
- {
- i++;
- }
- }
- }.start();
-
- // Create ConnectionValidator multiiple times.
- HashMap metadata = new HashMap();
- metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1");
- TestConnectionValidator[] validators = new TestConnectionValidator[COUNT];
- for (int i = 0; i < COUNT; i++)
- {
- validators[i] = new TestConnectionValidator(i, errors, client, metadata);
- validators[i].addConnectionListener(client, new TestConnectionListener());
- }
-
- Thread.sleep(5000);
- assertEquals(0, errors.get());
-
- 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() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- 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 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 void handleConnectionException(Throwable throwable, Client client)
- {
- }
- }
-
- static class TestConnectionValidator extends ConnectionValidator
- {
- public volatile boolean timerWasNull;
- int id;
- Rendezvous rendezvous;
- boolean[] flags;
- SynchronizedInt errors;
- Field field;
-
- public TestConnectionValidator(int id, SynchronizedInt errors, Client client, Map metadata) throws SecurityException, NoSuchFieldException
- {
- super(client, metadata);
- this.id = id;
- this.errors = errors;
- field = ConnectionValidator.class.getDeclaredField("timer");
- field.setAccessible(true);
- }
-
- public void run()
- {
- try
- {
-// log.info(id + ": starting");
- timerWasNull = (field.get(this) == null);
- if (timerWasNull)
- {
- log.info("timer was null: " + id);
- errors.increment();
- }
- }
- catch (Exception e)
- {
- log.info("exception", e);
- }
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
+
+
+/**
+ * Unit test for JBREM-1166.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Dec 13, 2009
+ */
+public class ConnectionValidatorNPETestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionValidatorNPETestCase.class);
+ private static boolean firstTime = true;
+ private static int COUNT = 2000;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected SynchronizedInt errors = new SynchronizedInt(0);
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testNPE() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(config);
+ Client client = new Client(serverLocator, config);
+ client.connect();
+
+ // Start busy thread.
+ new Thread()
+ {
+ public void run()
+ {
+ int i = 0;
+ while (true)
+ {
+ i++;
+ }
+ }
+ }.start();
+
+ // Create ConnectionValidator multiiple times.
+ HashMap metadata = new HashMap();
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1");
+ TestConnectionValidator[] validators = new TestConnectionValidator[COUNT];
+ for (int i = 0; i < COUNT; i++)
+ {
+ validators[i] = new TestConnectionValidator(i, errors, client, metadata);
+ validators[i].addConnectionListener(client, new TestConnectionListener());
+ }
+
+ Thread.sleep(5000);
+ assertEquals(0, errors.get());
+
+ 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() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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 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 void handleConnectionException(Throwable throwable, Client client)
+ {
+ }
+ }
+
+ static class TestConnectionValidator extends ConnectionValidator
+ {
+ public volatile boolean timerWasNull;
+ int id;
+ Rendezvous rendezvous;
+ boolean[] flags;
+ SynchronizedInt errors;
+ Field field;
+
+ public TestConnectionValidator(int id, SynchronizedInt errors, Client client, Map metadata) throws SecurityException, NoSuchFieldException
+ {
+ super(client, metadata);
+ this.id = id;
+ this.errors = errors;
+ field = ConnectionValidator.class.getDeclaredField("timer");
+ field.setAccessible(true);
+ }
+
+ public void run()
+ {
+ try
+ {
+// log.info(id + ": starting");
+ timerWasNull = (field.get(this) == null);
+ if (timerWasNull)
+ {
+ log.info("timer was null: " + id);
+ errors.increment();
+ }
+ }
+ catch (Exception e)
+ {
+ log.info("exception", e);
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorNPETestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTiedToLeaseTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTiedToLeaseTestCase.java 2010-08-05 01:03:23 UTC (rev 5980)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTiedToLeaseTestCase.java 2010-08-05 01:04:38 UTC (rev 5981)
@@ -1,588 +1,588 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.remoting.connection;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimerTask;
-
-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.LeasePinger;
-import org.jboss.remoting.MicroRemoteClientInvoker;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit tests for JBREM-891.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jan 19, 2008
- * </p>
- */
-public class ConnectionValidatorTiedToLeaseTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionValidatorTiedToLeaseTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected TestConnectionListener serverListener;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testTiedToLeaseDefaultConfigurationLocalInvoker() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- client.addConnectionListener(clientListener);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify LeasePinger is running.
- assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
- ClientInvoker clientInvoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
- assertNotNull(pinger);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- // Shut down lease on server side.
- connector.removeConnectionListener(serverListener);
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has stopped.
- Thread.sleep(4000);
- assertTrue(clientListener.notified);
- assertEquals(-1, client.getPingPeriod());
-
- // Verfiy LeasePinger has stopped.
- timerTask = (TimerTask) field.get(pinger);
- assertNull(timerTask);
-
- client.removeConnectionListener(clientListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testTiedToLeaseDefaultConfigurationRemoteInvoker() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- Map metadata = new HashMap();
- metadata.put(InvokerLocator.FORCE_REMOTE, "true");
- client.addConnectionListener(clientListener, metadata);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify LeasePinger is running.
- assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
- ClientInvoker clientInvoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
- assertNotNull(pinger);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- // Shut down lease on server side.
- connector.removeConnectionListener(serverListener);
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has stopped.
- Thread.sleep(4000);
- assertTrue(clientListener.notified);
- assertEquals(-1, client.getPingPeriod());
-
- // Verfiy LeasePinger has stopped.
- timerTask = (TimerTask) field.get(pinger);
- assertNull(timerTask);
-
- client.removeConnectionListener(clientListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testTiedToLeaseDontStopLease() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- Map metadata = new HashMap();
- metadata.put(InvokerLocator.FORCE_REMOTE, "true");
- metadata.put(ConnectionValidator.TIE_TO_LEASE, "true");
- metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "false");
- client.addConnectionListener(clientListener, metadata);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify LeasePinger is running.
- assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
- ClientInvoker clientInvoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
- assertNotNull(pinger);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- // Shut down lease on server side.
- connector.removeConnectionListener(serverListener);
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has stopped.
- Thread.sleep(4000);
- assertTrue(clientListener.notified);
- assertEquals(-1, client.getPingPeriod());
-
- // Verfiy LeasePinger has not stopped.
- timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- client.removeConnectionListener(clientListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNotTiedToLeaseDontStopLease() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- Map metadata = new HashMap();
- metadata.put(InvokerLocator.FORCE_REMOTE, "true");
- metadata.put(ConnectionValidator.TIE_TO_LEASE, "false");
- metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "false");
- client.addConnectionListener(clientListener, metadata);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify LeasePinger is running.
- assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
- ClientInvoker clientInvoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
- assertNotNull(pinger);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- // Shut down lease on server side.
- connector.removeConnectionListener(serverListener);
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has not stopped.
- Thread.sleep(4000);
- assertFalse(clientListener.notified);
- assertTrue(client.getPingPeriod() > -1);
-
- // Verfiy LeasePinger has not stopped.
- timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- client.removeConnectionListener(clientListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNotTiedToLeaseStopLease() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- Map metadata = new HashMap();
- metadata.put(InvokerLocator.FORCE_REMOTE, "true");
- metadata.put(ConnectionValidator.TIE_TO_LEASE, "false");
- metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "true");
- client.addConnectionListener(clientListener, metadata);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Verify LeasePinger is running.
- assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
- ClientInvoker clientInvoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
- assertNotNull(pinger);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- assertNotNull(timerTask);
-
- // Prevent server from responding to ConnectionValidator pings.
- ServerInvoker serverInvoker = connector.getServerInvoker();
- field = ServerInvoker.class.getDeclaredField("started");
- field.setAccessible(true);
- field.set(serverInvoker, new Boolean(false));
- assertFalse(field.getBoolean(serverInvoker));
- log.info("Stopped server invoker");
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has stopped.
- Thread.sleep(4000);
- assertTrue(clientListener.notified);
- assertEquals(-1, client.getPingPeriod());
-
- // Verfiy LeasePinger has stopped.
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- timerTask = (TimerTask) field.get(pinger);
- assertNull(timerTask);
-
- client.removeConnectionListener(clientListener);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testTiedToLeaseServerLeasingTurnedOff() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(false);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- 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");
-
- // Register client side listener.
- Object lock = new Object();
- TestConnectionListener clientListener = new TestConnectionListener(lock);
- Map metadata = new HashMap();
- metadata.put(InvokerLocator.FORCE_REMOTE, "true");
- client.addConnectionListener(clientListener, metadata);
- log.info("connection listener added on client side");
-
- // Verify ConnectionValidator is running.
- assertTrue(client.getPingPeriod() > -1);
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Wait for client side listener to be notified.
- synchronized (lock)
- {
- lock.wait(30000);
- }
-
- // Verify ConnectionValidator has not stopped.
- Thread.sleep(4000);
- assertFalse(clientListener.notified);
- assertTrue(client.getPingPeriod() > -1);
-
- client.removeConnectionListener(clientListener);
- 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 startLeasing) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- locatorURI += "/?" + InvokerLocator.CLIENT_LEASE + "=true";
- locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=4000";
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- config.put(ServerInvoker.CLIENT_LEASE_PERIOD, "4000");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- if (startLeasing)
- {
- serverListener = new TestConnectionListener();
- connector.addConnectionListener(serverListener);
- }
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- {
- connector.removeConnectionListener(serverListener);
- 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 notified;
- private Object lock;
-
- TestConnectionListener()
- {
- this(new Object());
- }
- TestConnectionListener(Object lock)
- {
- this.lock = lock;
- }
- public void handleConnectionException(Throwable throwable, Client client)
- {
- notified = true;
- synchronized (lock)
- {
- try
- {
- // Give listener a chance to wait on lock.
- Thread.sleep(4000);
- }
- catch (InterruptedException e)
- {
- log.info("Unexpected interrupt in TestConnectionListener");
- }
- lock.notifyAll();
- }
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.connection;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimerTask;
+
+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.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit tests for JBREM-891.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jan 19, 2008
+ * </p>
+ */
+public class ConnectionValidatorTiedToLeaseTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionValidatorTiedToLeaseTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener serverListener;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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 testTiedToLeaseDefaultConfigurationLocalInvoker() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ client.addConnectionListener(clientListener);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify LeasePinger is running.
+ assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
+ ClientInvoker clientInvoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
+ assertNotNull(pinger);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ // Shut down lease on server side.
+ connector.removeConnectionListener(serverListener);
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has stopped.
+ Thread.sleep(4000);
+ assertTrue(clientListener.notified);
+ assertEquals(-1, client.getPingPeriod());
+
+ // Verfiy LeasePinger has stopped.
+ timerTask = (TimerTask) field.get(pinger);
+ assertNull(timerTask);
+
+ client.removeConnectionListener(clientListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testTiedToLeaseDefaultConfigurationRemoteInvoker() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ Map metadata = new HashMap();
+ metadata.put(InvokerLocator.FORCE_REMOTE, "true");
+ client.addConnectionListener(clientListener, metadata);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify LeasePinger is running.
+ assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
+ ClientInvoker clientInvoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
+ assertNotNull(pinger);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ // Shut down lease on server side.
+ connector.removeConnectionListener(serverListener);
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has stopped.
+ Thread.sleep(4000);
+ assertTrue(clientListener.notified);
+ assertEquals(-1, client.getPingPeriod());
+
+ // Verfiy LeasePinger has stopped.
+ timerTask = (TimerTask) field.get(pinger);
+ assertNull(timerTask);
+
+ client.removeConnectionListener(clientListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testTiedToLeaseDontStopLease() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ Map metadata = new HashMap();
+ metadata.put(InvokerLocator.FORCE_REMOTE, "true");
+ metadata.put(ConnectionValidator.TIE_TO_LEASE, "true");
+ metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "false");
+ client.addConnectionListener(clientListener, metadata);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify LeasePinger is running.
+ assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
+ ClientInvoker clientInvoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
+ assertNotNull(pinger);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ // Shut down lease on server side.
+ connector.removeConnectionListener(serverListener);
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has stopped.
+ Thread.sleep(4000);
+ assertTrue(clientListener.notified);
+ assertEquals(-1, client.getPingPeriod());
+
+ // Verfiy LeasePinger has not stopped.
+ timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ client.removeConnectionListener(clientListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNotTiedToLeaseDontStopLease() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ Map metadata = new HashMap();
+ metadata.put(InvokerLocator.FORCE_REMOTE, "true");
+ metadata.put(ConnectionValidator.TIE_TO_LEASE, "false");
+ metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "false");
+ client.addConnectionListener(clientListener, metadata);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify LeasePinger is running.
+ assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
+ ClientInvoker clientInvoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
+ assertNotNull(pinger);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ // Shut down lease on server side.
+ connector.removeConnectionListener(serverListener);
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has not stopped.
+ Thread.sleep(4000);
+ assertFalse(clientListener.notified);
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Verfiy LeasePinger has not stopped.
+ timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ client.removeConnectionListener(clientListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNotTiedToLeaseStopLease() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ Map metadata = new HashMap();
+ metadata.put(InvokerLocator.FORCE_REMOTE, "true");
+ metadata.put(ConnectionValidator.TIE_TO_LEASE, "false");
+ metadata.put(ConnectionValidator.STOP_LEASE_ON_FAILURE, "true");
+ client.addConnectionListener(clientListener, metadata);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify LeasePinger is running.
+ assertTrue(client.getInvoker() instanceof MicroRemoteClientInvoker);
+ ClientInvoker clientInvoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(clientInvoker);
+ assertNotNull(pinger);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ assertNotNull(timerTask);
+
+ // Prevent server from responding to ConnectionValidator pings.
+ ServerInvoker serverInvoker = connector.getServerInvoker();
+ field = ServerInvoker.class.getDeclaredField("started");
+ field.setAccessible(true);
+ field.set(serverInvoker, new Boolean(false));
+ assertFalse(field.getBoolean(serverInvoker));
+ log.info("Stopped server invoker");
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has stopped.
+ Thread.sleep(4000);
+ assertTrue(clientListener.notified);
+ assertEquals(-1, client.getPingPeriod());
+
+ // Verfiy LeasePinger has stopped.
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ timerTask = (TimerTask) field.get(pinger);
+ assertNull(timerTask);
+
+ client.removeConnectionListener(clientListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testTiedToLeaseServerLeasingTurnedOff() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ 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");
+
+ // Register client side listener.
+ Object lock = new Object();
+ TestConnectionListener clientListener = new TestConnectionListener(lock);
+ Map metadata = new HashMap();
+ metadata.put(InvokerLocator.FORCE_REMOTE, "true");
+ client.addConnectionListener(clientListener, metadata);
+ log.info("connection listener added on client side");
+
+ // Verify ConnectionValidator is running.
+ assertTrue(client.getPingPeriod() > -1);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Wait for client side listener to be notified.
+ synchronized (lock)
+ {
+ lock.wait(30000);
+ }
+
+ // Verify ConnectionValidator has not stopped.
+ Thread.sleep(4000);
+ assertFalse(clientListener.notified);
+ assertTrue(client.getPingPeriod() > -1);
+
+ client.removeConnectionListener(clientListener);
+ 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 startLeasing) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI += "/?" + InvokerLocator.CLIENT_LEASE + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=4000";
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put(ServerInvoker.CLIENT_LEASE_PERIOD, "4000");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ if (startLeasing)
+ {
+ serverListener = new TestConnectionListener();
+ connector.addConnectionListener(serverListener);
+ }
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ {
+ connector.removeConnectionListener(serverListener);
+ 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 notified;
+ private Object lock;
+
+ TestConnectionListener()
+ {
+ this(new Object());
+ }
+ TestConnectionListener(Object lock)
+ {
+ this.lock = lock;
+ }
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ notified = true;
+ synchronized (lock)
+ {
+ try
+ {
+ // Give listener a chance to wait on lock.
+ Thread.sleep(4000);
+ }
+ catch (InterruptedException e)
+ {
+ log.info("Unexpected interrupt in TestConnectionListener");
+ }
+ lock.notifyAll();
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/ConnectionValidatorTiedToLeaseTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 3 months