JBoss Remoting SVN: r3615 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-13 00:56:06 -0400 (Thu, 13 Mar 2008)
New Revision: 3615
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-826: Removed some log.error() calls.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2008-03-13 04:55:43 UTC (rev 3614)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2008-03-13 04:56:06 UTC (rev 3615)
@@ -1697,7 +1697,7 @@
// the only elements should be the callback handler and possibly the callback handle object
if(params == null || params.length < 0 || params.length > 3)
{
- log.error("Recieved addClientListener InternalInvocation, but getParameters() " +
+ log.debug("Received addClientListener InternalInvocation, but getParameters() " +
"returned: " + params);
throw new RuntimeException(
"InvokerCallbackHandler and callback handle object (optional) must be supplied as " +
@@ -1768,7 +1768,7 @@
}
else
{
- log.error("Client request is an InputStream, but the registered handlers do not " +
+ log.debug("Client request is an InputStream, but the registered handlers do not " +
"implement the StreamInvocationHandler interface, so could not process call.");
throw new RuntimeException(
"No handler registered of proper type (StreamInvocationHandler).");
@@ -1789,7 +1789,7 @@
}
else
{
- log.error("Error processing InternalInvocation. Unable to process method " +
+ log.debug("Error processing InternalInvocation. Unable to process method " +
methodName + ". Please make sure this should be an InternalInvocation.");
throw new RuntimeException(
"Error processing InternalInvocation. Unable to process method " + methodName);
16 years, 1 month
JBoss Remoting SVN: r3614 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-13 00:55:43 -0400 (Thu, 13 Mar 2008)
New Revision: 3614
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java
Log:
JBREM-826: Removed some log.warn() calls.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java 2008-03-13 04:55:16 UTC (rev 3613)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java 2008-03-13 04:55:43 UTC (rev 3614)
@@ -162,13 +162,13 @@
}
catch (Throwable throwable)
{
- log.warn(this + " failed sending disconnect for client lease for " +
+ log.debug(this + " failed sending disconnect for client lease for " +
"client with session ID " + sessionID);
}
}
else
{
- log.warn(this + " tried to remove lease for client with session ID " + sessionID +
+ log.debug(this + " tried to remove lease for client with session ID " + sessionID +
", but no such lease was found");
}
@@ -287,7 +287,6 @@
catch (Throwable t)
{
log.debug(this + " failed to ping to server", t);
- log.warn(this + " failed to ping to server: " + t.getMessage());
}
}
16 years, 1 month
JBoss Remoting SVN: r3613 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-13 00:55:16 -0400 (Thu, 13 Mar 2008)
New Revision: 3613
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-826: Removed some log.error() calls.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-03-13 04:54:53 UTC (rev 3612)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-03-13 04:55:16 UTC (rev 3613)
@@ -471,7 +471,7 @@
}
catch (Exception e)
{
- log.error("Unable to create client invoker for locator: " + locator);
+ log.debug("Unable to create client invoker for locator: " + locator);
throw new RuntimeException("Unable to create client invoker for locator: " + locator, e);
}
16 years, 1 month
JBoss Remoting SVN: r3612 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-13 00:54:53 -0400 (Thu, 13 Mar 2008)
New Revision: 3612
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-826: Removed some log.error() calls.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2008-03-13 03:34:35 UTC (rev 3611)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2008-03-13 04:54:53 UTC (rev 3612)
@@ -323,7 +323,7 @@
}
catch (Exception e)
{
- log.error(e);
+ log.debug(e);
throw new IOException(e.getMessage());
}
@@ -1080,7 +1080,7 @@
}
catch (Exception e)
{
- log.warn("unable to remove remote callback handler: " + e.getMessage());
+ log.debug("unable to remove remote callback handler", e);
}
}
@@ -1124,7 +1124,7 @@
}
catch (Exception e)
{
- log.warn("unable to remove remote callback handler: " + e.getMessage());
+ log.debug("unable to remove remote callback handler", e);
}
}
16 years, 1 month
JBoss Remoting SVN: r3611 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:34:35 -0400 (Wed, 12 Mar 2008)
New Revision: 3611
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestDecorator.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestUnDecorator.java
Log:
JBREM-167: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestDecorator.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestDecorator.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestDecorator.java 2008-03-13 03:34:35 UTC (rev 3611)
@@ -0,0 +1,72 @@
+
+/*
+* 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.transport.rmi;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.MarshallerDecorator;
+
+
+/**
+ * Part of unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class TestDecorator implements MarshallerDecorator, Marshaller
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3285464065838923918L;
+
+ public Object addDecoration(Object obj) throws IOException
+ {
+ if (obj instanceof InvocationRequest)
+ {
+ InvocationRequest ir = (InvocationRequest) obj;
+ if (ir.getParameter() instanceof Integer)
+ {
+ int i = ((Integer) ir.getParameter()).intValue();
+ ir.setParameter(new Integer(i + 1));
+ }
+ }
+
+ return obj;
+ }
+
+ public Marshaller cloneMarshaller() throws CloneNotSupportedException
+ {
+ return new TestDecorator();
+ }
+
+ public void write(Object dataObject, OutputStream output) throws IOException
+ {
+ // no-op
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestUnDecorator.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestUnDecorator.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/TestUnDecorator.java 2008-03-13 03:34:35 UTC (rev 3611)
@@ -0,0 +1,77 @@
+
+/*
+* 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.transport.rmi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.marshal.UnMarshallerDecorator;
+
+
+/**
+ * Part of unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class TestUnDecorator implements UnMarshallerDecorator, UnMarshaller
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 6808291060065002247L;
+
+ public Object removeDecoration(Object obj) throws IOException
+ {
+ if (obj instanceof InvocationRequest)
+ {
+ InvocationRequest ir = (InvocationRequest) obj;
+ if (ir.getParameter() instanceof Integer)
+ {
+ int i = ((Integer) ir.getParameter()).intValue();
+ ir.setParameter(new Integer(i - 1));
+ }
+ }
+ return obj;
+ }
+
+ public UnMarshaller cloneUnMarshaller() throws CloneNotSupportedException
+ {
+ return new TestUnDecorator();
+ }
+
+ public Object read(InputStream inputStream, Map metadata) throws IOException, ClassNotFoundException
+ {
+ return null;
+ }
+
+ public void setClassLoader(ClassLoader classloader)
+ {
+ // no-op
+ }
+}
+
16 years, 1 month
JBoss Remoting SVN: r3610 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:33:00 -0400 (Wed, 12 Mar 2008)
New Revision: 3610
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerDecoratorTestCase.java
Log:
JBREM-167: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerDecoratorTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerDecoratorTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerDecoratorTestCase.java 2008-03-13 03:33:00 UTC (rev 3610)
@@ -0,0 +1,166 @@
+/*
+* 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.transport.rmi;
+
+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.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.marshal.MarshalFactory;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class RMIInvokerDecoratorTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(RMIInvokerDecoratorTestCase.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);
+ MarshalFactory.addMarshaller("decorated", new TestDecorator(), new TestUnDecorator());
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testDecoration() 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(new Integer(17), client.invoke(new Integer(17)));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "rmi";
+ }
+
+
+ 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 += "/?" + InvokerLocator.DATATYPE + "=decorated";
+ 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) {}
+ }
+}
\ No newline at end of file
16 years, 1 month
JBoss Remoting SVN: r3609 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:32:36 -0400 (Wed, 12 Mar 2008)
New Revision: 3609
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingClientTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingServerTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingTestCase.java
Log:
JBREM-167: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingClientTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingClientTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingClientTest.java 2008-03-13 03:32:36 UTC (rev 3609)
@@ -0,0 +1,433 @@
+/*
+* 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.transport.rmi;
+
+import junit.framework.TestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.invocation.NameBasedInvocation;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.ComplexReturn;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockInvokerCallbackHandler;
+import org.jboss.test.remoting.transport.mock.MockTest;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.rmi.MarshalledObject;
+import java.rmi.server.UID;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class RMIInvokerOnewayMarshallingClientTest extends TestCase
+{
+
+ private String sessionId = new UID().toString();
+ private Client client;
+ private Connector connector;
+ private InvokerLocator locator;
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+
+ private static final Logger log = Logger.getLogger(RMIInvokerOnewayMarshallingClientTest.class);
+
+ public void init(Map metadata)
+ {
+ try
+ {
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, this.port));
+ //InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port);
+ System.out.println("client locator: " + locator);
+ client = new Client(locator, "mock");
+ client.connect();
+ }
+ catch(Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ private String buildLocatorURI(Map metadata, int port)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port);
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ private InvokerLocator initServer(Map metadata, int serverPort) throws Exception
+ {
+ if(serverPort < 0)
+ {
+ serverPort = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + serverPort);
+
+// InvokerRegistry.registerInvoker("mock", MockClientInvoker.class, MockServerInvoker.class);
+ connector = new Connector();
+
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, serverPort));
+ System.out.println("Server locator: " + locator);
+
+ //InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<handlers>\n");
+ buf.append(" <handler subsystem=\"mock\">org.jboss.test.remoting.transport.mock.MockServerInvocationHandler</handler>\n");
+ buf.append("</handlers>\n");
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.setConfiguration(xml.getDocumentElement());
+ //connector.create();
+ connector.start();
+ return locator;
+ }
+
+
+ public void setUp() throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ locator = initServer(metadata, -1);
+ metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYPE);
+ metadata.put(RMIServerInvoker.RMI_ONEWAY_MARSHALLING, "true");
+ metadata.put("serializationtype", "jboss");
+ init(metadata);
+ log.info("Using metadata: " + metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ connector = null;
+ }
+ locator = null;
+ if(client != null)
+ {
+ client.disconnect();
+ client = null;
+ }
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a local callback server
+ *
+ * @throws Throwable
+ */
+ public void testLocalPushCallbackWithDatatype() throws Throwable
+ {
+ setUp();
+ runLocalPushCallback();
+ }
+
+ public void runLocalPushCallback() throws Throwable
+ {
+ log.debug("running testLocalPushCallback()");
+
+ sessionId = new UID().toString();
+
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testLocalPushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a remote callback server
+ *
+ * @throws Throwable
+ */
+ public void testRemotePushCallbackWithDataType() throws Throwable
+ {
+ setUp();
+ runRemotePushCallback();
+ }
+
+ public void runRemotePushCallback() throws Throwable
+ {
+ log.debug("running testRemotePushCallback()");
+
+ sessionId = new UID().toString();
+ //InvokerLocator locator = client.getInvoker().getLocator();
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testRemotePushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ // TODO: No way to currently check the remote callback handler
+ // to see if it got callback -TME
+ /*
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ */
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ /*
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ */
+ }
+
+ /**
+ * Tests simple invocation and pull callbacks. Meaning will add a listener and
+ * will then have to get the callbacks from the server.
+ *
+ * @throws Throwable
+ */
+ public void testPullCallbackWithDataType() throws Throwable
+ {
+ setUp();
+ runPullCallback();
+ }
+
+ public void runPullCallback() throws Throwable
+ {
+ log.debug("running testPullCallback()");
+
+ // should be null by default, since don't have connector started, but setting anyway
+ //client.setClientLocator(null);
+
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("bar", "foo");
+ assertTrue("Result of runPullCallbackTest() invocation of bar.", "foo".equals(ret));
+ client.addListener(handler);
+ // invoke which should cause callback on server side
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ ret = client.getCallbacks(handler);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have something.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after add listener.",
+ ret != null);
+ // can now call directly on client
+ //ret = makeInvocation("removeListener", null);
+ client.removeListener(handler);
+ ret = makeInvocation("getCallbacks", null);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have been empty.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after remove listener.",
+ ret == null);
+ }
+
+ /**
+ * Tests complex invocation to get object containing array of complex objects.
+ *
+ * @throws Throwable
+ */
+ public void testArrayReturnWithDataType() throws Throwable
+ {
+ setUp();
+ runArrayReturn();
+ }
+
+ public void runArrayReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testComplexReturn", null);
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ /**
+ * Tests complex invocation to get marshalled object.
+ *
+ * @throws Throwable
+ */
+ public void testMarshalledObjectReturnWithDataType() throws Throwable
+ {
+ setUp();
+ runMarshalledObjectReturn();
+ }
+
+ public void runMarshalledObjectReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testMarshalledObject", null);
+ ret = ((MarshalledObject) ret).get();
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ private Object makeInvocation(String method, String param) throws Throwable
+ {
+ Object ret = client.invoke(new NameBasedInvocation(method,
+ new Object[]{param},
+ new String[]{String.class.getName()}),
+ null);
+
+ return ret;
+ }
+
+// public static void main(String[] args)
+// {
+// RMIInvokerClientTest client = new RMIInvokerClientTest();
+// try
+// {
+// client.setUp();
+// client.testArrayReturn();
+// client.testArrayReturnWithDataType();
+// client.testLocalPushCallback();
+// client.testLocalPushCallbackWithDatatype();
+// client.testMarshalledObjectReturn();
+// client.testMarshalledObjectReturnWithDataType();
+// client.testPullCallback();
+// client.testPullCallbackWithDataType();
+// client.testRemotePushCallback();
+// client.testRemotePushCallbackWithDataType();
+// }
+// catch (Throwable throwable)
+// {
+// throwable.printStackTrace();
+// }
+// finally
+// {
+// try
+// {
+// client.tearDown();
+// }
+// catch (Exception e)
+// {
+// e.printStackTrace();
+// }
+// }
+//
+// }
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingServerTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingServerTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingServerTest.java 2008-03-13 03:32:36 UTC (rev 3609)
@@ -0,0 +1,151 @@
+/*
+* 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.transport.rmi;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
+
+
+/**
+ * Unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class RMIInvokerOnewayMarshallingServerTest extends ServerTestCase
+{
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+ private Connector connector;
+
+ private static final Logger log = Logger.getLogger(RMIInvokerOnewayMarshallingServerTest.class);
+
+ public void init(Map metatdata) throws Exception
+ {
+ if(port < 0)
+ {
+ port = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + port);
+
+ connector = new Connector();
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
+ System.out.println("server locator: " + locator);
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.start();
+ connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
+ }
+
+ private String buildLocatorURI(Map metadata)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port);
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ protected String getSubsystem()
+ {
+ return "mock";
+ }
+
+ protected ServerInvocationHandler getServerInvocationHandler()
+ {
+ return new MockServerInvocationHandler();
+ }
+
+ public void setUp() throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYPE);
+ metadata.put(RMIServerInvoker.RMI_ONEWAY_MARSHALLING, "true");
+ metadata.put("serializationtype", "jboss");
+ init(metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ RMIInvokerOnewayMarshallingServerTest server = new RMIInvokerOnewayMarshallingServerTest();
+ try
+ {
+ server.setUp();
+ Thread.currentThread().sleep(6000000);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerOnewayMarshallingTestCase.java 2008-03-13 03:32:36 UTC (rev 3609)
@@ -0,0 +1,44 @@
+/*
+* 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.transport.rmi;
+
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * Unit test for JBREM-167.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Mar 12, 2008
+ * </p>
+ */
+public class RMIInvokerOnewayMarshallingTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses(RMIInvokerOnewayMarshallingClientTest.class.getName(),
+ 1,
+ RMIInvokerOnewayMarshallingServerTest.class.getName());
+ }
+}
\ No newline at end of file
16 years, 1 month
JBoss Remoting SVN: r3608 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:31:07 -0400 (Wed, 12 Mar 2008)
New Revision: 3608
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerClientTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerServerTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerClientTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerServerTest.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerTestCase.java
Log:
JBREM-167: Broke RMIInvokerTestCase into RMIInvokerNativeMarshallingTestCase and RMIInvokerSerializableMarshallerTestCase.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerClientTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerClientTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerClientTest.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,430 @@
+/*
+* 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.transport.rmi;
+
+import junit.framework.TestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.invocation.NameBasedInvocation;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.ComplexReturn;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockInvokerCallbackHandler;
+import org.jboss.test.remoting.transport.mock.MockTest;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.rmi.MarshalledObject;
+import java.rmi.server.UID;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This is the actual concrete test for the invoker client.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerNativeMarshallerClientTest extends TestCase
+{
+
+ private String sessionId = new UID().toString();
+ private Client client;
+ private Connector connector;
+ private InvokerLocator locator;
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+
+ private static final Logger log = Logger.getLogger(RMIInvokerNativeMarshallerClientTest.class);
+
+ public void init(Map metadata)
+ {
+ try
+ {
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, this.port));
+ //InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port);
+ System.out.println("client locator: " + locator);
+ client = new Client(locator, "mock");
+ client.connect();
+ }
+ catch(Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ private String buildLocatorURI(Map metadata, int port)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port);
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ private InvokerLocator initServer(Map metadata, int serverPort) throws Exception
+ {
+ if(serverPort < 0)
+ {
+ serverPort = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + serverPort);
+
+// InvokerRegistry.registerInvoker("mock", MockClientInvoker.class, MockServerInvoker.class);
+ connector = new Connector();
+
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, serverPort));
+ System.out.println("Server locator: " + locator);
+
+ //InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<handlers>\n");
+ buf.append(" <handler subsystem=\"mock\">org.jboss.test.remoting.transport.mock.MockServerInvocationHandler</handler>\n");
+ buf.append("</handlers>\n");
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.setConfiguration(xml.getDocumentElement());
+ //connector.create();
+ connector.start();
+ return locator;
+ }
+
+
+ public void setUp(boolean withNativeMarshaller) throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ locator = initServer(metadata, -1);
+ if(!withNativeMarshaller)
+ {
+ metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYPE);
+ }
+ init(metadata);
+ log.info("Using metadata: " + metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ connector = null;
+ }
+ locator = null;
+ if(client != null)
+ {
+ client.disconnect();
+ client = null;
+ }
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a local callback server
+ *
+ * @throws Throwable
+ */
+ public void testLocalPushCallback() throws Throwable
+ {
+ setUp(true);
+ runLocalPushCallback();
+ }
+
+ public void runLocalPushCallback() throws Throwable
+ {
+ log.debug("running testLocalPushCallback()");
+
+ sessionId = new UID().toString();
+
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testLocalPushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a remote callback server
+ *
+ * @throws Throwable
+ */
+ public void testRemotePushCallback() throws Throwable
+ {
+ setUp(true);
+ runRemotePushCallback();
+ }
+
+ public void runRemotePushCallback() throws Throwable
+ {
+ log.debug("running testRemotePushCallback()");
+
+ sessionId = new UID().toString();
+ //InvokerLocator locator = client.getInvoker().getLocator();
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testRemotePushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ // TODO: No way to currently check the remote callback handler
+ // to see if it got callback -TME
+ /*
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ */
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ /*
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ */
+ }
+
+ /**
+ * Tests simple invocation and pull callbacks. Meaning will add a listener and
+ * will then have to get the callbacks from the server.
+ *
+ * @throws Throwable
+ */
+ public void testPullCallback() throws Throwable
+ {
+ setUp(true);
+ runPullCallback();
+ }
+
+ public void runPullCallback() throws Throwable
+ {
+ log.debug("running testPullCallback()");
+
+ // should be null by default, since don't have connector started, but setting anyway
+ //client.setClientLocator(null);
+
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("bar", "foo");
+ assertTrue("Result of runPullCallbackTest() invocation of bar.", "foo".equals(ret));
+ client.addListener(handler);
+ // invoke which should cause callback on server side
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ ret = client.getCallbacks(handler);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have something.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after add listener.",
+ ret != null);
+ // can now call directly on client
+ //ret = makeInvocation("removeListener", null);
+ client.removeListener(handler);
+ ret = makeInvocation("getCallbacks", null);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have been empty.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after remove listener.",
+ ret == null);
+ }
+
+ /**
+ * Tests complex invocation to get object containing array of complex objects.
+ *
+ * @throws Throwable
+ */
+ public void testArrayReturn() throws Throwable
+ {
+ setUp(true);
+ runArrayReturn();
+ }
+
+ public void runArrayReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testComplexReturn", null);
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ /**
+ * Tests complex invocation to get marshalled object.
+ *
+ * @throws Throwable
+ */
+ public void testMarshalledObjectReturn() throws Throwable
+ {
+ setUp(true);
+ runMarshalledObjectReturn();
+ }
+
+ public void runMarshalledObjectReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testMarshalledObject", null);
+ ret = ((MarshalledObject) ret).get();
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ private Object makeInvocation(String method, String param) throws Throwable
+ {
+ Object ret = client.invoke(new NameBasedInvocation(method,
+ new Object[]{param},
+ new String[]{String.class.getName()}),
+ null);
+
+ return ret;
+ }
+
+// public static void main(String[] args)
+// {
+// RMIInvokerClientTest client = new RMIInvokerClientTest();
+// try
+// {
+// client.setUp();
+// client.testArrayReturn();
+// client.testArrayReturnWithDataType();
+// client.testLocalPushCallback();
+// client.testLocalPushCallbackWithDatatype();
+// client.testMarshalledObjectReturn();
+// client.testMarshalledObjectReturnWithDataType();
+// client.testPullCallback();
+// client.testPullCallbackWithDataType();
+// client.testRemotePushCallback();
+// client.testRemotePushCallbackWithDataType();
+// }
+// catch (Throwable throwable)
+// {
+// throwable.printStackTrace();
+// }
+// finally
+// {
+// try
+// {
+// client.tearDown();
+// }
+// catch (Exception e)
+// {
+// e.printStackTrace();
+// }
+// }
+//
+// }
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerServerTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerServerTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerServerTest.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,144 @@
+/*
+* 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.transport.rmi;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
+
+
+/**
+ * This is the concrete test for invoker server.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerNativeMarshallerServerTest extends ServerTestCase
+{
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+ private Connector connector;
+
+ private static final Logger log = Logger.getLogger(RMIInvokerNativeMarshallerServerTest.class);
+
+ public void init(Map metatdata) throws Exception
+ {
+ if(port < 0)
+ {
+ port = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + port);
+
+ connector = new Connector();
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
+ System.out.println("server locator: " + locator);
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.start();
+ connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
+ }
+
+ private String buildLocatorURI(Map metadata)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port + "/?");
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ protected String getSubsystem()
+ {
+ return "mock";
+ }
+
+ protected ServerInvocationHandler getServerInvocationHandler()
+ {
+ return new MockServerInvocationHandler();
+ }
+
+ public void setUp() throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ init(metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ RMIInvokerNativeMarshallerServerTest server = new RMIInvokerNativeMarshallerServerTest();
+ try
+ {
+ server.setUp();
+ Thread.currentThread().sleep(6000000);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerNativeMarshallerTestCase.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,43 @@
+/*
+* 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.transport.rmi;
+
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * This should be used as the main test case for the invoker client/server.
+ * It will start one instance of the client and one of the server and will
+ * gather the test results and report them in standard JUnit format. When
+ * wanting to run JUnit test for invoker, this is the class to use.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerNativeMarshallerTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses(RMIInvokerNativeMarshallerClientTest.class.getName(),
+ 1,
+ RMIInvokerNativeMarshallerServerTest.class.getName());
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerClientTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerClientTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerClientTest.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,430 @@
+/*
+* 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.transport.rmi;
+
+import junit.framework.TestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.invocation.NameBasedInvocation;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.ComplexReturn;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockInvokerCallbackHandler;
+import org.jboss.test.remoting.transport.mock.MockTest;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.rmi.MarshalledObject;
+import java.rmi.server.UID;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This is the actual concrete test for the invoker client.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerSerializableMarshallerClientTest extends TestCase
+{
+
+ private String sessionId = new UID().toString();
+ private Client client;
+ private Connector connector;
+ private InvokerLocator locator;
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+
+ private static final Logger log = Logger.getLogger(RMIInvokerSerializableMarshallerClientTest.class);
+
+ public void init(Map metadata)
+ {
+ try
+ {
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, this.port));
+ //InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port);
+ System.out.println("client locator: " + locator);
+ client = new Client(locator, "mock");
+ client.connect();
+ }
+ catch(Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ private String buildLocatorURI(Map metadata, int port)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port);
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ private InvokerLocator initServer(Map metadata, int serverPort) throws Exception
+ {
+ if(serverPort < 0)
+ {
+ serverPort = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + serverPort);
+
+// InvokerRegistry.registerInvoker("mock", MockClientInvoker.class, MockServerInvoker.class);
+ connector = new Connector();
+
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metadata, serverPort));
+ System.out.println("Server locator: " + locator);
+
+ //InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<handlers>\n");
+ buf.append(" <handler subsystem=\"mock\">org.jboss.test.remoting.transport.mock.MockServerInvocationHandler</handler>\n");
+ buf.append("</handlers>\n");
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.setConfiguration(xml.getDocumentElement());
+ //connector.create();
+ connector.start();
+ return locator;
+ }
+
+
+ public void setUp(boolean withNativeMarshaller) throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ locator = initServer(metadata, -1);
+ if(!withNativeMarshaller)
+ {
+ metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYPE);
+ }
+ init(metadata);
+ log.info("Using metadata: " + metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ connector = null;
+ }
+ locator = null;
+ if(client != null)
+ {
+ client.disconnect();
+ client = null;
+ }
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a local callback server
+ *
+ * @throws Throwable
+ */
+ public void testLocalPushCallbackWithDatatype() throws Throwable
+ {
+ setUp(false);
+ runLocalPushCallback();
+ }
+
+ public void runLocalPushCallback() throws Throwable
+ {
+ log.debug("running testLocalPushCallback()");
+
+ sessionId = new UID().toString();
+
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testLocalPushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testLocalPushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ }
+
+ /**
+ * Test simple invocation and adding of listener with push callback (meaning server
+ * will send callback message when it gets it) to a remote callback server
+ *
+ * @throws Throwable
+ */
+ public void testRemotePushCallbackWithDataType() throws Throwable
+ {
+ setUp(false);
+ runRemotePushCallback();
+ }
+
+ public void runRemotePushCallback() throws Throwable
+ {
+ log.debug("running testRemotePushCallback()");
+
+ sessionId = new UID().toString();
+ //InvokerLocator locator = client.getInvoker().getLocator();
+ sessionId = client.getSessionId();
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("foo", "bar");
+ assertTrue("Result of testRemotePushCallback() invocation of foo.", "bar".equals(ret));
+ client.addListener(handler, locator);
+ // invoke which should cause callback
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(3000);
+ log.debug("done sleeping.");
+ // TODO: No way to currently check the remote callback handler
+ // to see if it got callback -TME
+ /*
+ int callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbacksPerformed after adding listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did not get callback.",
+ (callbacksPerformed == 1));
+ */
+ // Can now call direct on client
+ client.removeListener(handler);
+ // shouldn't get callback now since removed listener
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ log.debug("done sleeping.");
+ /*
+ callbacksPerformed = handler.isCallbackReceived();
+ log.debug("callbackPerformed after removing listener is " + callbacksPerformed);
+ assertTrue("Result of testRemotePushCallback() failed since did get callback " +
+ "but have been removed as listener.",
+ (callbacksPerformed == 1));
+ */
+ }
+
+ /**
+ * Tests simple invocation and pull callbacks. Meaning will add a listener and
+ * will then have to get the callbacks from the server.
+ *
+ * @throws Throwable
+ */
+ public void testPullCallbackWithDataType() throws Throwable
+ {
+ setUp(false);
+ runPullCallback();
+ }
+
+ public void runPullCallback() throws Throwable
+ {
+ log.debug("running testPullCallback()");
+
+ // should be null by default, since don't have connector started, but setting anyway
+ //client.setClientLocator(null);
+
+ MockInvokerCallbackHandler handler = new MockInvokerCallbackHandler(sessionId);
+
+ // simple invoke, should return bar
+ Object ret = makeInvocation("bar", "foo");
+ assertTrue("Result of runPullCallbackTest() invocation of bar.", "foo".equals(ret));
+ client.addListener(handler);
+ // invoke which should cause callback on server side
+ ret = makeInvocation("test", "test");
+ // allow time for callback
+ Thread.sleep(2000);
+ ret = client.getCallbacks(handler);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have something.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after add listener.",
+ ret != null);
+ // can now call directly on client
+ //ret = makeInvocation("removeListener", null);
+ client.removeListener(handler);
+ ret = makeInvocation("getCallbacks", null);
+ log.debug("getCallbacks returned " + ret);
+ log.debug("should have been empty.");
+ assertTrue("Result of runPullCallbackTest() getCallbacks() after remove listener.",
+ ret == null);
+ }
+
+ /**
+ * Tests complex invocation to get object containing array of complex objects.
+ *
+ * @throws Throwable
+ */
+ public void testArrayReturnWithDataType() throws Throwable
+ {
+ setUp(false);
+ runArrayReturn();
+ }
+
+ public void runArrayReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testComplexReturn", null);
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ /**
+ * Tests complex invocation to get marshalled object.
+ *
+ * @throws Throwable
+ */
+ public void testMarshalledObjectReturnWithDataType() throws Throwable
+ {
+ setUp(false);
+ runMarshalledObjectReturn();
+ }
+
+ public void runMarshalledObjectReturn() throws Throwable
+ {
+ // simple invoke, should return bar
+ Object ret = makeInvocation("testMarshalledObject", null);
+ ret = ((MarshalledObject) ret).get();
+ ComplexReturn complexRet = (ComplexReturn) ret;
+ MockTest[] mockTests = complexRet.getMockTests();
+ assertTrue("ComplexReturn's array should contain 2 items",
+ 2 == mockTests.length);
+ for(int x = 0; x < mockTests.length; x++)
+ {
+ System.err.println(mockTests[x]);
+ MockTest test = mockTests[x];
+ assertNotNull("MockTest should not be null", test);
+ }
+
+// assertTrue("Result of runPullCallbackTest() invocation of bar.",
+// "foo".equals(ret));
+ }
+
+ private Object makeInvocation(String method, String param) throws Throwable
+ {
+ Object ret = client.invoke(new NameBasedInvocation(method,
+ new Object[]{param},
+ new String[]{String.class.getName()}),
+ null);
+
+ return ret;
+ }
+
+// public static void main(String[] args)
+// {
+// RMIInvokerClientTest client = new RMIInvokerClientTest();
+// try
+// {
+// client.setUp();
+// client.testArrayReturn();
+// client.testArrayReturnWithDataType();
+// client.testLocalPushCallback();
+// client.testLocalPushCallbackWithDatatype();
+// client.testMarshalledObjectReturn();
+// client.testMarshalledObjectReturnWithDataType();
+// client.testPullCallback();
+// client.testPullCallbackWithDataType();
+// client.testRemotePushCallback();
+// client.testRemotePushCallbackWithDataType();
+// }
+// catch (Throwable throwable)
+// {
+// throwable.printStackTrace();
+// }
+// finally
+// {
+// try
+// {
+// client.tearDown();
+// }
+// catch (Exception e)
+// {
+// e.printStackTrace();
+// }
+// }
+//
+// }
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerServerTest.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerServerTest.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerServerTest.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,145 @@
+/*
+* 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.transport.rmi;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.test.remoting.TestUtil;
+import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
+import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
+import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
+
+
+/**
+ * This is the concrete test for invoker server.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerSerializableMarshallerServerTest extends ServerTestCase
+{
+ private int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1;
+ protected String transport = "rmi";
+ private Connector connector;
+
+ private static final Logger log = Logger.getLogger(RMIInvokerSerializableMarshallerServerTest.class);
+
+ public void init(Map metatdata) throws Exception
+ {
+ if(port < 0)
+ {
+ port = TestUtil.getRandomPort();
+ }
+ log.debug("port = " + port);
+
+ connector = new Connector();
+ InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
+ System.out.println("server locator: " + locator);
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.start();
+ connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
+ }
+
+ private String buildLocatorURI(Map metadata)
+ {
+ if(metadata == null || metadata.size() == 0)
+ {
+ return transport + "://localhost:" + port;
+ }
+ else
+ {
+ StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + port);
+
+ Set keys = metadata.keySet();
+ if(keys.size() > 0)
+ {
+ uriBuffer.append("/?");
+ }
+
+ Iterator itr = keys.iterator();
+ while(itr.hasNext())
+ {
+ String key = (String) itr.next();
+ String value = (String) metadata.get(key);
+ uriBuffer.append(key + "=" + value + "&");
+ }
+ return uriBuffer.substring(0, uriBuffer.length() - 1);
+ }
+ }
+
+ protected String getSubsystem()
+ {
+ return "mock";
+ }
+
+ protected ServerInvocationHandler getServerInvocationHandler()
+ {
+ return new MockServerInvocationHandler();
+ }
+
+ public void setUp() throws Exception
+ {
+ Map metadata = new HashMap();
+ String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
+ if(newMetadata != null && newMetadata.length() > 0)
+ {
+ metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
+ }
+ metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port + 1));
+ metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYPE);
+ init(metadata);
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ RMIInvokerSerializableMarshallerServerTest server = new RMIInvokerSerializableMarshallerServerTest();
+ try
+ {
+ server.setUp();
+ Thread.currentThread().sleep(6000000);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/RMIInvokerSerializableMarshallerTestCase.java 2008-03-13 03:31:07 UTC (rev 3608)
@@ -0,0 +1,43 @@
+/*
+* 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.transport.rmi;
+
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * This should be used as the main test case for the invoker client/server.
+ * It will start one instance of the client and one of the server and will
+ * gather the test results and report them in standard JUnit format. When
+ * wanting to run JUnit test for invoker, this is the class to use.
+ *
+ * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
+ */
+public class RMIInvokerSerializableMarshallerTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses(RMIInvokerSerializableMarshallerClientTest.class.getName(),
+ 1,
+ RMIInvokerSerializableMarshallerServerTest.class.getName());
+ }
+}
\ No newline at end of file
16 years, 1 month
JBoss Remoting SVN: r3607 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:28:24 -0400 (Wed, 12 Mar 2008)
New Revision: 3607
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
Log:
JBREM-167: Added ability to marshal/unmarshal in both directions.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java 2008-03-13 03:27:14 UTC (rev 3606)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIServerInvoker.java 2008-03-13 03:28:24 UTC (rev 3607)
@@ -29,12 +29,22 @@
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.marshal.MarshalFactory;
import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.MarshallerDecorator;
import org.jboss.remoting.marshal.UnMarshaller;
import org.jboss.remoting.marshal.UnMarshallerDecorator;
+import org.jboss.remoting.marshal.VersionedMarshaller;
+import org.jboss.remoting.marshal.VersionedUnMarshaller;
+import org.jboss.remoting.marshal.rmi.RMIMarshaller;
+import org.jboss.remoting.marshal.rmi.RMIUnMarshaller;
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.serialization.SerializationManager;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jboss.util.propertyeditor.PropertyEditors;
import org.jboss.logging.Logger;
import javax.net.SocketFactory;
+
+import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -55,6 +65,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
/**
@@ -66,10 +77,13 @@
*/
public class RMIServerInvoker extends ServerInvoker implements RMIServerInvokerInf, Cloneable
{
+ public static String RMI_ONEWAY_MARSHALLING = "rmiOnewayMarshalling";
+
private static final Logger log = Logger.getLogger(RMIServerInvoker.class);
protected boolean isPrimaryServer = true;
protected Set secondaryServers = new HashSet();
+ protected boolean rmiOnewayMarshalling;
private Remote stub;
@@ -124,6 +138,14 @@
}
}
+ protected void setup() throws Exception
+ {
+ Properties props = new Properties();
+ props.putAll(getConfiguration());
+ PropertyEditors.mapJavaBeanProperties(this, props, false);
+ super.setup();
+ }
+
protected RMIServerInvoker copy() throws IOException
{
Object o = null;
@@ -329,7 +351,7 @@
{
Object payload = invocation;
- if(unmarshaller != null)
+ if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller))
{
if(unmarshaller instanceof UnMarshallerDecorator)
{
@@ -337,26 +359,42 @@
}
else
{
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(byteOut);
- oos.writeObject(payload);
- oos.flush();
+ ByteArrayInputStream is = null;
+ if (rmiOnewayMarshalling)
+ {
+ // Legacy treatment, pre 2.4.0
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
+ ObjectOutputStream oos = manager.createOutput(baos);
+ oos.writeObject(payload);
+ oos.flush();
+ oos.close();
+ is = new ByteArrayInputStream(baos.toByteArray());
+ }
+ else
+ {
+ is = new ByteArrayInputStream((byte[]) payload);
+ }
- ByteArrayInputStream is = new ByteArrayInputStream(byteOut.toByteArray());
-
try
{
- oos.close();
- payload = unmarshaller.read(is, null);
- is.close();
+ if (unmarshaller instanceof VersionedUnMarshaller)
+ {
+ payload = ((VersionedUnMarshaller) unmarshaller).read(is, null, getVersion());
+ is.close();
+ }
+ else
+ {
+ payload = unmarshaller.read(is, null);
+ is.close();
+ }
}
catch(ClassNotFoundException e)
{
- log.error("Could not unmarshall invocation request" + payload, e);
+ log.debug("Could not unmarshall invocation request" + payload, e);
throw new IOException(e.getMessage());
}
}
-
}
if (payload instanceof InvocationRequest)
@@ -380,32 +418,34 @@
}
Object response = invoke(payload);
- /* Jira Issue: JBREM-167
- if(marshaller != null)
+ if(marshaller != null && !(marshaller instanceof RMIMarshaller) && !rmiOnewayMarshalling)
{
- PipedOutputStream pos = new PipedOutputStream();
- PipedInputStream pis = new PipedInputStream();
- pos.connect(pis);
- ObjectOutputStream oos = new ObjectOutputStream(pos);
- marshaller.write(response, oos);
- pos.flush();
- pos.write(new byte[0]);
- pos.flush();
- ObjectInputStream ois = new ObjectInputStream(pis);
- try
+ if(marshaller instanceof MarshallerDecorator)
{
- oos.close();
- response = ois.readObject();
- ois.close();
+ response = ((MarshallerDecorator) marshaller).addDecoration(response);
}
- catch(ClassNotFoundException e)
+ else
{
- log.error("Could not marshall invocation response object " + response, e);
- throw new IOException(e.getMessage());
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ if (marshaller instanceof VersionedMarshaller)
+ ((VersionedMarshaller) marshaller).write(response, byteOut, getVersion());
+ else
+ marshaller.write(response, byteOut);
+
+ byteOut.close();
+ response = byteOut.toByteArray();
}
}
- */
-
return response;
}
+
+ public boolean isRmiOnewayMarshalling()
+ {
+ return rmiOnewayMarshalling;
+ }
+
+ public void setRmiOnewayMarshalling(boolean rmiOnewayMarshalling)
+ {
+ this.rmiOnewayMarshalling = rmiOnewayMarshalling;
+ }
}
16 years, 1 month
JBoss Remoting SVN: r3606 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-12 23:27:14 -0400 (Wed, 12 Mar 2008)
New Revision: 3606
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java
Log:
JBREM-167: Added ability to marshal/unmarshal in both directions.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java 2008-03-12 07:54:08 UTC (rev 3605)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/rmi/RMIClientInvoker.java 2008-03-13 03:27:14 UTC (rev 3606)
@@ -32,18 +32,23 @@
import org.jboss.remoting.RemoteClientInvoker;
import org.jboss.remoting.Remoting;
import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.Version;
import org.jboss.remoting.marshal.Marshaller;
import org.jboss.remoting.marshal.MarshallerDecorator;
import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.marshal.UnMarshallerDecorator;
import org.jboss.remoting.marshal.VersionedMarshaller;
+import org.jboss.remoting.marshal.VersionedUnMarshaller;
import org.jboss.remoting.marshal.rmi.RMIMarshaller;
+import org.jboss.remoting.marshal.rmi.RMIUnMarshaller;
+import org.jboss.remoting.serialization.SerializationManager;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.threadpool.RunnableTaskWrapper;
import org.jboss.util.threadpool.Task;
import org.jboss.util.threadpool.ThreadPool;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -92,6 +97,8 @@
private Object timeoutThreadPoolLock = new Object();
private ThreadPool timeoutThreadPool;
+
+ protected boolean rmiOnewayMarshalling;
/**
* Need flag to indicate if have been able to lookup registry and set stub.
@@ -105,14 +112,47 @@
public RMIClientInvoker(InvokerLocator locator)
{
super(locator);
+ configureParameters();
}
public RMIClientInvoker(InvokerLocator locator, Map configuration)
{
super(locator, configuration);
+ configureParameters();
}
+
+ protected void configureParameters()
+ {
+ Map params = configuration;
+ if (params == null)
+ {
+ return;
+ }
+ // look for enableTcpNoDelay param
+ Object val = params.get(RMIServerInvoker.RMI_ONEWAY_MARSHALLING);
+ if (val instanceof String)
+ {
+ try
+ {
+ rmiOnewayMarshalling = Boolean.valueOf((String)val).booleanValue();
+ log.debug(this + " setting rmiOnewayMarshalling to " + rmiOnewayMarshalling);
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + RMIServerInvoker.RMI_ONEWAY_MARSHALLING +
+ " value of " + val + " to a boolean value. Defaulting to false");
+ }
+ }
+ else if (val != null)
+ {
+ log.warn(this + " value of " + RMIServerInvoker.RMI_ONEWAY_MARSHALLING +
+ " (" + val + ") must be a String. Defaulting to false");
+ }
+ }
+
+
private int getRegistryPort(InvokerLocator locator)
{
int port = RMIServerInvoker.DEFAULT_REGISTRY_PORT;
@@ -303,19 +343,31 @@
((VersionedMarshaller) marshaller).write(payload, byteOut, getVersion());
else
marshaller.write(payload, byteOut);
- ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(byteIn);
+
+ byteOut.close();
+
+ if (rmiOnewayMarshalling)
+ {
+ // Legacy treatment, pre 2.4.0.
+ ByteArrayInputStream bais = new ByteArrayInputStream(byteOut.toByteArray());
+ SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
+ ObjectInputStream ois = manager.createInput(bais, getClassLoader());
- try
- {
- byteOut.close();
- payload = ois.readObject();
- ois.close();
+ try
+ {
+ byteOut.close();
+ payload = ois.readObject();
+ ois.close();
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.debug("Could not marshall invocation payload object " + payload, e);
+ throw new IOException(e.getMessage());
+ }
}
- catch(ClassNotFoundException e)
+ else
{
- log.debug("Could not marshall invocation payload object " + payload, e);
- throw new IOException(e.getMessage());
+ payload = byteOut.toByteArray();
}
}
}
@@ -323,7 +375,8 @@
int simulatedTimeout = getSimulatedTimeout(configuration, metadata);
if (simulatedTimeout <= 0)
{
- return server.transport(payload);
+ Object result = server.transport(payload);
+ return unmarshal(result, unmarshaller, metadata);
}
else
{
@@ -360,7 +413,7 @@
pool.runTaskWrapper(wrapper);
if (log.isTraceEnabled()) log.trace("task finished in thread pool");
- Object result = resultHolder.value;
+ Object result = unmarshal(resultHolder.value, unmarshaller, metadata);
if (result == null)
{
if (log.isTraceEnabled()) log.trace("invocation timed out");
@@ -381,38 +434,6 @@
return result;
}
}
-
-// Object response = server.transport(payload);
-
- /* Jira Issue: JBREM-167
- if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller))
- {
- PipedOutputStream pos = new PipedOutputStream();
- PipedInputStream pis = new PipedInputStream();
- pos.connect(pis);
- ObjectOutputStream oos = new ObjectOutputStream(pos);
- oos.writeObject(response);
- oos.flush();
- oos.reset();
- oos.writeObject(Boolean.TRUE);
- oos.flush();
- oos.reset();
- try
- {
- oos.close();
- response = unmarshaller.read(pis, metadata);
- pis.close();
- }
- catch(ClassNotFoundException e)
- {
- log.error("Could not unmarshall invocation response" + response, e);
- throw new IOException(e.getMessage());
- }
-
- }
- */
-
-// return response;
}
catch(RemoteException e)
{
@@ -459,6 +480,42 @@
}
+ protected Object unmarshal(Object o, UnMarshaller unmarshaller, Map metadata) throws IOException
+ {
+ Object result = o;
+ if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller) && !rmiOnewayMarshalling)
+ {
+ if(unmarshaller instanceof UnMarshallerDecorator)
+ {
+ result = ((UnMarshallerDecorator) unmarshaller).removeDecoration(o);
+ }
+ else
+ {
+ byte[] byteIn = (byte[]) o;
+ ByteArrayInputStream is = new ByteArrayInputStream(byteIn);
+
+ try
+ {
+ if (unmarshaller instanceof VersionedUnMarshaller)
+ {
+ result = ((VersionedUnMarshaller) unmarshaller).read(is, metadata, getVersion());
+ }
+ else
+ {
+ result = unmarshaller.read(is, metadata);
+ }
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.debug("Could not unmarshall invocation response" + o, e);
+ throw new IOException(e.getMessage());
+ }
+ }
+ }
+
+ return result;
+ }
+
/**
* Gets the thread pool being used for simulating timeouts. If one has
* not been specifically set via configuration or call to set it, will always return
16 years, 1 month