[jboss-cvs] JBoss Messaging SVN: r3656 - in trunk: src/main/org/jboss/jms/server/connectionmanager and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 1 07:37:33 EST 2008


Author: jmesnil
Date: 2008-02-01 07:37:33 -0500 (Fri, 01 Feb 2008)
New Revision: 3656

Added:
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/ConnectionExceptionNotifier.java
   trunk/tests/src/org/jboss/test/messaging/jms/network/
   trunk/tests/src/org/jboss/test/messaging/jms/network/ClientNetworkFailureTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/network/NetworkFailureFilter.java
Removed:
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/KeepAliveNotifier.java
Modified:
   trunk/src/main/org/jboss/jms/client/JBossConnection.java
   trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
   trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/ConnectionExceptionListener.java
   trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ClientKeepAliveTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ServerKeepAliveTest.java
Log:
* refactoring: added a NetworkFailureFilter to test network failure

Modified: trunk/src/main/org/jboss/jms/client/JBossConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnection.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/jms/client/JBossConnection.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -122,8 +122,16 @@
 
    public void close() throws JMSException
    {
-      connection.closing();
-      connection.close();
+      try
+      {
+         connection.closing();
+         connection.close();
+      } finally
+      {
+         // FIXME regardless of the pb when closing/close the connection, we must ensure
+         // the remoting connection is properly stopped
+         connection.getRemotingConnection().stop();
+      }
    }
 
    public ConnectionConsumer createConnectionConsumer(Destination destination,

Modified: trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -200,7 +200,7 @@
 
    // ConnectionExceptionListener ------------------------------------------------------------------
    
-   public void handleConnectionException(Exception e, String clientSessionID)
+   public void handleConnectionException(Throwable t, String clientSessionID)
    {
       handleClientFailure(clientSessionID , true);
    }

Modified: trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerImpl.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -211,6 +211,7 @@
          securityDeployer.start();
          queueSettingsDeployer.start();
          connectionManager.start();
+         remotingService.addConnectionExceptionListener(connectionManager);
          memoryManager.start();
          postOffice.start();
          ConnectionFactoryAdvisedPacketHandler connectionFactoryAdvisedPacketHandler =
@@ -258,6 +259,7 @@
          securityDeployer.stop();
          queueSettingsDeployer.stop();
          connectionManager.stop();
+         remotingService.removeConnectionExceptionListener(connectionManager);
          connectionManager = null;
          memoryManager.stop();
          memoryManager = null;

Modified: trunk/src/main/org/jboss/messaging/core/remoting/ConnectionExceptionListener.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/ConnectionExceptionListener.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/ConnectionExceptionListener.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -14,6 +14,6 @@
  */
 public interface ConnectionExceptionListener
 {
-   void handleConnectionException(Exception e, String sessionID);
+   void handleConnectionException(Throwable t, String sessionID);
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -23,5 +23,8 @@
    void addInterceptor(Interceptor interceptor);
 
    void removeInterceptor(Interceptor interceptor);
-   
+
+   void addConnectionExceptionListener(ConnectionExceptionListener listener);
+
+   void removeConnectionExceptionListener(ConnectionExceptionListener listener);  
 }

Added: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/ConnectionExceptionNotifier.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/ConnectionExceptionNotifier.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/ConnectionExceptionNotifier.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -0,0 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.mina;
+
+
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public interface ConnectionExceptionNotifier
+{
+   public abstract void fireConnectionException(Throwable t, String remoteSessionID);
+}
\ No newline at end of file

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/KeepAliveNotifier.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/KeepAliveNotifier.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/KeepAliveNotifier.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -1,21 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.impl.mina;
-
-import java.util.concurrent.TimeoutException;
-
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public interface KeepAliveNotifier
-{
-   public abstract void notifyKeepAliveTimeout(TimeoutException e, String remoteSessionID);
-}
\ No newline at end of file

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -19,7 +19,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeoutException;
 
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.ConnectFuture;
@@ -46,7 +45,7 @@
  * @version <tt>$Revision$</tt>
  * 
  */
-public class MinaConnector implements NIOConnector, KeepAliveNotifier
+public class MinaConnector implements NIOConnector, ConnectionExceptionNotifier
 {
    // Constants -----------------------------------------------------
 
@@ -104,7 +103,7 @@
 
    public NIOSession connect() throws IOException
    {
-      if (session != null)
+      if (session != null && session.isConnected())
       {
          return new MinaSession(session);
       }
@@ -184,9 +183,9 @@
       this.listener = listener;
    }
    
-   // KeepAliveManager implementation -------------------------------
+   // ConnectionExceptionNotifier implementation -------------------------------
    
-   public void notifyKeepAliveTimeout(TimeoutException cause, String remoteSessionID)
+   public void fireConnectionException(Throwable cause, String remoteSessionID)
    {
       if (listener != null)
          listener.handleConnectionException(cause, remoteSessionID);

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -6,6 +6,7 @@
  */
 package org.jboss.messaging.core.remoting.impl.mina;
 
+import java.io.IOException;
 import java.util.concurrent.TimeoutException;
 
 import org.apache.mina.common.IoHandlerAdapter;
@@ -36,16 +37,16 @@
 
    private final PacketDispatcher dispatcher;
 
-   private KeepAliveNotifier keepAliveManager;
+   private ConnectionExceptionNotifier connectionExceptionNotifier;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
    
-   public MinaHandler(PacketDispatcher dispatcher, KeepAliveNotifier keepAliveManager)
+   public MinaHandler(PacketDispatcher dispatcher, ConnectionExceptionNotifier keepAliveNotifier)
    {
       this.dispatcher = dispatcher;
-      this.keepAliveManager = keepAliveManager;
+      this.connectionExceptionNotifier = keepAliveNotifier;
    }
 
    // Public --------------------------------------------------------
@@ -56,12 +57,10 @@
    public void exceptionCaught(IoSession session, Throwable cause)
          throws Exception
    {
-      if (cause instanceof KeepAliveTimeoutException && keepAliveManager != null)
+      if (connectionExceptionNotifier != null)
       {
          String serverSessionID = Long.toString(session.getId());
-         TimeoutException e = new TimeoutException();
-         e.initCause(cause);
-         keepAliveManager.notifyKeepAliveTimeout(e, serverSessionID);
+         connectionExceptionNotifier.fireConnectionException(cause, serverSessionID);
       }
       // FIXME ugly way to know we're on the server side
       // close session only on the server side

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -14,18 +14,18 @@
 import static org.jboss.messaging.core.remoting.impl.mina.FilterChainSupport.addMDCFilter;
 
 import java.net.InetSocketAddress;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeoutException;
 
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
 import org.jboss.beans.metadata.api.annotations.Install;
 import org.jboss.beans.metadata.api.annotations.Uninstall;
 import org.jboss.messaging.core.remoting.ConnectionExceptionListener;
+import org.jboss.messaging.core.remoting.Interceptor;
 import org.jboss.messaging.core.remoting.KeepAliveFactory;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
-import org.jboss.messaging.core.remoting.Interceptor;
 import org.jboss.messaging.core.remoting.RemotingConfiguration;
 import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.util.Logger;
@@ -36,23 +36,23 @@
  * @version <tt>$Revision$</tt>
  * 
  */
-public class MinaService implements RemotingService, KeepAliveNotifier
+public class MinaService implements RemotingService, ConnectionExceptionNotifier
 {
    // Constants -----------------------------------------------------
 
    private static final Logger log = Logger.getLogger(MinaService.class);
 
-   public static final String DISABLE_INVM_KEY = "disable-invm";
-
    // Attributes ----------------------------------------------------
 
+   private boolean started = false;
+   
    private RemotingConfiguration remotingConfig;
    
    private NioSocketAcceptor acceptor;
 
    private PacketDispatcher dispatcher;
 
-   private ConnectionExceptionListener listener;
+   private List<ConnectionExceptionListener> listeners = new ArrayList<ConnectionExceptionListener>();
 
    private KeepAliveFactory factory;
    
@@ -89,13 +89,20 @@
       this.filters.remove(filter);
    }
 
-   public void setConnectionExceptionListener(ConnectionExceptionListener listener)
+   public void addConnectionExceptionListener(ConnectionExceptionListener listener)
    {
       assert listener != null;
 
-      this.listener = listener;
+      listeners.add(listener);
    }
-   
+
+   public void removeConnectionExceptionListener(ConnectionExceptionListener listener)
+   {
+      assert listener != null;
+
+      listeners.remove(listener);
+   }
+
    // TransportService implementation -------------------------------
 
    public void start() throws Exception
@@ -131,6 +138,8 @@
          if (!disableInvm)
             REGISTRY.register(remotingConfig, dispatcher);
       }
+      
+      started = true;
    }
 
    public void stop()
@@ -143,6 +152,8 @@
       }
       
       REGISTRY.unregister();
+      
+      started = false;
    }
 
    public PacketDispatcher getDispatcher()
@@ -154,15 +165,23 @@
    {
       return remotingConfig;
    }
+   
+   public DefaultIoFilterChainBuilder getFilterChain() 
+   {
+      assert started == true;
+      assert acceptor != null;
+      
+      return acceptor.getFilterChain();
+   }
 
-   // KeepAliveManager implementation -------------------------------
+   // ConnectionExceptionNotifier implementation -------------------------------
 
-   public void notifyKeepAliveTimeout(TimeoutException e, String remoteSessionID)
+   public void fireConnectionException(Throwable t, String remoteSessionID)
    {
-      if (listener != null)
+      for (ConnectionExceptionListener listener : listeners)
       {
          String clientSessionID = PacketDispatcher.sessions.get(remoteSessionID);
-         listener.handleConnectionException(e, clientSessionID);
+         listener.handleConnectionException(t, clientSessionID);
       }
    }
 
@@ -175,6 +194,13 @@
       this.factory = factory;
    }
 
+   public void setRemotingConfiguration(RemotingConfiguration remotingConfig)
+   {
+      assert started == false;
+      
+      this.remotingConfig = remotingConfig;
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ClientKeepAliveTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ClientKeepAliveTest.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ClientKeepAliveTest.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -77,12 +77,11 @@
 
       replay(factory);
 
-      
       final CountDownLatch latch = new CountDownLatch(1);
 
-      service.setConnectionExceptionListener(new ConnectionExceptionListener()
+      service.addConnectionExceptionListener(new ConnectionExceptionListener()
       {
-         public void handleConnectionException(Exception e, String sessionID)
+         public void handleConnectionException(Throwable e, String sessionID)
          {
             latch.countDown();
          }
@@ -114,9 +113,9 @@
       final String[] clientSessionIDNotResponding = new String[1];
       final CountDownLatch latch = new CountDownLatch(1);
 
-      service.setConnectionExceptionListener(new ConnectionExceptionListener()
+      service.addConnectionExceptionListener(new ConnectionExceptionListener()
       {
-         public void handleConnectionException(Exception e, String sessionID)
+         public void handleConnectionException(Throwable t, String sessionID)
          {
             clientSessionIDNotResponding[0] = sessionID;
             latch.countDown();
@@ -173,9 +172,9 @@
          final String[] clientSessionIDNotResponding = new String[1];
          final CountDownLatch latch = new CountDownLatch(1);
 
-         service.setConnectionExceptionListener(new ConnectionExceptionListener()
+         service.addConnectionExceptionListener(new ConnectionExceptionListener()
          {
-            public void handleConnectionException(Exception e, String sessionID)
+            public void handleConnectionException(Throwable t, String sessionID)
             {
                clientSessionIDNotResponding[0] = sessionID;
                latch.countDown();
@@ -216,9 +215,9 @@
       final String[] sessionIDNotResponding = new String[1];
       final CountDownLatch latch = new CountDownLatch(1);
 
-      service.setConnectionExceptionListener(new ConnectionExceptionListener()
+      service.addConnectionExceptionListener(new ConnectionExceptionListener()
       {
-         public void handleConnectionException(Exception e, String sessionID)
+         public void handleConnectionException(Throwable t, String sessionID)
          {
             sessionIDNotResponding[0] = sessionID;
             latch.countDown();

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ServerKeepAliveTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ServerKeepAliveTest.java	2008-01-31 20:26:32 UTC (rev 3655)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/ServerKeepAliveTest.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -82,7 +82,7 @@
  
       connector.setConnectionExceptionListener(new ConnectionExceptionListener()
       {
-         public void handleConnectionException(Exception e, String sessionID)
+         public void handleConnectionException(Throwable t, String sessionID)
          {
             sessionIDNotResponding[0] = sessionID;
             latch.countDown();

Added: trunk/tests/src/org/jboss/test/messaging/jms/network/ClientNetworkFailureTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/network/ClientNetworkFailureTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/network/ClientNetworkFailureTest.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -0,0 +1,213 @@
+/*
+ * 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.messaging.jms.network;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.KEEP_ALIVE_INTERVAL;
+import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.KEEP_ALIVE_TIMEOUT;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+
+import org.jboss.jms.server.ConnectionManager;
+import org.jboss.messaging.core.remoting.ConnectionExceptionListener;
+import org.jboss.messaging.core.remoting.RemotingConfiguration;
+import org.jboss.messaging.core.remoting.impl.mina.MinaService;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ClientNetworkFailureTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   private MinaService minaService;
+   private RemotingConfiguration originalRemotingConf;
+   private NetworkFailureFilter networkFailureFilter;
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ClientNetworkFailureTest(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      minaService = (MinaService) servers.get(0).getMessagingServer()
+            .getRemotingService();
+      originalRemotingConf = minaService.getRemotingConfiguration();
+      minaService.stop();
+      RemotingConfiguration oldRemotingConfig = minaService
+            .getRemotingConfiguration();
+      RemotingConfiguration newRemotingConfig = new RemotingConfiguration(
+            oldRemotingConfig);
+      newRemotingConfig.setInvmDisabled(true);
+      newRemotingConfig.setKeepAliveInterval(KEEP_ALIVE_INTERVAL);
+      newRemotingConfig.setKeepAliveTimeout(KEEP_ALIVE_TIMEOUT);
+      minaService.setRemotingConfiguration(newRemotingConfig);
+      minaService.start();
+
+      networkFailureFilter = new NetworkFailureFilter();
+      minaService.getFilterChain().addFirst("network-failure",
+            networkFailureFilter);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      minaService.getFilterChain().remove("network-failure");
+
+      minaService.stop();
+      minaService.setRemotingConfiguration(originalRemotingConf);
+      minaService.start();
+
+      super.tearDown();
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testServerResourcesCleanUpWhenClientCommThrowsException()
+         throws Exception
+   {
+      QueueConnection conn = getConnectionFactory().createQueueConnection();
+
+      assertActiveConnectionsOnTheServer(1);
+
+      final CountDownLatch exceptionLatch = new CountDownLatch(2);
+
+      conn.setExceptionListener(new ExceptionListener()
+      {
+
+         public void onException(JMSException e)
+         {
+            exceptionLatch.countDown();
+         }
+      });
+      ConnectionExceptionListener listener = new ListenerWithLatch(
+            exceptionLatch);
+      minaService.addConnectionExceptionListener(listener);
+
+      networkFailureFilter.messageSentThrowsException = new IOException(
+            "Client is unreachable");
+      networkFailureFilter.messageReceivedDropsPacket = true;
+
+      boolean gotExceptionsOnTheServerAndTheClient = exceptionLatch.await(
+            KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 2, SECONDS);
+      assertTrue(gotExceptionsOnTheServerAndTheClient);
+      assertActiveConnectionsOnTheServer(0);
+
+      try
+      {
+         conn.close();
+         fail("close should fail since client resources must have been cleaned up on the server side");
+      } catch (Exception e)
+      {
+      }
+
+      minaService.removeConnectionExceptionListener(listener);
+   }
+
+   public void testServerResourcesCleanUpWhenClientCommDropsPacket()
+         throws Exception
+   {
+      QueueConnection conn = getConnectionFactory().createQueueConnection();
+
+      final CountDownLatch exceptionLatch = new CountDownLatch(2);
+      conn.setExceptionListener(new ExceptionListener()
+      {
+         public void onException(JMSException e)
+         {
+            exceptionLatch.countDown();
+         }
+      });
+
+      ConnectionExceptionListener listener = new ListenerWithLatch(
+            exceptionLatch);
+      minaService.addConnectionExceptionListener(listener);
+
+      assertActiveConnectionsOnTheServer(1);
+
+      networkFailureFilter.messageSentDropsPacket = true;
+      networkFailureFilter.messageReceivedDropsPacket = true;
+
+      boolean gotExceptionsOnTheServerAndTheClient = exceptionLatch.await(
+            KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 2, SECONDS);
+      assertTrue(gotExceptionsOnTheServerAndTheClient);
+      assertActiveConnectionsOnTheServer(0);
+
+      try
+      {
+         conn.close();
+         fail("close should fail since client resources must have been cleaned up on the server side");
+      } catch (Exception e)
+      {
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private static void assertActiveConnectionsOnTheServer(int expectedSize)
+         throws Exception
+   {
+      ConnectionManager cm = servers.get(0).getMessagingServer()
+            .getConnectionManager();
+      assertEquals(expectedSize, cm.getActiveConnections().size());
+   }
+
+   // Inner classes -------------------------------------------------
+
+   private final class ListenerWithLatch implements ConnectionExceptionListener
+   {
+      private final CountDownLatch exceptionLatch;
+
+      private ListenerWithLatch(CountDownLatch exceptionLatch)
+      {
+         this.exceptionLatch = exceptionLatch;
+      }
+
+      public void handleConnectionException(Throwable e, String sessionID)
+      {
+         exceptionLatch.countDown();
+      }
+   }
+}

Added: trunk/tests/src/org/jboss/test/messaging/jms/network/NetworkFailureFilter.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/network/NetworkFailureFilter.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/network/NetworkFailureFilter.java	2008-02-01 12:37:33 UTC (rev 3656)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.messaging.jms.network;
+
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteRequest;
+
+final class NetworkFailureFilter extends IoFilterAdapter
+{
+   Exception messageSentThrowsException = null;
+   boolean messageSentDropsPacket = false;
+   boolean messageReceivedDropsPacket = false;
+
+   @Override
+   public void messageSent(NextFilter nextFilter, IoSession session,
+         WriteRequest writeRequest) throws Exception
+   {
+      if (messageSentThrowsException != null)
+      {
+         throw messageSentThrowsException;
+      } else if (messageSentDropsPacket)
+      {
+         // do nothing
+      } else
+      {
+         nextFilter.messageSent(session, writeRequest);
+      }
+   }
+
+   @Override
+   public void messageReceived(NextFilter nextFilter, IoSession session,
+         Object message) throws Exception
+   {
+      if (messageReceivedDropsPacket)
+      {
+         // do nothing
+      } else
+      {
+         super.messageReceived(nextFilter, session, message);
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list