[jboss-remoting-commits] JBoss Remoting SVN: r6149 - 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
Sat Nov 13 11:39:49 EST 2010


Author: ron.sigal at jboss.com
Date: 2010-11-13 11:39:49 -0500 (Sat, 13 Nov 2010)
New Revision: 6149

Modified:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java
Log:
JBREM-1256: Changed getConnection() to getConnection(String); JBREM-1228: added testBasicSendFailureNPE().

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-11-13 16:35:15 UTC (rev 6148)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/InvocationTestBase.java	2010-11-13 16:39:49 UTC (rev 6149)
@@ -27,6 +27,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Date;
+import java.util.Random;
 import java.util.concurrent.atomic.AtomicReference;
 import org.jboss.remoting3.Client;
 import org.jboss.remoting3.ClientConnector;
@@ -56,14 +59,17 @@
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 @Test
 public abstract class InvocationTestBase {
     private static final Logger log = Logger.getLogger("test");
+    private static Random random = new Random(new Date().getTime());
 
     protected Endpoint endpoint;
+    protected String xnioName;
 
     @BeforeTest
     public void setUp() throws IOException {
@@ -71,7 +77,11 @@
         enter();
         try {
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-            endpoint = Remoting.getConfiguredEndpoint();
+            String s = "xnio" + String.valueOf(Math.abs(random.nextInt()));
+            log.info(this + " creating xnio: " + s);
+            OptionMap optionMap = OptionMap.builder().set(RemotingRootTestBase.XNIO_ID, s).getMap();
+            endpoint = Remoting.getConfiguredEndpoint(optionMap);
+            log.info("created XNIO: " + xnioName);
         } finally {
             exit();
         }
@@ -88,7 +98,7 @@
         log.info("-------------------------------------------------------------");
     }
 
-    protected abstract Connection getConnection() throws Exception;
+    protected abstract Connection getConnection(String xnioName) throws Exception;
 
     public void testBasicInvoke() throws Exception {
         enter();
@@ -107,7 +117,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test1", "*", InvocationTestObject.class, InvocationTestObject.class, getClass().getClassLoader(), OptionMap.EMPTY).get();
                     try {
@@ -156,7 +166,7 @@
              }
           }).register();
           try {
-             final Connection connection = getConnection();
+             final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
              try {
                 final Client<TypedRequestObject, InvocationTestObject> client = connection.openClient("test1", "*", TypedRequestObject.class, InvocationTestObject.class, getClass().getClassLoader(), OptionMap.EMPTY).get();
                 try {
@@ -195,7 +205,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
                     try {
@@ -234,7 +244,7 @@
                }
            }).register();
            try {
-               final Connection connection = getConnection();
+               final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                try {
                    final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
                    try {
@@ -280,6 +290,73 @@
        }
     }
 
+    /**
+     * Tests for race between handling RemoteProtocol.REQUEST and RemoteProtocol.CLIENT_CLOSE in
+     * RemoteMessageHandler.  See JBREM-1257.
+     */
+    public void testBasicSendFailureNPE() 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(String.valueOf(Math.abs(random.nextInt())));
+               try {
+                   final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
+                   try {
+                       log.info("sending FAILURE request");
+                       PrintStream savedOutPrintStream = System.out;
+                       PrintStream savedERRPrintStream = System.err;
+                       ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
+                       ByteArrayOutputStream baosErr = new ByteArrayOutputStream();
+                       System.setOut(new PrintStream(baosOut));
+                       System.setErr(new PrintStream(baosErr));
+                       client.send(requestObj);
+                       baosOut.flush();
+                       baosErr.flush();
+                       String logOut = baosOut.toString();
+                       String logErr = baosErr.toString();
+                       System.setOut(savedOutPrintStream);
+                       System.setErr(savedERRPrintStream);
+                       System.out.println("+++++++++++++++ LOG.OUT +++++++++++++++++++");
+                       System.out.println(logOut);
+                       System.out.println("+++++++++++++++ LOG.OUT +++++++++++++++++++");
+                       System.out.println("+++++++++++++++ LOG.ERR +++++++++++++++++++");
+                       System.out.println(logErr);
+                       System.out.println("+++++++++++++++ LOG.ERR +++++++++++++++++++");
+                       assertFalse(logOut.contains("NullPointerException"));
+                       assertFalse(logErr.contains("NullPointerException"));
+                   } catch (Exception e) {
+                      fail("didn't expect an exception: " + e.getMessage());
+                   }
+                   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 {
@@ -297,7 +374,7 @@
              }
           }).register();
           try {
-             final Connection connection = getConnection();
+             final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
              try {
                 final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test2", "*", InvocationTestObject.class, InvocationTestObject.class).get();
                 try {
@@ -353,7 +430,7 @@
              }
           }).register();
           try {
-             final Connection connection = getConnection();
+             final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
              try {
                 final Client<TypedRequestObject, InvocationTestObject> client = connection.openClient("test2", "*", TypedRequestObject.class, InvocationTestObject.class).get();
                 try {
@@ -403,7 +480,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<ClientConnector, InvocationTestObject> client = connection.openClient("test3", "*", ClientConnector.class, InvocationTestObject.class).get();
                     try {
@@ -451,7 +528,7 @@
     public void testNotFoundService() throws Throwable {
         enter();
         try {
-            final Connection connection = getConnection();
+            final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
             try {
                 connection.openClient("blah", "bzzt", Object.class, Object.class).get();
             } catch (ServiceNotFoundException e) {
@@ -487,7 +564,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<InvocationTestObject, InvocationTestObject> client = connection.openClient("test1", "*", InvocationTestObject.class, InvocationTestObject.class, getClass().getClassLoader(), optionMap).get();
                     try {
@@ -541,7 +618,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<InputStream, InputStream> client = connection.openClient("streamtest", "*", InputStream.class, InputStream.class, InvocationTestBase.class.getClassLoader(), OptionMap.EMPTY).get();
                     try {
@@ -592,7 +669,7 @@
                 }
             }).register();
             try {
-                final Connection connection = getConnection();
+                final Connection connection = getConnection(String.valueOf(Math.abs(random.nextInt())));
                 try {
                     final Client<OutputStream, OutputStream> client = connection.openClient("streamtest", "*", OutputStream.class, OutputStream.class, InvocationTestBase.class.getClassLoader(), OptionMap.EMPTY).get();
                     try {
@@ -623,7 +700,7 @@
     public void tearDown() throws IOException {
         enter();
         try {
-            Xnio.getInstance().close();
+            Xnio.getInstance(xnioName).close();
             System.runFinalization();
         } finally {
             exit();



More information about the jboss-remoting-commits mailing list