[jboss-remoting-commits] JBoss Remoting SVN: r6099 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Sep 15 18:05:58 EDT 2010


Author: ron.sigal at 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 {



More information about the jboss-remoting-commits mailing list