JBoss Remoting SVN: r5980 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:03:23 -0400 (Wed, 04 Aug 2010)
New Revision: 5980
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst/ParentFirstClassloaderTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst/ParentFirstClassloaderTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst/ParentFirstClassloaderTestCase.java 2010-08-05 01:02:35 UTC (rev 5979)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst/ParentFirstClassloaderTestCase.java 2010-08-05 01:03:23 UTC (rev 5980)
@@ -1,326 +1,326 @@
-/*
-* 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.classloader.parentfirst;
-
-import java.io.Serializable;
-import java.net.InetAddress;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-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.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-1042.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Aug 3, 2008
- * </p>
- */
-public class ParentFirstClassloaderTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ParentFirstClassloaderTestCase.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()
- {
- }
-
-
- /**
- * Verify that by default the context classloader is not called first.
- */
- public void testDefaultConfig() 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");
-
- TestClassLoader tcl = new TestClassLoader();
- Thread.currentThread().setContextClassLoader(tcl);
-
- // Test connection.
- client.invoke("abc");
- log.info("connection is good");
-
- // Verify that TestClassLoader has not been queried.
- assertFalse(tcl.visited);
- log.info("context classloader has not been queried");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- /**
- * Verify that by the context classloader is called first if
- * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION is set to "true"
- * in the InvokerLocator.
- */
- public void testByInvokerLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION + "=false";
- 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");
-
- TestClassLoader tcl = new TestClassLoader();
- setContextClassLoader(tcl);
-
- // Test connection.
- client.invoke("abc");
- log.info("connection is good");
-
- // Verify that TestClassLoader has been queried.
- assertTrue(tcl.visited);
- log.info("context classloader has been queried");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- /**
- * Verify that by the context classloader is called first if
- * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION is set to "true"
- * in the config map.
- */
- public void testByConfigMap() 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.CLASSLOADING_PARENT_FIRST_DELEGATION, "false");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- TestClassLoader tcl = new TestClassLoader();
- setContextClassLoader(tcl);
-
- // Test connection.
- client.invoke("abc");
- log.info("connection is good");
-
- // Verify that TestClassLoader has been queried.
- assertTrue(tcl.visited);
- log.info("context classloader has been queried");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- /**
- * Verify that by the context classloader is called first if the system property
- * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP is set to "true"
- * in the config map.
- */
- public void testBySystemProperty() 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);
- System.setProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP, "false");
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- TestClassLoader tcl = new TestClassLoader();
- setContextClassLoader(tcl);
-
- // Test connection.
- client.invoke("abc");
- log.info("connection is good");
-
- // Verify that TestClassLoader has been queried.
- assertTrue(tcl.visited);
- log.info("context classloader has been queried");
-
- 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();
- }
-
-
- protected void setContextClassLoader(final ClassLoader classLoader)
- {
- AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- Thread.currentThread().setContextClassLoader(classLoader);
- return null;
- }
- });
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return new TestClass();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class TestClassLoader extends ClassLoader
- {
- boolean visited;
-
- public Class loadClass(String name) throws ClassNotFoundException
- {
- visited = true;
- log.info("TestClassLoader.loadClass(): " + name);
- throw new ClassNotFoundException(name);
- }
- }
-
-
- static class TestClass implements Serializable
- {
- /** The serialVersionUID */
- private static final long serialVersionUID = 1L;
- }
+/*
+* 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.classloader.parentfirst;
+
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+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.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-1042.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Aug 3, 2008
+ * </p>
+ */
+public class ParentFirstClassloaderTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ParentFirstClassloaderTestCase.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()
+ {
+ }
+
+
+ /**
+ * Verify that by default the context classloader is not called first.
+ */
+ public void testDefaultConfig() 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");
+
+ TestClassLoader tcl = new TestClassLoader();
+ Thread.currentThread().setContextClassLoader(tcl);
+
+ // Test connection.
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Verify that TestClassLoader has not been queried.
+ assertFalse(tcl.visited);
+ log.info("context classloader has not been queried");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Verify that by the context classloader is called first if
+ * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION is set to "true"
+ * in the InvokerLocator.
+ */
+ public void testByInvokerLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "/?" + Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION + "=false";
+ 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");
+
+ TestClassLoader tcl = new TestClassLoader();
+ setContextClassLoader(tcl);
+
+ // Test connection.
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Verify that TestClassLoader has been queried.
+ assertTrue(tcl.visited);
+ log.info("context classloader has been queried");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Verify that by the context classloader is called first if
+ * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION is set to "true"
+ * in the config map.
+ */
+ public void testByConfigMap() 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.CLASSLOADING_PARENT_FIRST_DELEGATION, "false");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ TestClassLoader tcl = new TestClassLoader();
+ setContextClassLoader(tcl);
+
+ // Test connection.
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Verify that TestClassLoader has been queried.
+ assertTrue(tcl.visited);
+ log.info("context classloader has been queried");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ /**
+ * Verify that by the context classloader is called first if the system property
+ * org.jboss.remoting.Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP is set to "true"
+ * in the config map.
+ */
+ public void testBySystemProperty() 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);
+ System.setProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP, "false");
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ TestClassLoader tcl = new TestClassLoader();
+ setContextClassLoader(tcl);
+
+ // Test connection.
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Verify that TestClassLoader has been queried.
+ assertTrue(tcl.visited);
+ log.info("context classloader has been queried");
+
+ 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();
+ }
+
+
+ protected void setContextClassLoader(final ClassLoader classLoader)
+ {
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return new TestClass();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestClassLoader extends ClassLoader
+ {
+ boolean visited;
+
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ visited = true;
+ log.info("TestClassLoader.loadClass(): " + name);
+ throw new ClassNotFoundException(name);
+ }
+ }
+
+
+ static class TestClass implements Serializable
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/parentfirst/ParentFirstClassloaderTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5979 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:02:35 -0400 (Wed, 04 Aug 2010)
New Revision: 5979
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/CurrentThreadContextClassLoaderTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass1.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass2.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/CurrentThreadContextClassLoaderTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/CurrentThreadContextClassLoaderTestCase.java 2010-08-05 01:01:06 UTC (rev 5978)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/CurrentThreadContextClassLoaderTestCase.java 2010-08-05 01:02:35 UTC (rev 5979)
@@ -1,374 +1,374 @@
-/*
- * 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.classloader.currentthread;
-
-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.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 tests for JBREM-1127
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright May 10, 2009
- * </p>
- */
-public class CurrentThreadContextClassLoaderTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(CurrentThreadContextClassLoaderTestCase.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 String currentPackage;
- protected ClassLoader mainContextClassLoader;
- protected TestClassLoader testClassLoader1;
- protected TestClassLoader testClassLoader2;
- protected TestCallingThread testCallingThread;
-
-
- 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);
- }
-
- String className = getClass().getName();
- int index = className.lastIndexOf('.');
- currentPackage = className.substring(0, index);
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- mainContextClassLoader = Thread.currentThread().getContextClassLoader();
-
- // Create testClassLoader1 for testCallingThread.
- testClassLoader1 = new TestClassLoader("testClassLoader1");
-
- // Create testClassLoader2 for main thread.
- testClassLoader2 = new TestClassLoader("testClassLoader2");
-
- // 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");
-
- // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
- TestCallingThread t = new TestCallingThread(client);
- t.run();
- synchronized (t)
- {
- if (!t.done)
- {
- t.wait();
- }
- }
-
- // Make invocation in main thread with context classloader testClassLoader2.
- testClassLoader2.setClassLoader(mainContextClassLoader);
- Thread.currentThread().setContextClassLoader(testClassLoader2);
- log.info("main thread result: " + client.invoke("2"));
- assertTrue(testClassLoader1.counter > 0);
- assertTrue(testClassLoader2.counter == 0);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseCurrentThreadClassLoaderFalse() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- mainContextClassLoader = Thread.currentThread().getContextClassLoader();
-
- // Create testClassLoader1 for testCallingThread.
- testClassLoader1 = new TestClassLoader("testClassLoader1");
-
- // Create testClassLoader2 for main thread.
- testClassLoader2 = new TestClassLoader("testClassLoader2");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.USE_CURRENT_THREAD_CLASS_LOADER, "false");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
- TestCallingThread t = new TestCallingThread(client);
- t.run();
- synchronized (t)
- {
- if (!t.done)
- {
- t.wait();
- }
- }
-
- // Make invocation in main thread with context classloader testClassLoader2.
- testClassLoader2.setClassLoader(mainContextClassLoader);
- Thread.currentThread().setContextClassLoader(testClassLoader2);
- log.info("main thread result: " + client.invoke("2"));
- assertTrue(testClassLoader1.counter > 0);
- assertTrue(testClassLoader2.counter == 0);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseCurrentThreadClassLoaderTrue() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- mainContextClassLoader = Thread.currentThread().getContextClassLoader();
-
- // Create testClassLoader1 for testCallingThread.
- testClassLoader1 = new TestClassLoader("testClassLoader1");
-
- // Create testClassLoader2 for main thread.
- testClassLoader2 = new TestClassLoader("testClassLoader2");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.USE_CURRENT_THREAD_CLASS_LOADER, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
- TestCallingThread t = new TestCallingThread(client);
- t.run();
- synchronized (t)
- {
- if (!t.done)
- {
- t.wait();
- }
- }
-
- // Make invocation in main thread with context classloader testClassLoader2.
- testClassLoader2.setClassLoader(mainContextClassLoader);
- Thread.currentThread().setContextClassLoader(testClassLoader2);
- log.info("main thread result: " + client.invoke("2"));
- assertTrue(testClassLoader1.counter > 0);
- assertTrue(testClassLoader2.counter > 0);
-
- 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;
- locatorURI += "/?" + Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION + "=false";
- 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();
- }
-
-
- class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- Object o = invocation.getParameter();
- if ("1".equals(o))
- {
- return Class.forName(currentPackage + ".TestClass1").newInstance();
- }
- else if ("2".equals(o))
- {
- return Class.forName(currentPackage + ".TestClass2").newInstance();
- }
- else
- {
- throw new Exception("unexpected request: " + o);
- }
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- class TestCallingThread extends Thread
- {
- Client client;
- boolean done;
-
- public TestCallingThread(Client client)
- {
- this.client = client;
- }
-
- public void run()
- {
- try
- {
- // Make testClassloader1 the context classloader for this TestCallingThread.
- testClassLoader1.setClassLoader(mainContextClassLoader);
- Thread.currentThread().setContextClassLoader(testClassLoader1);
- log.info("TestCallingThread result: " + client.invoke("1"));
- synchronized (this)
- {
- done = true;
- notifyAll();
- }
- }
- catch (Throwable e)
- {
- log.error("Error", e);
- }
- }
- }
-
-
- static class TestClassLoader extends ClassLoader
- {
- ClassLoader cl;
- String name;
- int counter;
-
- public TestClassLoader(String name)
- {
- this.name = name;
- }
-
- public Class loadClass(String name) throws ClassNotFoundException
- {
- counter++;
- log.info(this + " called: " + name);
-// log.info(this + " called: " + name, new Exception());
- return cl.loadClass(name);
- }
-
- public void setClassLoader(ClassLoader cl)
- {
- this.cl = cl;
- }
-
- public String toString()
- {
- return 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.classloader.currentthread;
+
+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.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 tests for JBREM-1127
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright May 10, 2009
+ * </p>
+ */
+public class CurrentThreadContextClassLoaderTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(CurrentThreadContextClassLoaderTestCase.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 String currentPackage;
+ protected ClassLoader mainContextClassLoader;
+ protected TestClassLoader testClassLoader1;
+ protected TestClassLoader testClassLoader2;
+ protected TestCallingThread testCallingThread;
+
+
+ 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);
+ }
+
+ String className = getClass().getName();
+ int index = className.lastIndexOf('.');
+ currentPackage = className.substring(0, index);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ mainContextClassLoader = Thread.currentThread().getContextClassLoader();
+
+ // Create testClassLoader1 for testCallingThread.
+ testClassLoader1 = new TestClassLoader("testClassLoader1");
+
+ // Create testClassLoader2 for main thread.
+ testClassLoader2 = new TestClassLoader("testClassLoader2");
+
+ // 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");
+
+ // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
+ TestCallingThread t = new TestCallingThread(client);
+ t.run();
+ synchronized (t)
+ {
+ if (!t.done)
+ {
+ t.wait();
+ }
+ }
+
+ // Make invocation in main thread with context classloader testClassLoader2.
+ testClassLoader2.setClassLoader(mainContextClassLoader);
+ Thread.currentThread().setContextClassLoader(testClassLoader2);
+ log.info("main thread result: " + client.invoke("2"));
+ assertTrue(testClassLoader1.counter > 0);
+ assertTrue(testClassLoader2.counter == 0);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseCurrentThreadClassLoaderFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ mainContextClassLoader = Thread.currentThread().getContextClassLoader();
+
+ // Create testClassLoader1 for testCallingThread.
+ testClassLoader1 = new TestClassLoader("testClassLoader1");
+
+ // Create testClassLoader2 for main thread.
+ testClassLoader2 = new TestClassLoader("testClassLoader2");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.USE_CURRENT_THREAD_CLASS_LOADER, "false");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
+ TestCallingThread t = new TestCallingThread(client);
+ t.run();
+ synchronized (t)
+ {
+ if (!t.done)
+ {
+ t.wait();
+ }
+ }
+
+ // Make invocation in main thread with context classloader testClassLoader2.
+ testClassLoader2.setClassLoader(mainContextClassLoader);
+ Thread.currentThread().setContextClassLoader(testClassLoader2);
+ log.info("main thread result: " + client.invoke("2"));
+ assertTrue(testClassLoader1.counter > 0);
+ assertTrue(testClassLoader2.counter == 0);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseCurrentThreadClassLoaderTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ mainContextClassLoader = Thread.currentThread().getContextClassLoader();
+
+ // Create testClassLoader1 for testCallingThread.
+ testClassLoader1 = new TestClassLoader("testClassLoader1");
+
+ // Create testClassLoader2 for main thread.
+ testClassLoader2 = new TestClassLoader("testClassLoader2");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.USE_CURRENT_THREAD_CLASS_LOADER, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Make invocation, creating unmarshaller with testClassLoader1, in separate thread.
+ TestCallingThread t = new TestCallingThread(client);
+ t.run();
+ synchronized (t)
+ {
+ if (!t.done)
+ {
+ t.wait();
+ }
+ }
+
+ // Make invocation in main thread with context classloader testClassLoader2.
+ testClassLoader2.setClassLoader(mainContextClassLoader);
+ Thread.currentThread().setContextClassLoader(testClassLoader2);
+ log.info("main thread result: " + client.invoke("2"));
+ assertTrue(testClassLoader1.counter > 0);
+ assertTrue(testClassLoader2.counter > 0);
+
+ 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;
+ locatorURI += "/?" + Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION + "=false";
+ 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();
+ }
+
+
+ class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ Object o = invocation.getParameter();
+ if ("1".equals(o))
+ {
+ return Class.forName(currentPackage + ".TestClass1").newInstance();
+ }
+ else if ("2".equals(o))
+ {
+ return Class.forName(currentPackage + ".TestClass2").newInstance();
+ }
+ else
+ {
+ throw new Exception("unexpected request: " + o);
+ }
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ class TestCallingThread extends Thread
+ {
+ Client client;
+ boolean done;
+
+ public TestCallingThread(Client client)
+ {
+ this.client = client;
+ }
+
+ public void run()
+ {
+ try
+ {
+ // Make testClassloader1 the context classloader for this TestCallingThread.
+ testClassLoader1.setClassLoader(mainContextClassLoader);
+ Thread.currentThread().setContextClassLoader(testClassLoader1);
+ log.info("TestCallingThread result: " + client.invoke("1"));
+ synchronized (this)
+ {
+ done = true;
+ notifyAll();
+ }
+ }
+ catch (Throwable e)
+ {
+ log.error("Error", e);
+ }
+ }
+ }
+
+
+ static class TestClassLoader extends ClassLoader
+ {
+ ClassLoader cl;
+ String name;
+ int counter;
+
+ public TestClassLoader(String name)
+ {
+ this.name = name;
+ }
+
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ counter++;
+ log.info(this + " called: " + name);
+// log.info(this + " called: " + name, new Exception());
+ return cl.loadClass(name);
+ }
+
+ public void setClassLoader(ClassLoader cl)
+ {
+ this.cl = cl;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/CurrentThreadContextClassLoaderTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass1.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass1.java 2010-08-05 01:01:06 UTC (rev 5978)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass1.java 2010-08-05 01:02:35 UTC (rev 5979)
@@ -1,30 +1,30 @@
-/*
- * 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.classloader.currentthread;
-
-import java.io.Serializable;
-
-public class TestClass1 implements Serializable
-{
- private static final long serialVersionUID = 1L;
-}
-
+/*
+ * 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.classloader.currentthread;
+
+import java.io.Serializable;
+
+public class TestClass1 implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+}
+
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass1.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass2.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass2.java 2010-08-05 01:01:06 UTC (rev 5978)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass2.java 2010-08-05 01:02:35 UTC (rev 5979)
@@ -1,30 +1,30 @@
-/*
- * 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.classloader.currentthread;
-
-import java.io.Serializable;
-
-public class TestClass2 implements Serializable
-{
- private static final long serialVersionUID = 1L;
-}
-
+/*
+ * 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.classloader.currentthread;
+
+import java.io.Serializable;
+
+public class TestClass2 implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+}
+
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/currentthread/TestClass2.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5978 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 21:01:06 -0400 (Wed, 04 Aug 2010)
New Revision: 5978
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/RemoteClassloaderTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/RemoteClassloaderTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/RemoteClassloaderTestCase.java 2010-08-05 00:59:48 UTC (rev 5977)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/RemoteClassloaderTestCase.java 2010-08-05 01:01:06 UTC (rev 5978)
@@ -1,224 +1,224 @@
-/*
- * 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.classloader;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.List;
-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.InvokerCallbackHandler;
-import org.jboss.remoting.loading.ClassByteClassLoader;
-import org.jboss.remoting.loading.ClassBytes;
-import org.jboss.remoting.marshal.MarshallLoaderFactory;
-import org.jboss.remoting.marshal.MarshallerLoaderConstants;
-import org.jboss.remoting.marshal.MarshallerLoaderHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit test for JBREM-1184.
- *
- * Note that testClassNotFound() passes even in the presence of the NullPointerException
- * described in JBREM-1184, so it's not really a regression test. However, I'm committing
- * the test for its documentation value. The NPE should not be seen in the log file.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Feb 15, 2010
- */
-public class RemoteClassloaderTestCase extends TestCase
-{
- private ByteArrayOutputStream baos;
- private PrintStream originalPrintStream;
- private Logger log;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- 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.DEBUG);
- 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(RemoteClassloaderTestCase.class);
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testClassNotFound() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- TestClassLoader tcl = new TestClassLoader();
- InvokerLocator loaderLocator = MarshallLoaderFactory.convertLocator(serverLocator);
- tcl.setClientInvoker(new Client(loaderLocator));
-
- try
- {
- tcl.findClass("a.b.c");
- fail("expected ClassNotFoundException");
- }
- catch (ClassNotFoundException e)
- {
- log.info("got expected ClassNotFoundException");
- }
- catch (Throwable t)
- {
- fail("expected ClassNotFoundException: got " + t);
- }
-
- System.setOut(originalPrintStream);
- String s = new String(baos.toByteArray());
- System.out.println(s);
- assertTrue(s.indexOf("java.lang.NullPointerException") == -1);
- assertTrue(s.indexOf("Can not load remote class bytes: server returned null class") >= 0);
-
- 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;
- locatorURI += "/?loaderport=4873";
- 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();
-
- // Install TestMarshallerLoaderHandler.
- Field field = Connector.class.getDeclaredField("marshallerLoaderConnector");
- field.setAccessible(true);
- Connector marshallerLoaderConnector = (Connector) field.get(connector);
- MarshallerLoaderHandler loader = new TestMarshallerLoaderHandler(null);
- marshallerLoaderConnector.addInvocationHandler("loader", loader);
- }
-
-
- 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 TestMarshallerLoaderHandler extends MarshallerLoaderHandler
- {
- public TestMarshallerLoaderHandler(List repositories)
- {
- super(repositories);
- }
-
- public Object invoke(InvocationRequest invocation) throws Throwable
- {
- Map metadMap = invocation.getRequestPayload();
- String className = (String) metadMap.get(MarshallerLoaderConstants.CLASSNAME);
- return new ClassBytes(className, null);
- }
- }
-
-
- static class TestClassLoader extends ClassByteClassLoader
- {
- public Class findClass(String name) throws ClassNotFoundException
- {
- return super.findClass(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.classloader;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.List;
+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.InvokerCallbackHandler;
+import org.jboss.remoting.loading.ClassByteClassLoader;
+import org.jboss.remoting.loading.ClassBytes;
+import org.jboss.remoting.marshal.MarshallLoaderFactory;
+import org.jboss.remoting.marshal.MarshallerLoaderConstants;
+import org.jboss.remoting.marshal.MarshallerLoaderHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1184.
+ *
+ * Note that testClassNotFound() passes even in the presence of the NullPointerException
+ * described in JBREM-1184, so it's not really a regression test. However, I'm committing
+ * the test for its documentation value. The NPE should not be seen in the log file.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 15, 2010
+ */
+public class RemoteClassloaderTestCase extends TestCase
+{
+ private ByteArrayOutputStream baos;
+ private PrintStream originalPrintStream;
+ private Logger log;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ 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.DEBUG);
+ 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(RemoteClassloaderTestCase.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testClassNotFound() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ TestClassLoader tcl = new TestClassLoader();
+ InvokerLocator loaderLocator = MarshallLoaderFactory.convertLocator(serverLocator);
+ tcl.setClientInvoker(new Client(loaderLocator));
+
+ try
+ {
+ tcl.findClass("a.b.c");
+ fail("expected ClassNotFoundException");
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.info("got expected ClassNotFoundException");
+ }
+ catch (Throwable t)
+ {
+ fail("expected ClassNotFoundException: got " + t);
+ }
+
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("java.lang.NullPointerException") == -1);
+ assertTrue(s.indexOf("Can not load remote class bytes: server returned null class") >= 0);
+
+ 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;
+ locatorURI += "/?loaderport=4873";
+ 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();
+
+ // Install TestMarshallerLoaderHandler.
+ Field field = Connector.class.getDeclaredField("marshallerLoaderConnector");
+ field.setAccessible(true);
+ Connector marshallerLoaderConnector = (Connector) field.get(connector);
+ MarshallerLoaderHandler loader = new TestMarshallerLoaderHandler(null);
+ marshallerLoaderConnector.addInvocationHandler("loader", loader);
+ }
+
+
+ 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 TestMarshallerLoaderHandler extends MarshallerLoaderHandler
+ {
+ public TestMarshallerLoaderHandler(List repositories)
+ {
+ super(repositories);
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ Map metadMap = invocation.getRequestPayload();
+ String className = (String) metadMap.get(MarshallerLoaderConstants.CLASSNAME);
+ return new ClassBytes(className, null);
+ }
+ }
+
+
+ static class TestClassLoader extends ClassByteClassLoader
+ {
+ public Class findClass(String name) throws ClassNotFoundException
+ {
+ return super.findClass(name);
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/classloader/RemoteClassloaderTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5977 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/store/blocking.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:59:48 -0400 (Wed, 04 Aug 2010)
New Revision: 5977
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/store/blocking/BlockingStoreDeadlockTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/store/blocking/BlockingStoreDeadlockTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/store/blocking/BlockingStoreDeadlockTestCase.java 2010-08-05 00:58:26 UTC (rev 5976)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/store/blocking/BlockingStoreDeadlockTestCase.java 2010-08-05 00:59:48 UTC (rev 5977)
@@ -1,216 +1,216 @@
-package org.jboss.test.remoting.callback.store.blocking;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-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.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.callback.ServerInvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-public class BlockingStoreDeadlockTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(BlockingStoreDeadlockTestCase.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 testForDeadlock() 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 connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Add callback handler.
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- client.addListener(callbackHandler);
- log.info("callback handler added");
-
- // Get callback.
- log.info("client getting callback");
- HashMap metadata = new HashMap();
- metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
- List callbacks = client.getCallbacks(callbackHandler, metadata);
- assertEquals(1, callbacks.size());
- log.info("got callback");
-
- client.removeListener(callbackHandler);
- 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");
- config.put(ServerInvokerCallbackHandler.CALLBACK_MEM_CEILING, "100");
- config.put(ServerInvokerCallbackHandler.CALLBACK_STORE_KEY, "org.jboss.remoting.callback.BlockingCallbackStore");
- 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
- {
- InvokerCallbackHandler handler;
-
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- handler = callbackHandler;
- Runtime runtime = Runtime.getRuntime();
- long max = 0;
- long total = 0;
-// long free = runtime.freeMemory();
-// float percentage = 100 * free / total;
-// if(max == total && memPercentCeiling >= percentage)
-
- ArrayList list = new ArrayList();
- do
- {
- try
- {
- list.add(new Byte[1000000]);
- max = runtime.maxMemory();
- total = runtime.totalMemory();
- log.info("max = " + max + ", total = " + total);
- }
- catch (OutOfMemoryError e)
- {
- log.info("heap space is full");
- break;
- }
- }
- while (max != total);
- log.info("heap is full");
- log.info("thread: " + Thread.currentThread().getName());
- new Thread()
- {
- public void run()
- {
- try
- {
- log.info("thread: " + Thread.currentThread().getName());
- log.info("adding callback");
- handler.handleCallback(new Callback("callback"));
- log.info("added callback");
- }
- catch (HandleCallbackException e)
- {
- log.error("Error", e);
- }
- }
- }.start();
- log.info("server added callback handler");
- }
- 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");
- }
- }
+package org.jboss.test.remoting.callback.store.blocking;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+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.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.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+public class BlockingStoreDeadlockTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(BlockingStoreDeadlockTestCase.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 testForDeadlock() 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 connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Add callback handler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler);
+ log.info("callback handler added");
+
+ // Get callback.
+ log.info("client getting callback");
+ HashMap metadata = new HashMap();
+ metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
+ List callbacks = client.getCallbacks(callbackHandler, metadata);
+ assertEquals(1, callbacks.size());
+ log.info("got callback");
+
+ client.removeListener(callbackHandler);
+ 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");
+ config.put(ServerInvokerCallbackHandler.CALLBACK_MEM_CEILING, "100");
+ config.put(ServerInvokerCallbackHandler.CALLBACK_STORE_KEY, "org.jboss.remoting.callback.BlockingCallbackStore");
+ 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
+ {
+ InvokerCallbackHandler handler;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ handler = callbackHandler;
+ Runtime runtime = Runtime.getRuntime();
+ long max = 0;
+ long total = 0;
+// long free = runtime.freeMemory();
+// float percentage = 100 * free / total;
+// if(max == total && memPercentCeiling >= percentage)
+
+ ArrayList list = new ArrayList();
+ do
+ {
+ try
+ {
+ list.add(new Byte[1000000]);
+ max = runtime.maxMemory();
+ total = runtime.totalMemory();
+ log.info("max = " + max + ", total = " + total);
+ }
+ catch (OutOfMemoryError e)
+ {
+ log.info("heap space is full");
+ break;
+ }
+ }
+ while (max != total);
+ log.info("heap is full");
+ log.info("thread: " + Thread.currentThread().getName());
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ log.info("thread: " + Thread.currentThread().getName());
+ log.info("adding callback");
+ handler.handleCallback(new Callback("callback"));
+ log.info("added callback");
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Error", e);
+ }
+ }
+ }.start();
+ log.info("server added callback handler");
+ }
+ 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/callback/store/blocking/BlockingStoreDeadlockTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5976 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/params.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:58:26 -0400 (Wed, 04 Aug 2010)
New Revision: 5976
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/params/UseAllParamsTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/params/UseAllParamsTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/params/UseAllParamsTestCase.java 2010-08-05 00:56:43 UTC (rev 5975)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/params/UseAllParamsTestCase.java 2010-08-05 00:58:26 UTC (rev 5976)
@@ -1,465 +1,465 @@
-/*
- * 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.callback.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.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.CallbackPoller;
-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-1084.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Jan 17, 2009
- * </p>
- */
-public class UseAllParamsTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(UseAllParamsTestCase.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 testUseAllParamsDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsFalseinLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222&useAllParams=false";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsFalseinConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsFalseinMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- metadata.put(Client.USE_ALL_PARAMS, "false");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsTrueInLocator() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222&useAllParams=true";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, true, 333, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsTrueInConfig() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, true, 333, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testUseAllParamsTrueInMetadata() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("callbackPollPeriod", "333");
- clientConfig.put("maxErrorCount", "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 callback polling.
- TestCallbackHandler handler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- metadata.put("maxErrorCount", "555");
- metadata.put(Client.USE_ALL_PARAMS, "true");
- client.addListener(handler, metadata);
-
- // Test setting of parameters in CallbackPoller.
- testParameters(client, true, 333, 555);
-
- client.removeListener(handler);
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected void testParameters(Client client,
- boolean blockingExpected,
- long callbackPollPeriodExpected,
- int maxErrorCountExpected)
- throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
- {
- Field field = Client.class.getDeclaredField("callbackPollers");
- field.setAccessible(true);
- Map pollers = (Map) field.get(client);
- assertEquals(1, pollers.size());
- CallbackPoller poller = (CallbackPoller) pollers.values().iterator().next();
- field = CallbackPoller.class.getDeclaredField("blocking");
- field.setAccessible(true);
- boolean blocking = ((Boolean)field.get(poller)).booleanValue();
- field = CallbackPoller.class.getDeclaredField("pollPeriod");
- field.setAccessible(true);
- long callbackPollPeriod = ((Long) field.get(poller)).longValue();
- field = CallbackPoller.class.getDeclaredField("maxErrorCount");
- field.setAccessible(true);
- int maxErrorCount = ((Integer) field.get(poller)).intValue();
- log.info("blocking: " + blocking);
- log.info("callbackPollPeriod: " + callbackPollPeriod);
- log.info("maxErrorCount: " + maxErrorCount);
- assertEquals(blockingExpected, blocking);
- assertEquals(callbackPollPeriodExpected, callbackPollPeriod);
- assertEquals(maxErrorCountExpected, maxErrorCount);
- }
-
-
- 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 TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+ * 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.callback.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.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.CallbackPoller;
+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-1084.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Jan 17, 2009
+ * </p>
+ */
+public class UseAllParamsTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(UseAllParamsTestCase.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 testUseAllParamsDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsFalseinLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222&useAllParams=false";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsFalseinConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsFalseinMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ metadata.put(Client.USE_ALL_PARAMS, "false");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, false, CallbackPoller.DEFAULT_POLL_PERIOD, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsTrueInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222&useAllParams=true";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, true, 333, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsTrueInConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, true, 333, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllParamsTrueInMetadata() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI + "&blockingMode=blocking&callbackPollPeriod=111&maxErrorCount=222";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("callbackPollPeriod", "333");
+ clientConfig.put("maxErrorCount", "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 callback polling.
+ TestCallbackHandler handler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put("maxErrorCount", "555");
+ metadata.put(Client.USE_ALL_PARAMS, "true");
+ client.addListener(handler, metadata);
+
+ // Test setting of parameters in CallbackPoller.
+ testParameters(client, true, 333, 555);
+
+ client.removeListener(handler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void testParameters(Client client,
+ boolean blockingExpected,
+ long callbackPollPeriodExpected,
+ int maxErrorCountExpected)
+ throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
+ {
+ Field field = Client.class.getDeclaredField("callbackPollers");
+ field.setAccessible(true);
+ Map pollers = (Map) field.get(client);
+ assertEquals(1, pollers.size());
+ CallbackPoller poller = (CallbackPoller) pollers.values().iterator().next();
+ field = CallbackPoller.class.getDeclaredField("blocking");
+ field.setAccessible(true);
+ boolean blocking = ((Boolean)field.get(poller)).booleanValue();
+ field = CallbackPoller.class.getDeclaredField("pollPeriod");
+ field.setAccessible(true);
+ long callbackPollPeriod = ((Long) field.get(poller)).longValue();
+ field = CallbackPoller.class.getDeclaredField("maxErrorCount");
+ field.setAccessible(true);
+ int maxErrorCount = ((Integer) field.get(poller)).intValue();
+ log.info("blocking: " + blocking);
+ log.info("callbackPollPeriod: " + callbackPollPeriod);
+ log.info("maxErrorCount: " + maxErrorCount);
+ assertEquals(blockingExpected, blocking);
+ assertEquals(callbackPollPeriodExpected, callbackPollPeriod);
+ assertEquals(maxErrorCountExpected, maxErrorCount);
+ }
+
+
+ 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 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/callback/params/UseAllParamsTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5975 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:56:43 -0400 (Wed, 04 Aug 2010)
New Revision: 5975
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java 2010-08-05 00:54:59 UTC (rev 5974)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java 2010-08-05 00:56:43 UTC (rev 5975)
@@ -1,279 +1,279 @@
-/*
- * 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.callback.leak;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-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.remoting.Client;
-import org.jboss.remoting.ConnectionListener;
-import org.jboss.remoting.ConnectionNotifier;
-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.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit tests for JBREM-1119.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Apr 13, 2009
- * </p>
- */
-public class ServerInvokerCallbackHandlerLeakTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ServerInvokerCallbackHandlerLeakTestCase.class);
-
- private static boolean firstTime = true;
- private static int COUNT = 10;
- private static Object lock = new Object();
-
- 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);
- }
- TestConnectionListener.count = 0;
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testLeakWithCallbackHandlersListening() throws Throwable
- {
- doLeakTest(true);
- }
-
-
- public void testLeakWithoutCallbackHandlersListening() throws Throwable
- {
- doLeakTest(false);
- }
-
-
- public void doLeakTest(boolean registerCallbackListener) throws Throwable
- {
- log.info("entering " + getName());
- setupServer(registerCallbackListener);
-
- // Get fields.
- ServerInvoker serverInvoker = connector.getServerInvoker();
- Field field = ServerInvoker.class.getDeclaredField("connectionNotifier");
- field.setAccessible(true);
- ConnectionNotifier connectionNotifier = (ConnectionNotifier) field.get(serverInvoker);
- field = ServerInvoker.class.getDeclaredField("callbackHandlers");
- field.setAccessible(true);
- Map callbackHandlers = (Map) field.get(serverInvoker);
-
- // Create client.
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = null;
-
- for (int i = 0; i < COUNT; i++)
- {
- client = new Client(serverLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- client.addListener(callbackHandler, null, null, true);
- }
-
- field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(client.getInvoker());
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- timerTask.cancel();
-
- synchronized(lock)
- {
- lock.wait();
- }
- Thread.sleep(2000);
-
- assertEquals(COUNT, TestConnectionListener.count);
- assertEquals(1, connectionNotifier.size());
- assertTrue(callbackHandlers.isEmpty());
-
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(boolean registerCallbackListener) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- locatorURI += "/?leasing=true";
- if (registerCallbackListener)
- {
- locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=true";
- }
- else
- {
- locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=false";
- }
- 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();
- connector.setLeasePeriod(2000);
- TestConnectionListener listener = new TestConnectionListener(!registerCallbackListener);
- connector.addConnectionListener(listener);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- static public Set callbackHandlers = new HashSet();
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- callbackHandlers.add(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");
- }
- }
-
-
- static class TestConnectionListener implements ConnectionListener
- {
- static public int count;
- boolean shutdownCallbackHandlers;
-
- public TestConnectionListener(boolean shutdownCallbackHandlers)
- {
- this.shutdownCallbackHandlers = shutdownCallbackHandlers;
- }
-
- public synchronized void handleConnectionException(Throwable throwable, Client client)
- {
- log.info("got connection exception");
- if(++count == COUNT)
- {
- if (shutdownCallbackHandlers)
- {
- Iterator it = TestInvocationHandler.callbackHandlers.iterator();
- while (it.hasNext())
- {
- ServerInvokerCallbackHandler callbackHandler = (ServerInvokerCallbackHandler) it.next();
- callbackHandler.shutdown();
- log.info("shut down: " + callbackHandler);
- }
- TestInvocationHandler.callbackHandlers.clear();
- }
- synchronized(lock)
- {
- lock.notify();
- }
- }
- }
- }
+/*
+ * 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.callback.leak;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+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.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionNotifier;
+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.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit tests for JBREM-1119.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 13, 2009
+ * </p>
+ */
+public class ServerInvokerCallbackHandlerLeakTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerInvokerCallbackHandlerLeakTestCase.class);
+
+ private static boolean firstTime = true;
+ private static int COUNT = 10;
+ private static Object lock = new Object();
+
+ 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);
+ }
+ TestConnectionListener.count = 0;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testLeakWithCallbackHandlersListening() throws Throwable
+ {
+ doLeakTest(true);
+ }
+
+
+ public void testLeakWithoutCallbackHandlersListening() throws Throwable
+ {
+ doLeakTest(false);
+ }
+
+
+ public void doLeakTest(boolean registerCallbackListener) throws Throwable
+ {
+ log.info("entering " + getName());
+ setupServer(registerCallbackListener);
+
+ // Get fields.
+ ServerInvoker serverInvoker = connector.getServerInvoker();
+ Field field = ServerInvoker.class.getDeclaredField("connectionNotifier");
+ field.setAccessible(true);
+ ConnectionNotifier connectionNotifier = (ConnectionNotifier) field.get(serverInvoker);
+ field = ServerInvoker.class.getDeclaredField("callbackHandlers");
+ field.setAccessible(true);
+ Map callbackHandlers = (Map) field.get(serverInvoker);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = null;
+
+ for (int i = 0; i < COUNT; i++)
+ {
+ client = new Client(serverLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, null, null, true);
+ }
+
+ field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(client.getInvoker());
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ timerTask.cancel();
+
+ synchronized(lock)
+ {
+ lock.wait();
+ }
+ Thread.sleep(2000);
+
+ assertEquals(COUNT, TestConnectionListener.count);
+ assertEquals(1, connectionNotifier.size());
+ assertTrue(callbackHandlers.isEmpty());
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean registerCallbackListener) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI += "/?leasing=true";
+ if (registerCallbackListener)
+ {
+ locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=true";
+ }
+ else
+ {
+ locatorURI += "&" + ServerInvoker.REGISTER_CALLBACK_LISTENER + "=false";
+ }
+ 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();
+ connector.setLeasePeriod(2000);
+ TestConnectionListener listener = new TestConnectionListener(!registerCallbackListener);
+ connector.addConnectionListener(listener);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ static public Set callbackHandlers = new HashSet();
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ callbackHandlers.add(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");
+ }
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ static public int count;
+ boolean shutdownCallbackHandlers;
+
+ public TestConnectionListener(boolean shutdownCallbackHandlers)
+ {
+ this.shutdownCallbackHandlers = shutdownCallbackHandlers;
+ }
+
+ public synchronized void handleConnectionException(Throwable throwable, Client client)
+ {
+ log.info("got connection exception");
+ if(++count == COUNT)
+ {
+ if (shutdownCallbackHandlers)
+ {
+ Iterator it = TestInvocationHandler.callbackHandlers.iterator();
+ while (it.hasNext())
+ {
+ ServerInvokerCallbackHandler callbackHandler = (ServerInvokerCallbackHandler) it.next();
+ callbackHandler.shutdown();
+ log.info("shut down: " + callbackHandler);
+ }
+ TestInvocationHandler.callbackHandlers.clear();
+ }
+ synchronized(lock)
+ {
+ lock.notify();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/leak/ServerInvokerCallbackHandlerLeakTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5974 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:54:59 -0400 (Wed, 04 Aug 2010)
New Revision: 5974
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure/CallbackConnectionFailureTestParent.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure/CallbackConnectionFailureTestParent.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure/CallbackConnectionFailureTestParent.java 2010-08-05 00:53:35 UTC (rev 5973)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure/CallbackConnectionFailureTestParent.java 2010-08-05 00:54:59 UTC (rev 5974)
@@ -1,373 +1,373 @@
-/*
-* 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.callback.connectionfailure;
-
-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.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.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- *
- * Parent of unit tests for JBREM-873.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Dec 10, 2007
- * </p>
- */
-abstract public class CallbackConnectionFailureTestParent extends TestCase
-{
- private static Logger log = Logger.getLogger(CallbackConnectionFailureTestParent.class);
-
- private static boolean firstTime = true;
- private static String CALLBACK = "callback";
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
- protected TestConnectionListener connectionListener;
-
-
- 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 testCallbackConnectionFailureWithListener() throws Throwable
- {
- log.info("entering " + getName());
- doTest(true);
- log.info(getName() + " PASSES");
- }
-
-
- public void testCallbackConnectionFailureWithoutListener() throws Throwable
- {
- log.info("entering " + getName());
- doTest(false);
- log.info(getName() + " PASSES");
- }
-
-
- public void testCallbackConnectionFailureTwoClients() throws Throwable
- {
- // Start server.
- setupServer(true, 2);
-
- // Create clients.
- InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("enableLease", "true");
-
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator1, clientConfig);
- client1.connect();
- log.info("client1 is connected: " + client1.getSessionId());
- // Force the Clients to use distinct invokers.
- InvokerLocator clientLocator2 = new InvokerLocator(locatorURI + "/?a=b");
- Client client2 = new Client(clientLocator2, clientConfig);
- client2.connect();
- log.info("client2 is connected: " + client2.getSessionId());
- assertNotSame(client1.getInvoker(), client2.getInvoker());
-
- // Test connections.
- assertEquals("abc", client1.invoke("abc"));
- assertEquals("xyz", client1.invoke("xyz"));
- log.info("connections are good");
-
- // Add callback handlers.
- TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
- Map metadata = new HashMap();
- addExtraCallbackMetadata(metadata);
- int callbackPort = PortUtil.findFreePort(host);
- metadata.put(Client.CALLBACK_SERVER_PORT, Integer.toString(callbackPort));
- client1.addListener(callbackHandler1, metadata, null, true);
- client1.invoke(CALLBACK);
- assertEquals(1, callbackHandler1.count);
- log.info("first callback handler is installed");
-
- TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
- callbackPort = PortUtil.findFreePort(host);
- metadata.put(Client.CALLBACK_SERVER_PORT, Integer.toString(callbackPort));
- client2.addListener(callbackHandler2, metadata, null, true);
- client2.invoke(CALLBACK);
- assertEquals(2, callbackHandler1.count);
- assertEquals(1, callbackHandler2.count);
- log.info("second callback handler is installed");
-
- // Verify that first callback Client is disconnected when lease fails,
- // but second callback Client is not disconnected.
-
- // 1. Kill LeasePinger for Client 1.
- ClientInvoker invoker = client1.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(invoker);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- timerTask.cancel();
- log.info("stopped LeasePinger");
-
- // 2. Verify that first callback Client is disconnected.
- TestInvocationHandler2 tih = (TestInvocationHandler2) invocationHandler;
- ServerInvokerCallbackHandler sich1 = tih.callbackHandlers[0];
- Client callbackClient1 = sich1.getCallbackClient();
- Thread.sleep(12000);
- assertFalse(callbackClient1.isConnected());
- log.info("first callback Client is disconnected");
-
- // 2. Verify that second callback Client is not disconnected.
- ServerInvokerCallbackHandler sich2 = tih.callbackHandlers[1];
- Client callbackClient2 = sich2.getCallbackClient();
- assertTrue(callbackClient2.isConnected());
- log.info("second callback Client is connected");
-
- client1.removeListener(callbackHandler1);
- client1.disconnect();
- client2.removeListener(callbackHandler1);
- client2.disconnect();
- shutdownServer();
- }
-
-
- protected void doTest(boolean registerAsListener) throws Throwable
- {
- // Start server.
- setupServer(registerAsListener, 1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("enableLease", "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");
-
- // Add callback handler.
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- Map metadata = new HashMap();
- addExtraCallbackMetadata(metadata);
- client.addListener(callbackHandler, metadata, null, true);
- client.invoke(CALLBACK);
- assertEquals(1, callbackHandler.count);
- log.info("callback handler is installed");
-
- // Verify that callback Client is disconnected when lease fails.
-
- // 1. Kill LeasePinger.
- ClientInvoker invoker = client.getInvoker();
- Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
- field.setAccessible(true);
- LeasePinger pinger = (LeasePinger) field.get(invoker);
- field = LeasePinger.class.getDeclaredField("timerTask");
- field.setAccessible(true);
- TimerTask timerTask = (TimerTask) field.get(pinger);
- timerTask.cancel();
- log.info("stopped LeasePinger");
-
- // 2. Verify that callback Client is disconnected.
- ServerInvokerCallbackHandler sich = invocationHandler.callbackHandler;
- Client callbackClient = sich.getCallbackClient();
- Thread.sleep(12000);
- assertEquals(registerAsListener, !callbackClient.isConnected());
- log.info("callback Client is disconnected");
-
- // 3. Verify that testConnectionListener gets called.
- Thread.sleep(20000);
- assertTrue(connectionListener.ok);
-
-
- client.removeListener(callbackHandler);
- client.disconnect();
- shutdownServer();
- }
-
-
- abstract protected String getTransport();
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
- protected void addExtraCallbackMetadata(Map metadata) {}
- protected String extendInvokerLocator(String locatorURI) {return locatorURI;}
-
-
- protected void setupServer(boolean registerAsListener, int handlerVersion) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- locatorURI = extendInvokerLocator(locatorURI);
- 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", "2000");
- config.put(ServerInvoker.REGISTER_CALLBACK_LISTENER, Boolean.toString(registerAsListener));
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
-
- if (handlerVersion == 1)
- invocationHandler = new TestInvocationHandler();
- else
- invocationHandler = new TestInvocationHandler2();
-
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- connectionListener = new TestConnectionListener();
- connector.addConnectionListener(connectionListener);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public ServerInvokerCallbackHandler callbackHandler;
-
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- this.callbackHandler = (ServerInvokerCallbackHandler) callbackHandler;
- }
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- if (CALLBACK.equals(invocation.getParameter()))
- {
- callbackHandler.handleCallback(new Callback(CALLBACK));
- }
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class TestInvocationHandler2 extends TestInvocationHandler
- {
- public ServerInvokerCallbackHandler[] callbackHandlers = new ServerInvokerCallbackHandler[2];
- private int i = 0;
-
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- callbackHandlers[i++] = (ServerInvokerCallbackHandler) callbackHandler;
- log.info("callback handlers registered: " + i);
- }
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- if (CALLBACK.equals(invocation.getParameter()))
- {
- if (i > 0)
- callbackHandlers[0].handleCallback(new Callback(CALLBACK));
-
- if (i > 1)
- callbackHandlers[1].handleCallback(new Callback(CALLBACK));
- }
- return invocation.getParameter();
- }
- }
-
-
- static class TestCallbackHandler implements InvokerCallbackHandler
- {
- public int count;
-
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- count++;
- log.info(this + " received callback");
- }
- }
-
-
- static class TestConnectionListener implements ConnectionListener
- {
- public boolean ok;
-
- public void handleConnectionException(Throwable throwable, Client client)
- {
- try {Thread.sleep(20000);} catch (InterruptedException e) {}
- ok = true;
- log.info("connection failed: " + client.getSessionId());
- }
- }
+/*
+* 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.callback.connectionfailure;
+
+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.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.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ *
+ * Parent of unit tests for JBREM-873.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Dec 10, 2007
+ * </p>
+ */
+abstract public class CallbackConnectionFailureTestParent extends TestCase
+{
+ private static Logger log = Logger.getLogger(CallbackConnectionFailureTestParent.class);
+
+ private static boolean firstTime = true;
+ private static String CALLBACK = "callback";
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener connectionListener;
+
+
+ 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 testCallbackConnectionFailureWithListener() throws Throwable
+ {
+ log.info("entering " + getName());
+ doTest(true);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testCallbackConnectionFailureWithoutListener() throws Throwable
+ {
+ log.info("entering " + getName());
+ doTest(false);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testCallbackConnectionFailureTwoClients() throws Throwable
+ {
+ // Start server.
+ setupServer(true, 2);
+
+ // Create clients.
+ InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("enableLease", "true");
+
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator1, clientConfig);
+ client1.connect();
+ log.info("client1 is connected: " + client1.getSessionId());
+ // Force the Clients to use distinct invokers.
+ InvokerLocator clientLocator2 = new InvokerLocator(locatorURI + "/?a=b");
+ Client client2 = new Client(clientLocator2, clientConfig);
+ client2.connect();
+ log.info("client2 is connected: " + client2.getSessionId());
+ assertNotSame(client1.getInvoker(), client2.getInvoker());
+
+ // Test connections.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("xyz", client1.invoke("xyz"));
+ log.info("connections are good");
+
+ // Add callback handlers.
+ TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
+ Map metadata = new HashMap();
+ addExtraCallbackMetadata(metadata);
+ int callbackPort = PortUtil.findFreePort(host);
+ metadata.put(Client.CALLBACK_SERVER_PORT, Integer.toString(callbackPort));
+ client1.addListener(callbackHandler1, metadata, null, true);
+ client1.invoke(CALLBACK);
+ assertEquals(1, callbackHandler1.count);
+ log.info("first callback handler is installed");
+
+ TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
+ callbackPort = PortUtil.findFreePort(host);
+ metadata.put(Client.CALLBACK_SERVER_PORT, Integer.toString(callbackPort));
+ client2.addListener(callbackHandler2, metadata, null, true);
+ client2.invoke(CALLBACK);
+ assertEquals(2, callbackHandler1.count);
+ assertEquals(1, callbackHandler2.count);
+ log.info("second callback handler is installed");
+
+ // Verify that first callback Client is disconnected when lease fails,
+ // but second callback Client is not disconnected.
+
+ // 1. Kill LeasePinger for Client 1.
+ ClientInvoker invoker = client1.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(invoker);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ timerTask.cancel();
+ log.info("stopped LeasePinger");
+
+ // 2. Verify that first callback Client is disconnected.
+ TestInvocationHandler2 tih = (TestInvocationHandler2) invocationHandler;
+ ServerInvokerCallbackHandler sich1 = tih.callbackHandlers[0];
+ Client callbackClient1 = sich1.getCallbackClient();
+ Thread.sleep(12000);
+ assertFalse(callbackClient1.isConnected());
+ log.info("first callback Client is disconnected");
+
+ // 2. Verify that second callback Client is not disconnected.
+ ServerInvokerCallbackHandler sich2 = tih.callbackHandlers[1];
+ Client callbackClient2 = sich2.getCallbackClient();
+ assertTrue(callbackClient2.isConnected());
+ log.info("second callback Client is connected");
+
+ client1.removeListener(callbackHandler1);
+ client1.disconnect();
+ client2.removeListener(callbackHandler1);
+ client2.disconnect();
+ shutdownServer();
+ }
+
+
+ protected void doTest(boolean registerAsListener) throws Throwable
+ {
+ // Start server.
+ setupServer(registerAsListener, 1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("enableLease", "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");
+
+ // Add callback handler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ Map metadata = new HashMap();
+ addExtraCallbackMetadata(metadata);
+ client.addListener(callbackHandler, metadata, null, true);
+ client.invoke(CALLBACK);
+ assertEquals(1, callbackHandler.count);
+ log.info("callback handler is installed");
+
+ // Verify that callback Client is disconnected when lease fails.
+
+ // 1. Kill LeasePinger.
+ ClientInvoker invoker = client.getInvoker();
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger pinger = (LeasePinger) field.get(invoker);
+ field = LeasePinger.class.getDeclaredField("timerTask");
+ field.setAccessible(true);
+ TimerTask timerTask = (TimerTask) field.get(pinger);
+ timerTask.cancel();
+ log.info("stopped LeasePinger");
+
+ // 2. Verify that callback Client is disconnected.
+ ServerInvokerCallbackHandler sich = invocationHandler.callbackHandler;
+ Client callbackClient = sich.getCallbackClient();
+ Thread.sleep(12000);
+ assertEquals(registerAsListener, !callbackClient.isConnected());
+ log.info("callback Client is disconnected");
+
+ // 3. Verify that testConnectionListener gets called.
+ Thread.sleep(20000);
+ assertTrue(connectionListener.ok);
+
+
+ client.removeListener(callbackHandler);
+ client.disconnect();
+ shutdownServer();
+ }
+
+
+ abstract protected String getTransport();
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+ protected void addExtraCallbackMetadata(Map metadata) {}
+ protected String extendInvokerLocator(String locatorURI) {return locatorURI;}
+
+
+ protected void setupServer(boolean registerAsListener, int handlerVersion) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI = extendInvokerLocator(locatorURI);
+ 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", "2000");
+ config.put(ServerInvoker.REGISTER_CALLBACK_LISTENER, Boolean.toString(registerAsListener));
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+
+ if (handlerVersion == 1)
+ invocationHandler = new TestInvocationHandler();
+ else
+ invocationHandler = new TestInvocationHandler2();
+
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ connectionListener = new TestConnectionListener();
+ connector.addConnectionListener(connectionListener);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public ServerInvokerCallbackHandler callbackHandler;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ this.callbackHandler = (ServerInvokerCallbackHandler) callbackHandler;
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ if (CALLBACK.equals(invocation.getParameter()))
+ {
+ callbackHandler.handleCallback(new Callback(CALLBACK));
+ }
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestInvocationHandler2 extends TestInvocationHandler
+ {
+ public ServerInvokerCallbackHandler[] callbackHandlers = new ServerInvokerCallbackHandler[2];
+ private int i = 0;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ callbackHandlers[i++] = (ServerInvokerCallbackHandler) callbackHandler;
+ log.info("callback handlers registered: " + i);
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ if (CALLBACK.equals(invocation.getParameter()))
+ {
+ if (i > 0)
+ callbackHandlers[0].handleCallback(new Callback(CALLBACK));
+
+ if (i > 1)
+ callbackHandlers[1].handleCallback(new Callback(CALLBACK));
+ }
+ return invocation.getParameter();
+ }
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public int count;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ count++;
+ log.info(this + " received callback");
+ }
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean ok;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ try {Thread.sleep(20000);} catch (InterruptedException e) {}
+ ok = true;
+ log.info("connection failed: " + client.getSessionId());
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/connectionfailure/CallbackConnectionFailureTestParent.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5973 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:53:35 -0400 (Wed, 04 Aug 2010)
New Revision: 5973
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/DestroyNPETestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/DestroyNPETestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/DestroyNPETestCase.java 2010-08-05 00:50:27 UTC (rev 5972)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/callback/DestroyNPETestCase.java 2010-08-05 00:53:35 UTC (rev 5973)
@@ -1,217 +1,217 @@
-/*
-* 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.callback;
-
-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.callback.ServerInvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-
-/**
- * Unit test for JBREM-1081.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Mar 19, 2009
- * </p>
- */
-public class DestroyNPETestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(DestroyNPETestCase.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 testForNPE() 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 connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Add CallbackHandler.
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- client.addListener(callbackHandler, new HashMap(), null, true);
-
- // Shut down ServerInvokerCallbackHandler and verify there's no NullPointerException.
- invocationHandler.serverInvokerCallbackHandler.destroy();
- invocationHandler.serverInvokerCallbackHandler.setShouldPersist(true);
-
- try
- {
- invocationHandler.serverInvokerCallbackHandler.handleCallback(new Callback("callback"));
- }
- catch (HandleCallbackException e)
- {
- Throwable cause = e.getCause();
- if (cause != null && cause.getMessage().startsWith("Can not make remoting client invocation"))
- {
- log.info("Got expected HandleCallbackException");
- }
- else
- {
- fail("Got unexpected Exception");
- }
- }
- catch (NullPointerException e)
- {
- fail("Shouldn't get NullPointerException");
- }
- catch (Exception e)
- {
- fail("Got unexpected Exception");
- }
-
- client.removeListener(callbackHandler);
- 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 ServerInvokerCallbackHandler serverInvokerCallbackHandler;
-
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) 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.callback;
+
+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.callback.ServerInvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1081.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Mar 19, 2009
+ * </p>
+ */
+public class DestroyNPETestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(DestroyNPETestCase.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 testForNPE() 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 connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Add CallbackHandler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, new HashMap(), null, true);
+
+ // Shut down ServerInvokerCallbackHandler and verify there's no NullPointerException.
+ invocationHandler.serverInvokerCallbackHandler.destroy();
+ invocationHandler.serverInvokerCallbackHandler.setShouldPersist(true);
+
+ try
+ {
+ invocationHandler.serverInvokerCallbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (HandleCallbackException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause != null && cause.getMessage().startsWith("Can not make remoting client invocation"))
+ {
+ log.info("Got expected HandleCallbackException");
+ }
+ else
+ {
+ fail("Got unexpected Exception");
+ }
+ }
+ catch (NullPointerException e)
+ {
+ fail("Shouldn't get NullPointerException");
+ }
+ catch (Exception e)
+ {
+ fail("Got unexpected Exception");
+ }
+
+ client.removeListener(callbackHandler);
+ 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 ServerInvokerCallbackHandler serverInvokerCallbackHandler;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) 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/callback/DestroyNPETestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5972 - remoting2/branches/2.2/src/main/org/jboss/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:50:27 -0400 (Wed, 04 Aug 2010)
New Revision: 5972
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Property changes on: remoting2/branches/2.2/src/main/org/jboss/remoting/util/LocalHostUtil.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months
JBoss Remoting SVN: r5971 - remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 20:47:16 -0400 (Wed, 04 Aug 2010)
New Revision: 5971
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Property changes on: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 3 months