[jboss-remoting-commits] JBoss Remoting SVN: r4288 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Jun 10 23:15:34 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-06-10 23:15:34 -0400 (Tue, 10 Jun 2008)
New Revision: 4288

Modified:
   remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java
   remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java
Log:
JBREM-954: Test for wrapping InterruptedException in a RuntimeException configuration.

Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java	2008-06-11 03:14:38 UTC (rev 4287)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java	2008-06-11 03:15:34 UTC (rev 4288)
@@ -90,7 +90,7 @@
    }
    
    
-   public void testInterruptedException() throws Throwable
+   public void testNotWrappedInterruptedExceptionDefault() throws Throwable
    {
       log.info("entering " + getName());
       
@@ -139,9 +139,133 @@
          t2.wait(10000);
       }
       
-      // Verify exception is an InterruptedException wrapped in a RuntimeExceptio.
+      // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
       Throwable t = t2.throwable;
       log.info("throwable: " + t);
+      assertTrue(t instanceof CannotConnectException);
+      assertTrue(t.getCause() instanceof InterruptedException);
+      
+      client.disconnect();
+      shutdownServer();
+      log.info(getName() + " PASSES");
+   }
+   
+   
+   public void testNotWrappedInterruptedExceptionConfigured() throws Throwable
+   {
+      log.info("entering " + getName());
+      
+      // Start server.
+      setupServer();
+      
+      // Create client.
+      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+      HashMap clientConfig = new HashMap();
+      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+      clientConfig.put("numberOfCallRetries", "1");
+      clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "false");
+      addExtraClientConfig(clientConfig);
+      Client client = new Client(clientLocator, clientConfig);
+      client.connect();
+      log.info("client is connected");
+      
+      // Test connections.
+      assertEquals(FAST, client.invoke(FAST));
+      log.info("connection is good");
+      
+      InvokerThread t1 = new InvokerThread(client, "abc");
+      InvokerThread t2 = new InvokerThread(client, "xyz");
+      
+      // Start first invocation.
+      t1.start();
+      log.info("started first invocation");
+      
+      // Give first invocation time to start.
+      Thread.sleep(5000);
+      
+      // Start second invocation.
+      t2.start();
+      log.info("started second invocation");
+      
+      // Give second invocation time to start.
+      Thread.sleep(5000);
+      
+      // Interrupt second invocation as it waits for a semaphore.
+      t2.interrupt();
+      log.info("interrupted second invocation");
+
+      // Wait until second invocation throws an exception.
+      synchronized (t2)
+      {
+         t2.wait(10000);
+      }
+      
+      // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
+      Throwable t = t2.throwable;
+      log.info("throwable: " + t);
+      assertTrue(t instanceof CannotConnectException);
+      assertTrue(t.getCause() instanceof InterruptedException);
+      
+      client.disconnect();
+      shutdownServer();
+      log.info(getName() + " PASSES");
+   }
+   
+   
+   public void testWrappedInterruptedException() throws Throwable
+   {
+      log.info("entering " + getName());
+      
+      // Start server.
+      setupServer();
+      
+      // Create client.
+      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+      HashMap clientConfig = new HashMap();
+      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+      clientConfig.put("numberOfCallRetries", "1");
+      clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "true");
+      addExtraClientConfig(clientConfig);
+      Client client = new Client(clientLocator, clientConfig);
+      client.connect();
+      log.info("client is connected");
+      
+      // Test connections.
+      assertEquals(FAST, client.invoke(FAST));
+      log.info("connection is good");
+      
+      InvokerThread t1 = new InvokerThread(client, "abc");
+      InvokerThread t2 = new InvokerThread(client, "xyz");
+      
+      // Start first invocation.
+      t1.start();
+      log.info("started first invocation");
+      
+      // Give first invocation time to start.
+      Thread.sleep(5000);
+      
+      // Start second invocation.
+      t2.start();
+      log.info("started second invocation");
+      
+      // Give second invocation time to start.
+      Thread.sleep(5000);
+      
+      // Interrupt second invocation as it waits for a semaphore.
+      t2.interrupt();
+      log.info("interrupted second invocation");
+
+      // Wait until second invocation throws an exception.
+      synchronized (t2)
+      {
+         t2.wait(10000);
+      }
+      
+      // Verify exception is an InterruptedException wrapped in a RuntimeException.
+      Throwable t = t2.throwable;
+      log.info("throwable: " + t);
       assertTrue(t instanceof RuntimeException);
       assertFalse(t instanceof CannotConnectException);
       assertTrue(t.getCause() instanceof InterruptedException);

Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java	2008-06-11 03:14:38 UTC (rev 4287)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java	2008-06-11 03:15:34 UTC (rev 4288)
@@ -21,6 +21,9 @@
  */
 package org.jboss.test.remoting.transport.socket.interrupt;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
 import org.apache.log4j.Logger;
@@ -43,9 +46,11 @@
 {
    private static final Logger log = Logger.getLogger(MockInvokerInterruptTestCase.class);
    
-   public void test000() throws Throwable
+   public void testWrappedException() throws Throwable
    {
-      InvokerLocator il = new InvokerLocator("unittest", "127.0.0.1", 9999, "mock", null);
+      Map parameters = new HashMap();
+      parameters.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "true");
+      InvokerLocator il = new InvokerLocator("unittest", "127.0.0.1", 9999, "mock", parameters);
       CountDown startGate = new CountDown(1);
       MockMicroSocketClientInvoker ci = new MockMicroSocketClientInvoker(il, startGate);
       InvocationRequest ir = new InvocationRequest("", "", null, null, null, il);
@@ -70,7 +75,63 @@
          assertTrue(re.getCause() instanceof InterruptedException);
       }
    }
+   
+   public void testNotWrappedExceptionDefault() throws Throwable
+   {
+      InvokerLocator il = new InvokerLocator("unittest", "127.0.0.1", 9999, "mock", null);
+      CountDown startGate = new CountDown(1);
+      MockMicroSocketClientInvoker ci = new MockMicroSocketClientInvoker(il, startGate);
+      InvocationRequest ir = new InvocationRequest("", "", null, null, null, il);
+      
+      Runnable interrupterRunnable = new ThreadInterrupter(Thread.currentThread(), startGate);
+      Thread interrupter = new Thread(interrupterRunnable);
+      interrupter.start();
+      
+      ci.setMaxPoolSize(0);
+      ci.connect();
+      try
+      {
+         ci.invoke(ir);
+      }
+      catch(CannotConnectException cce)
+      {
+         log.info("got expected CannotConnectException");
+      }
+      catch (RuntimeException re)
+      {
+         fail("expected CannotConnectException");
+      }
+   }
 
+   public void testNotWrappedExceptionConfigured() throws Throwable
+   {
+      Map parameters = new HashMap();
+      parameters.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "false");
+      InvokerLocator il = new InvokerLocator("unittest", "127.0.0.1", 9999, "mock", parameters);
+      CountDown startGate = new CountDown(1);
+      MockMicroSocketClientInvoker ci = new MockMicroSocketClientInvoker(il, startGate);
+      InvocationRequest ir = new InvocationRequest("", "", null, null, null, il);
+      
+      Runnable interrupterRunnable = new ThreadInterrupter(Thread.currentThread(), startGate);
+      Thread interrupter = new Thread(interrupterRunnable);
+      interrupter.start();
+      
+      ci.setMaxPoolSize(0);
+      ci.connect();
+      try
+      {
+         ci.invoke(ir);
+      }
+      catch(CannotConnectException cce)
+      {
+         log.info("got expected CannotConnectException");
+      }
+      catch (RuntimeException re)
+      {
+         fail("expected CannotConnectException");
+      }
+   }
+   
    class MockMicroSocketClientInvoker extends MicroSocketClientInvoker
    {
       private CountDown startGate;




More information about the jboss-remoting-commits mailing list