JBoss Remoting SVN: r6108 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket: retriable and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-23 00:08:58 -0400 (Thu, 23 Sep 2010)
New Revision: 6108
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java
Log:
JBREM-1245: New unit test.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/retriable/SocketGeneralizedExceptionTestCase.java 2010-09-23 04:08:58 UTC (rev 6108)
@@ -0,0 +1,340 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.remoting.transport.socket.retriable;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLException;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1245.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Sep 22, 2010
+ * </p>
+ */
+public class SocketGeneralizedExceptionTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(SocketGeneralizedExceptionTestCase.class);
+
+ private static boolean firstTime = true;
+ protected static IOException exceptionToThrow;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+
+ TestOutputStream.counter = 0;
+ TestOutputStream.threwException = false;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testSSLException() throws Throwable
+ {
+ log.info("entering " + getName());
+ exceptionToThrow = new SSLException("Connection has been shutdown");
+ doTest();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConnectionResetException() throws Throwable
+ {
+ log.info("entering " + getName());
+ exceptionToThrow = new IOException("Connection reset by peer");
+ doTest();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConnectionClosedException() throws Throwable
+ {
+ log.info("entering " + getName());
+ exceptionToThrow = new IOException("Connection is closed");
+ doTest();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testBrokenPipeException() throws Throwable
+ {
+ log.info("entering " + getName());
+ exceptionToThrow = new IOException("Broken pipe");
+ doTest();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected void doTest() throws Throwable
+ {
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(2));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation works in spite of exception.
+ assertEquals("xyz", client.invoke("xyz"));
+ assertTrue(TestOutputStream.threwException);
+
+ client.disconnect();
+ shutdownServer();
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+ protected void addExtraServerConfig(Map config) {}
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?generalizeSocketException=true";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int initialSuccesses = 1;
+
+ public TestSocketFactory()
+ {
+ }
+ public TestSocketFactory(int initialSuccesses)
+ {
+ this.initialSuccesses = initialSuccesses;
+ }
+ public Socket createSocket()
+ {
+ Socket s = new TestSocket(initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ Socket s = new TestSocket(arg0, arg1, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ Socket s = new TestSocket(arg0, arg1, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ Socket s = new TestSocket(arg0, arg1, arg2, arg3, initialSuccesses);
+ log.info("returning " + s);
+ return s;
+ }
+ }
+
+
+ static class TestSocket extends Socket
+ {
+ int initialSuccesses;
+
+ public TestSocket(int initialWrites)
+ {
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(String host, int port, int initialWrites) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, int initialWrites) throws IOException
+ {
+ super(address, port);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.initialSuccesses = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int initialWrites) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.initialSuccesses = initialWrites;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), initialSuccesses);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+
+ static class TestOutputStream extends OutputStream
+ {
+ public static int counter;
+ public static boolean threwException;
+
+ OutputStream os;
+ boolean closed;
+ int initialWrites;
+ boolean doThrow = true;
+
+ public TestOutputStream(OutputStream os, int initialWrites)
+ {
+ this.os = os;
+ this.initialWrites = initialWrites;
+ }
+ public void write(int b) throws IOException
+ {
+ if (doThrow && ++counter == initialWrites)
+ {
+ log.info("throwing " + exceptionToThrow);
+ threwException = true;
+ throw exceptionToThrow;
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ log.info("TestOutputStream: counter = " + (counter + 1) + ", initialWrites = " + initialWrites);
+ if (++counter == initialWrites)
+ {
+ log.info("throwing " + exceptionToThrow);
+ threwException = true;
+ throw exceptionToThrow;
+ }
+ log.info(this + " calling write()");
+ doThrow = false;
+ os.write(b, off, len);
+ os.flush();
+ doThrow = true;
+ log.info(this + " back from write()");
+ }
+ }
+}
\ No newline at end of file
14 years, 2 months
JBoss Remoting SVN: r6107 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-23 00:08:05 -0400 (Thu, 23 Sep 2010)
New Revision: 6107
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1245: Added "connection shutdown" to RETRIABLE_ERROR_MESSAGE.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-09-23 04:05:40 UTC (rev 6106)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-09-23 04:08:05 UTC (rev 6107)
@@ -139,7 +139,7 @@
public static long serializeTime = 0;
public static long deserializeTime = 0;
- private static final String patternString = "^.*(?:connection.*reset|connection.*closed|broken.*pipe).*$";
+ private static final String patternString = "^.*(?:connection.*reset|connection.*closed|broken.*pipe|connection.*shutdown).*$";
private static final Pattern RETRIABLE_ERROR_MESSAGE = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
/**
14 years, 2 months
JBoss Remoting SVN: r6106 - remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-23 00:05:40 -0400 (Thu, 23 Sep 2010)
New Revision: 6106
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1245: Added "
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-09-15 22:12:24 UTC (rev 6105)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2010-09-23 04:05:40 UTC (rev 6106)
@@ -118,7 +118,7 @@
public static long serializeTime = 0;
public static long deserializeTime = 0;
- private static final String patternString = "^.*(?:connection.*reset|connection.*closed|broken.*pipe).*$";
+ private static final String patternString = "^.*(?:connection.*reset|connection.*closed|broken.*pipe|connection.*shutdown).*$";
private static final Pattern RETRIABLE_ERROR_MESSAGE = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
/**
14 years, 2 months
JBoss Remoting SVN: r6105 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:12:24 -0400 (Wed, 15 Sep 2010)
New Revision: 6105
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/RemoteClassTableWrapper.java
Log:
JBREM-1228: Wrapper used by RemoteClassTableTestCase.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/RemoteClassTableWrapper.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/RemoteClassTableWrapper.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/RemoteClassTableWrapper.java 2010-09-15 22:12:24 UTC (rev 6105)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3;
+
+import java.io.IOException;
+
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.remoting3.service.classtable.ClassLookupRequest;
+import org.jboss.remoting3.service.classtable.ClassLookupResponse;
+import org.jboss.remoting3.test.RemoteClassTableTestCase;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.log.Logger;
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ *
+ * Copyright Sep 8, 2010
+ */
+public class RemoteClassTableWrapper implements ClassTable {
+ public int classesWritten;
+ public int classesRead;
+ public Writer savedWriter;
+ public boolean writerMatches;
+ public int remoteResolutions;
+
+ private static final Logger log = Logger.getLogger(RemoteClassTableTestCase.class);
+
+ private RemoteClassTable remoteClassTable;
+
+ public RemoteClassTableWrapper(final Client<ClassLookupRequest, ClassLookupResponse> resolver) {
+ remoteClassTable = new RemoteClassTable(resolver);
+ }
+
+ public RemoteClassTableWrapper() {
+ remoteClassTable = new RemoteClassTable();
+ }
+
+ public Writer getClassWriter(Class<?> clazz) throws IOException {
+ Writer writer = remoteClassTable.getClassWriter(clazz);
+ if(classesWritten++ == 0) {
+ savedWriter = writer;
+ } else {
+ writerMatches = (writer == savedWriter);
+ }
+ log.info(this + " returning " + writer);
+ return writer;
+ }
+
+ public Class<?> readClass(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException {
+ Class<?> clazz = remoteClassTable.readClass(unmarshaller);
+ classesRead++;
+ log.info(this + " returning " + clazz);
+ return clazz;
+ }
+
+ public ClientListener<ClassLookupRequest, ClassLookupResponse> getClientListener() {
+ return new RctClientListenerWrapper();
+ }
+
+ private class RctClientListenerWrapper implements ClientListener<ClassLookupRequest, ClassLookupResponse> {
+ public RequestListener<ClassLookupRequest, ClassLookupResponse> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+ return new RctRequestListenerWrapper(remoteClassTable.getClientListener().handleClientOpen(clientContext, optionMap));
+ }
+ }
+
+ private class RctRequestListenerWrapper implements RequestListener<ClassLookupRequest, ClassLookupResponse> {
+ private RequestListener<ClassLookupRequest, ClassLookupResponse> rctRequestListener;
+
+ public RctRequestListenerWrapper(RequestListener<ClassLookupRequest, ClassLookupResponse> rctRequestListener) {
+ remoteResolutions++;
+ this.rctRequestListener = rctRequestListener;
+ }
+
+ public void handleRequest(final RequestContext<ClassLookupResponse> requestContext, final ClassLookupRequest request) throws RemoteExecutionException {
+ rctRequestListener.handleRequest(requestContext, request);
+ }
+ }
+}
14 years, 2 months
JBoss Remoting SVN: r6104 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:10:10 -0400 (Wed, 15 Sep 2010)
New Revision: 6104
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TestRequestListener.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TypedRequestObject.java
Log:
JBREM-1228: Classes used in tests.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TestRequestListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TestRequestListener.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TestRequestListener.java 2010-09-15 22:10:10 UTC (rev 6104)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @author tags. 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.remoting3.test;
+
+import java.io.IOException;
+
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.xnio.log.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ *
+ * Copyright Aug 28, 2010
+ */
+public class TestRequestListener implements RequestListener<InvocationTestObject, InvocationTestObject> {
+
+ private static final Logger log = Logger.getLogger(TestRequestListener.class);
+
+ private InvocationTestObject replyObject;
+
+ public TestRequestListener(InvocationTestObject replyObject) {
+ this.replyObject = replyObject;
+ }
+
+ public void handleRequest(final RequestContext<InvocationTestObject> objectRequestContext, final InvocationTestObject request) throws RemoteExecutionException {
+ try {
+ if (request.getAction().equals(InvocationTestObject.REPLY)) {
+ log.debug("Got request %s, sending reply %s", request, replyObject);
+ objectRequestContext.sendReply(replyObject);
+ } else if (request.getAction().equals(InvocationTestObject.FAILURE)) {
+ log.debug("Got request %s, sending failure", request);
+ objectRequestContext.sendFailure("failure", new TestRequestException());
+ } else if (request.getAction().equals(InvocationTestObject.CANCEL)) {
+ log.debug("Got request %s, sending cancel", request);
+ objectRequestContext.sendCancelled();
+ } else {
+ throw new RuntimeException("unexpected action: " + request.getAction());
+ }
+ } catch (IOException e) {
+ log.error(e, "reply");
+ throw new RemoteExecutionException(e);
+ }
+ }
+
+ public static class TestRequestException extends Exception {
+ private static final long serialVersionUID = 1L;
+ TestRequestException() {
+ super("", null);
+ }
+ }
+}
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TypedRequestObject.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TypedRequestObject.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/TypedRequestObject.java 2010-09-15 22:10:10 UTC (rev 6104)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test;
+
+import java.io.Serializable;
+
+import org.jboss.remoting3.TypedRequest;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright August 27, 2010
+ */
+public class TypedRequestObject implements TypedRequest<TypedRequestObject, InvocationTestObject>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private InvocationTestObject payload;
+
+ public TypedRequestObject(InvocationTestObject payload) {
+ this.payload = payload;
+ }
+
+ public InvocationTestObject castReply(Object reply) throws ClassCastException {
+ return InvocationTestObject.class.cast(reply);
+ }
+
+ public InvocationTestObject getPayload() {
+ return payload;
+ }
+}
14 years, 2 months
JBoss Remoting SVN: r6103 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:09:27 -0400 (Wed, 15 Sep 2010)
New Revision: 6103
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteClassTableTestCase.java
Log:
JBREM-1228: New unit test.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteClassTableTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteClassTableTestCase.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/RemoteClassTableTestCase.java 2010-09-15 22:09:27 UTC (rev 6103)
@@ -0,0 +1,283 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Random;
+
+import org.jboss.marshalling.ByteInput;
+import org.jboss.marshalling.ByteOutput;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.MarshallerFactory;
+import org.jboss.marshalling.Marshalling;
+import org.jboss.marshalling.MarshallingConfiguration;
+import org.jboss.marshalling.Unmarshaller;
+import org.jboss.marshalling.river.RiverMarshallerFactory;
+import org.jboss.remoting3.Client;
+import org.jboss.remoting3.Connection;
+import org.jboss.remoting3.Registration;
+import org.jboss.remoting3.RemoteClassTableWrapper;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.Endpoint.ServiceBuilder;
+import org.jboss.remoting3.service.classtable.ClassLookupRequest;
+import org.jboss.remoting3.service.classtable.ClassLookupResponse;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 7, 2010
+ */
+@Test(suiteName = "RemoteClassTable")
+public class RemoteClassTableTestCase extends RemotingTestBase {
+
+ private static final String RCT_INSTANCE_NAME = "rct_instancename";
+ private static final String RCT_SERVICE_TYPE = "rct_servicetype";
+ private static final Logger log = Logger.getLogger(RemoteClassTableTestCase.class);
+ private static int counter = Math.abs(new Random(new Date().getTime()).nextInt());
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() throws IOException {
+ }
+
+ @Test
+ public void testRemoteClassTableStandalone() throws Exception {
+ enter();
+
+ int idSender = counter++;
+ int idReceiver = counter++;
+ ServerPackage spSender = null;
+ ServerPackage spReceiver = null;
+ Registration reg = null;
+
+ try {
+
+ RequestListener<Object, Object> dummyRequestListener = new RequestListener<Object, Object>() {
+ public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException { /* unused */ }
+ };
+
+ // Set up RemoteClassTable service for sender.
+ spSender = setupServer(null, idSender, dummyRequestListener, "dummy", "dummy");
+ RemoteClassTableWrapper remoteClassTableWrapperSender = new RemoteClassTableWrapper();
+ ServiceBuilder<ClassLookupRequest, ClassLookupResponse> sb = spSender.endpoint.serviceBuilder(ClassLookupRequest.class, ClassLookupResponse.class);
+ sb.setInstanceName(RCT_INSTANCE_NAME).setServiceType(RCT_SERVICE_TYPE);
+ sb.setClientListener(remoteClassTableWrapperSender.getClientListener());
+ reg = sb.register();
+
+ // Set up RemoteClassTable for receiver.
+ spReceiver = setupServer(null, idReceiver, dummyRequestListener, "dummy", "dummy");
+ Connection connection = setupConnection(spReceiver, spSender);
+ Client<ClassLookupRequest, ClassLookupResponse> resolver = null;
+ resolver = getFutureResult(connection.openClient(RCT_SERVICE_TYPE, RCT_INSTANCE_NAME, ClassLookupRequest.class, ClassLookupResponse.class), "unable to create RCT client");
+ log.info("resolver: " + resolver);
+ RemoteClassTableWrapper remoteClassTableWrapperReceiver = new RemoteClassTableWrapper(resolver);
+
+ // Create muarshaller.
+ MarshallingConfiguration configSender = new MarshallingConfiguration();
+ configSender.setClassTable(remoteClassTableWrapperSender);
+ MarshallerFactory marshallerFactory = new RiverMarshallerFactory();
+ Marshaller marshaller = marshallerFactory.createMarshaller(configSender);
+
+ // Create unmarshaller
+ MarshallingConfiguration configReceiver = new MarshallingConfiguration();
+ configReceiver.setClassTable(remoteClassTableWrapperReceiver);
+ Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configReceiver);
+
+ // Marshal object.
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(10240);
+ ByteOutput byteOutput = Marshalling.createByteOutput(baos);
+ marshaller.start(byteOutput);
+ InvocationTestObject testObject = new InvocationTestObject();
+ marshaller.writeObject(testObject);
+ marshaller.finish();
+
+ // Unmarshal object.
+ byte[] bytes = baos.toByteArray();
+ ByteInput byteInput = Marshalling.createByteInput(new ByteArrayInputStream(bytes));
+ unmarshaller.start(byteInput);
+ Object result = unmarshaller.readObject();
+ unmarshaller.finish();
+
+ log.info("remoteClassTableWrapperSender.classesRead: " + remoteClassTableWrapperSender.classesRead);
+ log.info("remoteClassTableWrapperSender.classesWritten: " + remoteClassTableWrapperSender.classesWritten);
+ log.info("remoteClassTableWrapperReceiver.classesRead: " + remoteClassTableWrapperReceiver.classesRead);
+ log.info("remoteClassTableWrapperReceiver.classesWritten: " + remoteClassTableWrapperReceiver.classesWritten);
+ log.info("result: " + result);
+
+ assertEquals(testObject, result);
+ assertEquals(0, remoteClassTableWrapperSender.classesRead);
+ assertEquals(1, remoteClassTableWrapperSender.classesWritten);
+ assertEquals(1, remoteClassTableWrapperSender.remoteResolutions);
+ assertEquals(1, remoteClassTableWrapperReceiver.classesRead);
+ assertEquals(0, remoteClassTableWrapperReceiver.classesWritten);
+ assertEquals(0, remoteClassTableWrapperReceiver.remoteResolutions);
+ assertFalse(remoteClassTableWrapperSender.writerMatches);
+ assertFalse(remoteClassTableWrapperReceiver.writerMatches);
+
+ // Do it again.
+
+ // Create muarshaller.
+ marshaller = marshallerFactory.createMarshaller(configSender);
+
+ // Create unmarshaller
+ unmarshaller = marshallerFactory.createUnmarshaller(configReceiver);
+
+ // Marshal object.
+ baos = new ByteArrayOutputStream(10240);
+ byteOutput = Marshalling.createByteOutput(baos);
+ marshaller.start(byteOutput);
+ testObject = new InvocationTestObject();
+ marshaller.writeObject(testObject);
+ marshaller.finish();
+
+ // Unmarshal object.
+ bytes = baos.toByteArray();
+ byteInput = Marshalling.createByteInput(new ByteArrayInputStream(bytes));
+ unmarshaller.start(byteInput);
+ result = unmarshaller.readObject();
+ unmarshaller.finish();
+
+ log.info("remoteClassTableWrapperSender.classesRead: " + remoteClassTableWrapperSender.classesRead);
+ log.info("remoteClassTableWrapperSender.classesWritten: " + remoteClassTableWrapperSender.classesWritten);
+ log.info("remoteClassTableWrapperReceiver.classesRead: " + remoteClassTableWrapperReceiver.classesRead);
+ log.info("remoteClassTableWrapperReceiver.classesWritten: " + remoteClassTableWrapperReceiver.classesWritten);
+ log.info("result: " + result);
+
+ assertEquals(0, remoteClassTableWrapperSender.classesRead);
+ assertEquals(2, remoteClassTableWrapperSender.classesWritten);
+ assertEquals(1, remoteClassTableWrapperSender.remoteResolutions);
+ assertEquals(2, remoteClassTableWrapperReceiver.classesRead);
+ assertEquals(0, remoteClassTableWrapperReceiver.classesWritten);
+ assertEquals(0, remoteClassTableWrapperReceiver.remoteResolutions);
+ assertTrue(remoteClassTableWrapperSender.writerMatches);
+ assertFalse(remoteClassTableWrapperReceiver.writerMatches);
+ assertEquals(testObject, result);
+
+ log.info(getName() + " PASSES");
+ } finally {
+ if (reg != null) {
+ reg.close();
+ }
+ if (spReceiver != null) {
+ spReceiver.close();
+ }
+ if (spSender != null) {
+ spSender.close();
+ }
+ exit();
+ }
+ }
+
+// @Test
+// public void testRemoteClassTableAsService() throws Exception {
+// enter();
+//
+// int id0 = counter++;
+// int id1 = counter++;
+// ServerPackage sp0 = null;
+// ServerPackage sp1 = null;
+//
+// Registration reg0 = null;
+// Registration reg1 = null;
+//
+// try {
+//
+// // Set up "client" endpoint.
+// TestRequestListener testRequestListener0 = new TestRequestListener();
+// sp0 = setupServer(null, id0, testRequestListener0, "test0", "test0");
+//
+// // Set up "server" endpoint.
+// TestRequestListener testRequestListener1 = new TestRequestListener();
+// sp1 = setupServer(null, id1, testRequestListener1, "test1", "test1");
+//
+// // Set up RemoteClassTable service.
+// RemoteClassTableWrapper remoteClassTableWrapper1 = new RemoteClassTableWrapper();
+// ServiceBuilder<ClassLookupRequest, ClassLookupResponse> sb = sp1.endpoint.serviceBuilder(ClassLookupRequest.class, ClassLookupResponse.class);
+// sb.setInstanceName(RCT_INSTANCE_NAME).setServiceType(RCT_SERVICE_TYPE);
+// sb.setClientListener(remoteClassTableWrapper1.getClientListener());
+// reg1 = sb.register();
+//
+// // Set up RemoteClassTable client.
+// Connection connection = setupConnection(sp0, sp1);
+// Client<ClassLookupRequest, ClassLookupResponse> resolver = null;
+// resolver = getFutureResult(connection.openClient(RCT_SERVICE_TYPE, RCT_INSTANCE_NAME, ClassLookupRequest.class, ClassLookupResponse.class), "unable to create RCT client");
+// RemoteClassTableWrapper remoteClassTableWrapper0 = new RemoteClassTableWrapper(resolver);
+// reg0 = sp0.endpoint.addProtocolService(ProtocolServiceType.CLASS_TABLE, "remoteclasstable", remoteClassTableWrapper0);
+//
+// // Do invocation.
+// Client<InvocationTestObject, InvocationTestObject> client = getFutureResult(connection.openClient("test1", "test1", InvocationTestObject.class, InvocationTestObject.class), "unable to create client");
+// InvocationTestObject invocationObject = new InvocationTestObject();
+// assertEquals(invocationObject, client.invoke(invocationObject));
+// assertEquals(invocationObject, client.invoke(invocationObject));
+//
+// log.info("remoteClassTableWrapper0.classesRead: " + remoteClassTableWrapper0.classesRead);
+// log.info("remoteClassTableWrapper0.classesWritten: " + remoteClassTableWrapper0.classesWritten);
+// log.info("remoteClassTableWrapper1.classesRead: " + remoteClassTableWrapper1.classesRead);
+// log.info("remoteClassTableWrapper1.classesWritten: " + remoteClassTableWrapper1.classesWritten);
+//
+// log.info(getName() + " PASSES");
+// } finally {
+// if (reg0 != null) {
+// reg0.close();
+// }
+// if (reg1 != null) {
+// reg1.close();
+// }
+// if (sp0 != null) {
+// sp0.close();
+// }
+// if (sp1 != null) {
+// sp1.close();
+// }
+// exit();
+// }
+// }
+
+ static class TestRequestListener implements RequestListener<Object, Object> {
+
+ public void handleRequest(RequestContext<Object> context, Object request) throws RemoteExecutionException {
+ try {
+ context.sendReply(request);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
14 years, 2 months
JBoss Remoting SVN: r6102 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:08:56 -0400 (Wed, 15 Sep 2010)
New Revision: 6102
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalValueTestCase.java
Log:
JBREM-1228: Changed suiteName to "localValue".
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalValueTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalValueTestCase.java 2010-09-15 22:08:15 UTC (rev 6101)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalValueTestCase.java 2010-09-15 22:08:56 UTC (rev 6102)
@@ -29,7 +29,7 @@
import org.jboss.xnio.OptionMap;
import org.testng.annotations.Test;
-@Test(suiteName = "local")
+@Test(suiteName = "localValue")
public final class LocalValueTestCase extends InvocationTestBase {
protected Connection getConnection() throws IOException {
14 years, 2 months
JBoss Remoting SVN: r6101 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:08:15 -0400 (Wed, 15 Sep 2010)
New Revision: 6101
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalOneArgConnectTestCase.java
Log:
JBREM-1228: New unit test.
Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalOneArgConnectTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalOneArgConnectTestCase.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/LocalOneArgConnectTestCase.java 2010-09-15 22:08:15 UTC (rev 6101)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test;
+
+import java.io.IOException;
+import java.net.URI;
+import org.jboss.remoting3.Connection;
+import org.testng.annotations.Test;
+
+@Test(suiteName = "localOneArg")
+public final class LocalOneArgConnectTestCase extends InvocationTestBase {
+
+ protected Connection getConnection() throws IOException {
+ return endpoint.connect(URI.create("local:///")).get();
+ }
+}
14 years, 2 months
JBoss Remoting SVN: r6100 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:07:16 -0400 (Wed, 15 Sep 2010)
New Revision: 6100
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestObject.java
Log:
JBREM-1228: Added actions.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestObject.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestObject.java 2010-09-15 22:05:57 UTC (rev 6099)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestObject.java 2010-09-15 22:07:16 UTC (rev 6100)
@@ -25,23 +25,39 @@
import java.io.Serializable;
public final class InvocationTestObject implements Serializable {
- private static final long serialVersionUID = 7228470862155215008L;
- private final int frob = 12345;
+ public static final String REPLY = "reply";
+ public static final String FAILURE = "failure";
+ public static final String CANCEL = "cancel";
- public int getFrob() {
- return frob;
+ private static final long serialVersionUID = -6604871321606284771L;
+
+ private String action = REPLY;
+
+ public InvocationTestObject() {
}
+
+ public InvocationTestObject(String action) {
+ this.action = action;
+ }
+
+ public String getAction() {
+ return action;
+ }
public boolean equals(final Object obj) {
return obj instanceof InvocationTestObject && equals((InvocationTestObject) obj);
}
public boolean equals(final InvocationTestObject obj) {
- return obj != null && obj.frob == frob;
+ return obj != null && obj.action.equals(action);
}
public int hashCode() {
- return frob;
+ return action.hashCode();
}
+
+ public String toString() {
+ return "InvocationTestObject[" + System.identityHashCode(this) + ", " + action + "]";
+ }
}
14 years, 2 months
JBoss Remoting SVN: r6099 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-09-15 18:05:57 -0400 (Wed, 15 Sep 2010)
New Revision: 6099
Modified:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java
Log:
JBREM-1228: Added test methods; refactored RequestListener to separate class.
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java 2010-09-07 20:55:43 UTC (rev 6098)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java 2010-09-15 22:05:57 UTC (rev 6099)
@@ -37,11 +37,13 @@
import org.jboss.remoting3.Endpoint;
import org.jboss.remoting3.Registration;
import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.RemoteReplyException;
import org.jboss.remoting3.Remoting;
import org.jboss.remoting3.RequestContext;
import org.jboss.remoting3.RequestListener;
import org.jboss.remoting3.ServiceNotFoundException;
import org.jboss.remoting3.stream.Streams;
+import org.jboss.xnio.IoFuture;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.OptionMap;
import org.jboss.xnio.Options;
@@ -101,16 +103,7 @@
log.info("Client closed");
}
});
- return new RequestListener<InvocationTestObject, InvocationTestObject>() {
- public void handleRequest(final RequestContext<InvocationTestObject> objectRequestContext, final InvocationTestObject request) throws RemoteExecutionException {
- try {
- log.info("Got request %s, sending reply %s", request, replyObj);
- objectRequestContext.sendReply(replyObj);
- } catch (IOException e) {
- throw new RemoteExecutionException(e);
- }
- }
- };
+ return new TestRequestListener(replyObj);
}
}).register();
try {
@@ -136,6 +129,55 @@
}
}
+ public void testTypedInvoke() throws Exception {
+ enter();
+ try {
+ final InvocationTestObject requestObj = new InvocationTestObject();
+ final TypedRequestObject typedRequestObj = new TypedRequestObject(requestObj);
+ final InvocationTestObject replyObj = new InvocationTestObject();
+ final Registration registration = endpoint.serviceBuilder().setInstanceName("foo").setServiceType("test1").setRequestType(TypedRequestObject.class).
+ setReplyType(InvocationTestObject.class).setClientListener(new ClientListener<TypedRequestObject, InvocationTestObject>() {
+ public RequestListener<TypedRequestObject, InvocationTestObject> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+ clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
+ public void handleClose(final ClientContext closed) {
+ log.debug("Client closed");
+ }
+ });
+ return new RequestListener<TypedRequestObject, InvocationTestObject>() {
+ public void handleRequest(final RequestContext<InvocationTestObject> objectRequestContext, final TypedRequestObject request) throws RemoteExecutionException {
+ try {
+ log.debug("Got request %s, sending reply %s", request, replyObj);
+ objectRequestContext.sendReply(replyObj);
+ } catch (IOException e) {
+ throw new RemoteExecutionException(e);
+ }
+ }
+ };
+ }
+ }).register();
+ try {
+ final Connection connection = getConnection();
+ try {
+ final Client<TypedRequestObject, InvocationTestObject> client = connection.openClient("test1", "*", TypedRequestObject.class, InvocationTestObject.class, getClass().getClassLoader(), OptionMap.EMPTY).get();
+ try {
+ assertEquals(replyObj, client.invokeTyped(typedRequestObj));
+ } finally {
+ IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
+ }
+ } finally {
+ exit();
+ }
+ }
+
public void testBasicSend() throws Exception {
enter();
try {
@@ -149,17 +191,7 @@
log.info("Listener closed");
}
});
- return new RequestListener<InvocationTestObject, InvocationTestObject>() {
- public void handleRequest(final RequestContext<InvocationTestObject> objectRequestContext, final InvocationTestObject request) throws RemoteExecutionException {
- try {
- log.info("Got request %s, sending reply %s", request, replyObj);
- objectRequestContext.sendReply(replyObj);
- } catch (IOException e) {
- log.error(e, "reply");
- throw new RemoteExecutionException(e);
- }
- }
- };
+ return new TestRequestListener(replyObj);
}
}).register();
try {
@@ -185,6 +217,164 @@
}
}
+ public void testBasicSendFailure() throws Exception {
+ enter();
+ try {
+ final InvocationTestObject requestObj = new InvocationTestObject(InvocationTestObject.FAILURE);
+ final InvocationTestObject replyObj = new InvocationTestObject();
+ final Registration registration = endpoint.serviceBuilder().setInstanceName("foo").setServiceType("test2").setRequestType(InvocationTestObject.class).
+ setReplyType(InvocationTestObject.class).setClientListener(new ClientListener<InvocationTestObject, InvocationTestObject>() {
+ public RequestListener<InvocationTestObject, InvocationTestObject> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+ clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
+ public void handleClose(final ClientContext closed) {
+ log.debug("Listener closed");
+ }
+ });
+ return new TestRequestListener(replyObj);
+ }
+ }).register();
+ try {
+ final Connection connection = getConnection();
+ try {
+ final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
+ try {
+ log.info("sending FAILURE request");
+ IoFuture<? extends InvocationTestObject> future = client.send(requestObj);
+ Object o = future.get();
+ fail("expected RemoteReplyException: got " + o);
+ } catch (RemoteReplyException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof RemoteExecutionException) {
+ RemoteExecutionException ree = (RemoteExecutionException) cause;
+ if ("failure".equals(ree.getMessage()) && ree.getCause() instanceof TestRequestListener.TestRequestException) {
+ log.info("got expected exception: " + e + "(" + e.getMessage() + ", " + e.getCause() + ")");
+ } else {
+ fail("expected RemoteReplyException(RemoteExecutionException(\"failure\")), got: " + e);
+ }
+ } else {
+ fail("expected RemoteReplyException(RemoteExecutionException), got: " + e);
+ }
+ } catch (RemoteExecutionException e) {
+ if ("failure".equals(e.getMessage())) {
+ log.info("got expected exception: " + e + "(" + e.getMessage() + ", " + e.getCause() + ")");
+ } else {
+ fail("expected RemoteExecutionException(\"failure\"), got: " + e);
+ }
+ } catch (Exception e) {
+ fail("expected RemoteExecutionException: got " + e);
+ }
+ finally {
+ IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
+ }
+ } finally {
+ exit();
+ }
+ }
+
+ public void testBasicSendCancel() throws Exception {
+ enter();
+ try {
+ final InvocationTestObject requestObj = new InvocationTestObject(InvocationTestObject.CANCEL);
+ final InvocationTestObject replyObj = new InvocationTestObject();
+ final Registration registration = endpoint.serviceBuilder().setInstanceName("foo").setServiceType("test2").setRequestType(InvocationTestObject.class).
+ setReplyType(InvocationTestObject.class).setClientListener(new ClientListener<InvocationTestObject, InvocationTestObject>() {
+ public RequestListener<InvocationTestObject, InvocationTestObject> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+ clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
+ public void handleClose(final ClientContext closed) {
+ log.debug("Listener closed");
+ }
+ });
+ return new TestRequestListener(replyObj);
+ }
+ }).register();
+ try {
+ final Connection connection = getConnection();
+ try {
+ final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
+ try {
+ log.info("sending CANCEL request");
+ IoFuture<? extends InvocationTestObject> future = client.send(requestObj);
+ } catch (RemoteReplyException e) {
+ log.info("got expected exception: " + e + "(" + e.getMessage() + ", " + e.getCause() + ")");
+ } catch (Exception e) {
+ fail("expected RemoteReplyException: got " + e);
+ }
+ finally {
+ IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
+ }
+ } finally {
+ exit();
+ }
+ }
+
+ public void testTypedSend() throws Exception {
+ enter();
+ try {
+ final InvocationTestObject requestObj = new InvocationTestObject();
+ final TypedRequestObject typedRequestObj = new TypedRequestObject(requestObj);
+ final InvocationTestObject replyObj = new InvocationTestObject();
+ final Registration registration = endpoint.serviceBuilder().setInstanceName("foo").setServiceType("test2").setRequestType(TypedRequestObject.class).
+ setReplyType(InvocationTestObject.class).setClientListener(new ClientListener<TypedRequestObject, InvocationTestObject>() {
+ public RequestListener<TypedRequestObject, InvocationTestObject> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+ clientContext.addCloseHandler(new CloseHandler<ClientContext>() {
+ public void handleClose(final ClientContext closed) {
+ log.debug("Listener closed");
+ }
+ });
+ return new RequestListener<TypedRequestObject, InvocationTestObject>() {
+ public void handleRequest(final RequestContext<InvocationTestObject> objectRequestContext, final TypedRequestObject request) throws RemoteExecutionException {
+ try {
+ log.debug("Got request %s, sending reply %s", request, replyObj);
+ objectRequestContext.sendReply(replyObj);
+ } catch (IOException e) {
+ log.error(e, "reply");
+ throw new RemoteExecutionException(e);
+ }
+ }
+ };
+ }
+ }).register();
+ try {
+ final Connection connection = getConnection();
+ try {
+ final Client<TypedRequestObject, InvocationTestObject> client = connection.openClient("test2", "*", TypedRequestObject.class, InvocationTestObject.class).get();
+ try {
+ assertEquals(replyObj, client.sendTyped(typedRequestObj).get());
+ } finally {
+ IoUtils.safeClose(client);
+ client.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(connection);
+ connection.awaitClosedUninterruptibly();
+ }
+ } finally {
+ IoUtils.safeClose(registration);
+ registration.awaitClosedUninterruptibly();
+ }
+ } finally {
+ exit();
+ }
+ }
+
public void testBasicClientConnector() throws Exception {
enter();
try {
14 years, 2 months