[jboss-cvs] JBoss Messaging SVN: r4394 - in trunk/tests/src/org/jboss/messaging/tests/unit: core/remoting/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 5 10:25:18 EDT 2008


Author: jmesnil
Date: 2008-06-05 10:25:18 -0400 (Thu, 05 Jun 2008)
New Revision: 4394

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ConnectionManagerTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/INVMServerTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/network/
   trunk/tests/src/org/jboss/messaging/tests/unit/jms/server/
Log:
moved tests

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ConnectionManagerTest.java (from rev 4392, trunk/tests/src/org/jboss/messaging/tests/unit/jms/server/ConnectionManagerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ConnectionManagerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/ConnectionManagerTest.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -0,0 +1,115 @@
+/*
+  * 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.messaging.tests.unit.core.remoting.impl;
+
+
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.server.ConnectionManager;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ConnectionManagerTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   private MessagingServerImpl server;
+   // Constructors --------------------------------------------------
+
+   public ConnectionManagerTest(String name)
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception
+   {
+      ConfigurationImpl config = new ConfigurationImpl();
+      config.setTransport(TransportType.INVM);
+      server = new MessagingServerImpl(config);
+      server.start();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      if(server != null)
+      {
+         server.stop();
+         server = null;
+      }
+   }
+
+
+
+   // TestCase overrides -------------------------------------------
+
+   // Public --------------------------------------------------------
+   
+   public void testTwoConnectionsFromTheSameVM() throws Exception
+   {
+      
+      assertActiveConnectionsOnTheServer(0);
+      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(0));
+
+      ClientConnection conn_1 = cf.createConnection();
+      
+      assertActiveConnectionsOnTheServer(1);
+      
+      ClientConnection conn_2 = cf.createConnection();
+      
+      assertActiveConnectionsOnTheServer(2);
+      
+      assertFalse(conn_1.equals(conn_2));
+      
+      conn_1.close();
+      
+      assertActiveConnectionsOnTheServer(1);
+      
+      conn_2.close();
+      
+      assertActiveConnectionsOnTheServer(0);
+   }
+
+   private void assertActiveConnectionsOnTheServer(int expectedSize)
+   throws Exception
+   {
+      ConnectionManager cm = server
+      .getConnectionManager();
+      assertEquals(expectedSize, cm.getActiveConnections().size());
+   }
+
+}

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/INVMServerTest.java (from rev 4392, trunk/tests/src/org/jboss/messaging/tests/unit/jms/server/INVMServerTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/INVMServerTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/INVMServerTest.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -0,0 +1,83 @@
+package org.jboss.messaging.tests.unit.core.remoting.impl;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientConnectionInternal;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossConnection;
+
+import junit.framework.TestCase;
+
+public class INVMServerTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServerImpl server_1;
+   private MessagingServerImpl server_2;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testConnectionsToTwoINVMServers() throws Exception
+   {
+      ClientConnectionFactory cf_1 = new ClientConnectionFactoryImpl(
+            new LocationImpl(0));
+      ClientConnectionInternal conn_1 = (ClientConnectionInternal) cf_1.createConnection();
+
+      ClientConnectionFactory cf_2 = new ClientConnectionFactoryImpl(
+            new LocationImpl(1));
+      ClientConnectionInternal conn_2 = (ClientConnectionInternal) cf_2.createConnection();
+      
+      assertNotSame(conn_1.getRemotingConnection().getSessionID(), conn_2.getRemotingConnection().getSessionID());
+
+      conn_1.close();
+      conn_2.close();      
+}
+
+   // TestCase overrides --------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      ConfigurationImpl config = new ConfigurationImpl();
+      config.setServerID(0);
+      config.setTransport(TransportType.INVM);
+      server_1 = new MessagingServerImpl(config);
+      server_1.start();
+
+      config = new ConfigurationImpl();
+      config.setServerID(1);
+      config.setTransport(TransportType.INVM);
+      server_2 = new MessagingServerImpl(config);
+      server_2.start();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      server_1.stop();
+      server_2.stop();
+
+      super.tearDown();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network (from rev 4392, trunk/tests/src/org/jboss/messaging/tests/unit/jms/network)

Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/network/ClientNetworkFailureTest.java	2008-06-05 12:57:03 UTC (rev 4392)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -1,209 +0,0 @@
-/*
- * 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.messaging.tests.unit.jms.network;
-
-import junit.framework.TestCase;
-import org.jboss.messaging.core.client.ClientConnection;
-import org.jboss.messaging.core.client.ClientConnectionFactory;
-import org.jboss.messaging.core.client.RemotingSessionListener;
-import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
-import org.jboss.messaging.core.client.impl.LocationImpl;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.TransportType;
-import static org.jboss.messaging.core.remoting.TransportType.TCP;
-import org.jboss.messaging.core.remoting.impl.mina.MinaService;
-import org.jboss.messaging.core.server.ConnectionManager;
-import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.MessagingServerImpl;
-import static org.jboss.messaging.tests.integration.core.remoting.mina.TestSupport.KEEP_ALIVE_INTERVAL;
-import static org.jboss.messaging.tests.integration.core.remoting.mina.TestSupport.KEEP_ALIVE_TIMEOUT;
-
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @version <tt>$Revision$</tt>
- */
-public class ClientNetworkFailureTest extends TestCase
-{
-
-   // Constants -----------------------------------------------------
-   Logger log = Logger.getLogger(ClientNetworkFailureTest.class);
-   private MessagingServer server;
-   private MinaService minaService;
-   private NetworkFailureFilter networkFailureFilter;
-
-   // Static --------------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   public ClientNetworkFailureTest(String name)
-   {
-      super(name);
-   }
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      ConfigurationImpl newConfig = new ConfigurationImpl();
-      newConfig.setInvmDisabled(true);
-      newConfig.setHost("localhost");
-      newConfig.setPort(5400);
-      newConfig.setTransport(TransportType.TCP);
-      newConfig.setKeepAliveInterval(KEEP_ALIVE_INTERVAL);
-      newConfig.setKeepAliveTimeout(KEEP_ALIVE_TIMEOUT);
-      server = new MessagingServerImpl(newConfig);
-      server.start();
-      minaService = (MinaService) server.getRemotingService();
-      networkFailureFilter = new NetworkFailureFilter();
-      minaService.getFilterChain().addFirst("network-failure",
-              networkFailureFilter);
-
-      assertActiveConnectionsOnTheServer(0);
-   }
-
-   @Override
-   protected void tearDown() throws Exception
-   {
-      assertActiveConnectionsOnTheServer(0);
-      server.stop();
-      //minaService.start();
-
-      super.tearDown();
-   }
-
-   // Public --------------------------------------------------------
-
-   public void testServerResourcesCleanUpWhenClientCommThrowsException()
-           throws Exception
-   {
-      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(TCP, "localhost", 5400));
-
-      ClientConnection conn = cf.createConnection();
-
-      assertActiveConnectionsOnTheServer(1);
-
-      final CountDownLatch exceptionLatch = new CountDownLatch(2);
-      conn.setRemotingSessionListener(new RemotingSessionListener()
-      {
-         public void sessionDestroyed(long sessionID, MessagingException me)
-         {
-            exceptionLatch.countDown();
-         }
-      });
-      RemotingSessionListener listener = new FailureListenerWithLatch(exceptionLatch);
-      minaService.addRemotingSessionListener(listener);
-
-      networkFailureFilter.messageSentThrowsException = new IOException(
-              "Client is unreachable");
-      networkFailureFilter.messageReceivedDropsPacket = true;
-
-      boolean gotExceptionsOnTheServerAndTheClient = exceptionLatch.await(
-              KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 5000, MILLISECONDS);
-      assertTrue(gotExceptionsOnTheServerAndTheClient);
-      //now we  need to wait for the server to detect the client failover
-      //Thread.sleep((KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT) * 1000);
-      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.removeRemotingSessionListener(listener);
-   }
-
-   public void testServerResourcesCleanUpWhenClientCommDropsPacket()
-           throws Exception
-   {
-      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(TCP, "localhost", 5400));
-
-      ClientConnection conn = cf.createConnection();
-
-      final CountDownLatch exceptionLatch = new CountDownLatch(1);
-
-      RemotingSessionListener listener = new FailureListenerWithLatch(exceptionLatch);
-      minaService.addRemotingSessionListener(listener);
-
-      assertActiveConnectionsOnTheServer(1);
-
-      networkFailureFilter.messageSentDropsPacket = true;
-      networkFailureFilter.messageReceivedDropsPacket = true;
-
-      boolean gotExceptionOnTheServer = exceptionLatch.await(
-              KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 5000, MILLISECONDS);
-      assertTrue(gotExceptionOnTheServer);
-      //now we  need to wait for the server to detect the client failover
-      //Thread.sleep((KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT) * 1000);
-      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 final class FailureListenerWithLatch implements RemotingSessionListener
-   {
-      private final CountDownLatch exceptionLatch;
-
-      private FailureListenerWithLatch(CountDownLatch exceptionLatch)
-      {
-         this.exceptionLatch = exceptionLatch;
-      }
-
-      public void sessionDestroyed(long sessionID, MessagingException me)
-      {
-         log.warn("got expected exception on the server");
-         exceptionLatch.countDown();
-      }
-   }
-
-   private void assertActiveConnectionsOnTheServer(int expectedSize)
-           throws Exception
-   {
-      ConnectionManager cm = server
-              .getConnectionManager();
-      assertEquals(expectedSize, cm.getActiveConnections().size());
-   }
-}

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java (from rev 4393, trunk/tests/src/org/jboss/messaging/tests/unit/jms/network/ClientNetworkFailureTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/ClientNetworkFailureTest.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -0,0 +1,209 @@
+/*
+ * 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.messaging.tests.unit.core.remoting.network;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.RemotingSessionListener;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.TransportType;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import org.jboss.messaging.core.remoting.impl.mina.MinaService;
+import org.jboss.messaging.core.server.ConnectionManager;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import static org.jboss.messaging.tests.integration.core.remoting.mina.TestSupport.KEEP_ALIVE_INTERVAL;
+import static org.jboss.messaging.tests.integration.core.remoting.mina.TestSupport.KEEP_ALIVE_TIMEOUT;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @version <tt>$Revision$</tt>
+ */
+public class ClientNetworkFailureTest extends TestCase
+{
+
+   // Constants -----------------------------------------------------
+   Logger log = Logger.getLogger(ClientNetworkFailureTest.class);
+   private MessagingServer server;
+   private MinaService minaService;
+   private NetworkFailureFilter networkFailureFilter;
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ClientNetworkFailureTest(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      ConfigurationImpl newConfig = new ConfigurationImpl();
+      newConfig.setInvmDisabled(true);
+      newConfig.setHost("localhost");
+      newConfig.setPort(5400);
+      newConfig.setTransport(TransportType.TCP);
+      newConfig.setKeepAliveInterval(KEEP_ALIVE_INTERVAL);
+      newConfig.setKeepAliveTimeout(KEEP_ALIVE_TIMEOUT);
+      server = new MessagingServerImpl(newConfig);
+      server.start();
+      minaService = (MinaService) server.getRemotingService();
+      networkFailureFilter = new NetworkFailureFilter();
+      minaService.getFilterChain().addFirst("network-failure",
+              networkFailureFilter);
+
+      assertActiveConnectionsOnTheServer(0);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      assertActiveConnectionsOnTheServer(0);
+      server.stop();
+      //minaService.start();
+
+      super.tearDown();
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testServerResourcesCleanUpWhenClientCommThrowsException()
+           throws Exception
+   {
+      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(TCP, "localhost", 5400));
+
+      ClientConnection conn = cf.createConnection();
+
+      assertActiveConnectionsOnTheServer(1);
+
+      final CountDownLatch exceptionLatch = new CountDownLatch(2);
+      conn.setRemotingSessionListener(new RemotingSessionListener()
+      {
+         public void sessionDestroyed(long sessionID, MessagingException me)
+         {
+            exceptionLatch.countDown();
+         }
+      });
+      RemotingSessionListener listener = new FailureListenerWithLatch(exceptionLatch);
+      minaService.addRemotingSessionListener(listener);
+
+      networkFailureFilter.messageSentThrowsException = new IOException(
+              "Client is unreachable");
+      networkFailureFilter.messageReceivedDropsPacket = true;
+
+      boolean gotExceptionsOnTheServerAndTheClient = exceptionLatch.await(
+              KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 5000, MILLISECONDS);
+      assertTrue(gotExceptionsOnTheServerAndTheClient);
+      //now we  need to wait for the server to detect the client failover
+      //Thread.sleep((KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT) * 1000);
+      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.removeRemotingSessionListener(listener);
+   }
+
+   public void testServerResourcesCleanUpWhenClientCommDropsPacket()
+           throws Exception
+   {
+      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(TCP, "localhost", 5400));
+
+      ClientConnection conn = cf.createConnection();
+
+      final CountDownLatch exceptionLatch = new CountDownLatch(1);
+
+      RemotingSessionListener listener = new FailureListenerWithLatch(exceptionLatch);
+      minaService.addRemotingSessionListener(listener);
+
+      assertActiveConnectionsOnTheServer(1);
+
+      networkFailureFilter.messageSentDropsPacket = true;
+      networkFailureFilter.messageReceivedDropsPacket = true;
+
+      boolean gotExceptionOnTheServer = exceptionLatch.await(
+              KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT + 5000, MILLISECONDS);
+      assertTrue(gotExceptionOnTheServer);
+      //now we  need to wait for the server to detect the client failover
+      //Thread.sleep((KEEP_ALIVE_INTERVAL + KEEP_ALIVE_TIMEOUT) * 1000);
+      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 final class FailureListenerWithLatch implements RemotingSessionListener
+   {
+      private final CountDownLatch exceptionLatch;
+
+      private FailureListenerWithLatch(CountDownLatch exceptionLatch)
+      {
+         this.exceptionLatch = exceptionLatch;
+      }
+
+      public void sessionDestroyed(long sessionID, MessagingException me)
+      {
+         log.warn("got expected exception on the server");
+         exceptionLatch.countDown();
+      }
+   }
+
+   private void assertActiveConnectionsOnTheServer(int expectedSize)
+           throws Exception
+   {
+      ConnectionManager cm = server
+              .getConnectionManager();
+      assertEquals(expectedSize, cm.getActiveConnections().size());
+   }
+}

Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/network/NetworkFailureFilter.java	2008-06-05 12:57:03 UTC (rev 4392)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.tests.unit.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

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java (from rev 4393, trunk/tests/src/org/jboss/messaging/tests/unit/jms/network/NetworkFailureFilter.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/network/NetworkFailureFilter.java	2008-06-05 14:25:18 UTC (rev 4394)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.unit.core.remoting.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