[jboss-cvs] JBoss Messaging SVN: r5936 - in trunk: src/main/org/jboss/messaging/core/management/impl and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 26 08:52:35 EST 2009


Author: jmesnil
Date: 2009-02-26 08:52:34 -0500 (Thu, 26 Feb 2009)
New Revision: 5936

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientTestBase.java
Modified:
   trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
   trunk/src/main/org/jboss/messaging/core/remoting/RemotingConnection.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java
   trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
   trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/CrashClient.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSServerControlTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java
Log:
JBMESSAGING-1421: clean up server resources when the connection is closed

* added a QUIT packet which must be the *last* packet sent by a client to state that the connection can safely be closed on the server side
* in RemotingService, when receiving a connectionDestroyed event, destroy the connection immediately only if it is ready to be closed (it has received the QUIT packet). Otherwise, wait for the connection TTL to be hit to clean up the server resources associated to the connection
* updated the ClientCrashTest and ClientExitTest to check the connection and server sessions after the client has crashed/exited.

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -23,6 +23,7 @@
 package org.jboss.messaging.core.client.impl;
 
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.EARLY_RESPONSE;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.QUIT;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -48,6 +49,7 @@
 import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateSessionMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateSessionResponseMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
 import org.jboss.messaging.core.remoting.spi.Connection;
 import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
 import org.jboss.messaging.core.remoting.spi.Connector;
@@ -756,6 +758,8 @@
          {
             try
             {
+               quitConnection(entry.connection.getTransportConnection());
+
                entry.connection.destroy();
 
                entry.connector.close();
@@ -768,6 +772,14 @@
          mapIterator = null;
       }
    }
+   
+   private void quitConnection(final Connection connection)
+   {
+      PacketImpl quitPacket = new PacketImpl(QUIT);
+      MessagingBuffer buffer = connection.createBuffer(quitPacket.getRequiredBufferSize());
+      quitPacket.encode(buffer);      
+      connection.write(buffer);      
+   }
 
    private RemotingConnection getConnection(final int count)
    {

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -513,6 +513,8 @@
          String remoteAddress = connection.getRemoteAddress();
          if (remoteAddress.contains(ipAddress))
          {
+            // force the immediate closure of the connection and its resources
+            connection.setReadyToClose();
             connection.fail(new MessagingException(MessagingException.INTERNAL_ERROR, "connections for " + ipAddress +
                                                                                       " closed by management"));
             closed = true;

Modified: trunk/src/main/org/jboss/messaging/core/remoting/RemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/RemotingConnection.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/remoting/RemotingConnection.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -66,4 +66,9 @@
    void setReplicatingConnection(RemotingConnection connection);
    
    Connection getTransportConnection();
+   
+   void setReadyToClose();
+   
+   boolean isReadyToClose();
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -16,6 +16,7 @@
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.CREATESESSION_RESP;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.EARLY_RESPONSE;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.EXCEPTION;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.QUIT;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.NULL_RESPONSE;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.PACKETS_CONFIRMED;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.PING;
@@ -257,6 +258,8 @@
 
    private final Object failLock = new Object();
 
+   private boolean readyToClose = false;
+   
    // debug only stuff
 
    private boolean createdActive;
@@ -519,6 +522,15 @@
       {
          if (!frozen)
          {
+            // we intercept the QUIT command her to flag the remoting connection
+            // as ready to be closed. No other packets are expected to be
+            // handled after the QUIT packet
+            if (packet.getType() == QUIT)
+            {
+               setReadyToClose();
+               return;
+            }
+            
             final ChannelImpl channel = channels.get(packet.getChannelID());
 
             if (channel != null)
@@ -544,6 +556,16 @@
       }
    }
    
+   public void setReadyToClose()
+   {
+      this.readyToClose = true;
+   }
+   
+   public boolean isReadyToClose()
+   {
+      return readyToClose;
+   }
+   
 //   public void resetAllReplicatingChannels()
 //   {      
 //      replicatingConnection = null;
@@ -876,6 +898,11 @@
             packet = new SessionReplicateDeliveryMessage();
             break;
          }
+         case QUIT:
+         {
+            packet = new PacketImpl(QUIT);
+            break;
+         }
          default:
          {
             throw new IllegalArgumentException("Invalid type: " + packetType);
@@ -1337,6 +1364,12 @@
             throw new IllegalArgumentException("Cannot find channel with id " + id + " to close");
          }
          
+         if (connection.channels.size() == 0)
+         {
+            Packet last = new PacketImpl(QUIT);
+            send(last);
+         }
+         
          if (replicatingChannel != null)
          {
             replicatingChannel.close();

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketImpl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketImpl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -68,6 +68,8 @@
 
    public static final byte REPLICATE_CREATESESSION = 34;
 
+   public static final byte QUIT = 35;
+
    // Session
    public static final byte SESS_CREATECONSUMER = 40;
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -277,12 +277,15 @@
 
    public void connectionDestroyed(final Object connectionID)
    {
-      RemotingConnection conn = connections.remove(connectionID);
-            
-      if (conn != null)
+      RemotingConnection conn = connections.get(connectionID);
+      
+      // if the connection is not ready to be closed properly,
+      // the cleanup will occur when the connection TTL is hit
+      if (conn != null && conn.isReadyToClose())
       {
+         connections.remove(connectionID);
          conn.destroy();
-      }      
+      }
    }
 
    public void connectionException(final Object connectionID, final MessagingException me)
@@ -292,7 +295,7 @@
       if (rc != null)
       {
          rc.fail(me);
-      }     
+      }
    }
 
    public void addInterceptor(final Interceptor interceptor)
@@ -341,6 +344,7 @@
 
          for (RemotingConnection conn : failedConnections)
          {
+            connections.remove(conn.getID());
             MessagingException me = new MessagingException(MessagingException.CONNECTION_TIMEDOUT,
                                                            "Did not receive ping on connection. It is likely a client has exited or crashed without " + "closing its connection, or the network between the server and client has failed. The connection will now be closed.");
 

Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -113,7 +113,9 @@
    ResourceManager getResourceManager();
 
    List<ServerSession> getSessions(String connectionID);
-   
+
+   List<ServerSession> getSessions();
+
    ClusterManager getClusterManager();
    
    QueueFactory getQueueFactory();

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -706,6 +706,18 @@
       }
       return matchingSessions;
    }
+   
+   public List<ServerSession> getSessions()
+   {
+      Set<Entry<String, ServerSession>> sessionEntries = sessions.entrySet();
+      List<ServerSession> matchingSessions = new ArrayList<ServerSession>();
+      for (Entry<String, ServerSession> sessionEntry : sessionEntries)
+      {
+         ServerSession serverSession = sessionEntry.getValue();
+         matchingSessions.add(serverSession);
+      }
+      return matchingSessions;
+   }
 
    public RemotingConnection getReplicatingConnection()
    {

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientCrashTest.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -47,13 +47,10 @@
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
 import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.config.TransportConfiguration;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.server.MessagingService;
 import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.tests.util.ServiceTestBase;
 import org.jboss.messaging.tests.util.SpawnedVMSupport;
 import org.jboss.messaging.utils.SimpleString;
 
@@ -65,8 +62,12 @@
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
  * @version <tt>$Revision: 4032 $</tt>
  */
-public class ClientCrashTest extends ServiceTestBase
+public class ClientCrashTest extends ClientTestBase
 {
+   static final int PING_PERIOD = 2000;
+
+   static final int CONNECTION_TTL = 3000;
+
    // Constants -----------------------------------------------------
 
    public static final SimpleString QUEUE = new SimpleString("ClientCrashTestQueue");
@@ -83,45 +84,33 @@
 
    private ClientSessionFactory sf;
    
-   private MessagingService messagingService;
-
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
 
-   public void testCrashClientWithOneConnection() throws Exception
+   public void testCrashClient() throws Exception
    {
-      crashClient(1);
-   }
-
-   public void testCrashClientWithTwoConnections() throws Exception
-   {
-      crashClient(2);
-   }
-
-   public void crashClient(int numberOfConnectionsOnTheClient) throws Exception
-   {
       assertActiveConnections(0);
-
+      
       // spawn a JVM that creates a JMS client, which waits to receive a test
       // message
-      Process p = SpawnedVMSupport.spawnVM(CrashClient.class.getName(),
-                                           new String[] { Integer.toString(numberOfConnectionsOnTheClient) });
-
+      Process p = SpawnedVMSupport.spawnVM(CrashClient.class.getName());
+      
       ClientSession session = sf.createSession(false, true, true);
       session.createQueue(QUEUE, QUEUE, null, false, false);
       ClientConsumer consumer = session.createConsumer(QUEUE);
       ClientProducer producer = session.createProducer(QUEUE);
-
+      
       session.start();
-
+      
       // send the message to the queue
       Message messageFromClient = consumer.receive(5000);
       assertNotNull("no message received", messageFromClient);
       assertEquals(MESSAGE_TEXT_FROM_CLIENT, messageFromClient.getBody().getString());
-
+      
       assertActiveConnections(1 + 1); // One local and one from the other vm
-
+      assertActiveSession(1 + 1);
+      
       ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE,
                                                           false,
                                                           0,
@@ -129,22 +118,27 @@
                                                           (byte)1);
       message.getBody().putString(ClientCrashTest.MESSAGE_TEXT_FROM_SERVER);
       producer.send(message);
+      session.close();
 
+      Thread.sleep(500);
+      
+      assertActiveConnections(1);
+      assertActiveSession(1);      
+
       log.debug("waiting for the client VM to crash ...");
       p.waitFor();
-
+      
       assertEquals(9, p.exitValue());
+      
+      System.out.println("VM Exited");
 
-      Thread.sleep(4000);
-      // the crash must have been detected and the client resources cleaned
-      // up only the local connection remains
       assertActiveConnections(1);
+      assertActiveSession(1);      
 
-      session.close();
-
-      Thread.sleep(1000);
-
+      Thread.sleep(2 * PING_PERIOD + 2 * CONNECTION_TTL);
+      // the crash must have been detected and the resources cleaned up
       assertActiveConnections(0);
+      assertActiveSession(0);      
    }
 
    // Package protected ---------------------------------------------
@@ -154,16 +148,11 @@
    {
       super.setUp();
 
-      Configuration config = createDefaultConfig(true);
-      config.setSecurityEnabled(false);
-      messagingService = createService(false, config);
-      messagingService.start();
-
       sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"),
                                         null,
                                         DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
-                                        2000,
-                                        3000,
+                                        PING_PERIOD,
+                                        CONNECTION_TTL,
                                         DEFAULT_CALL_TIMEOUT,
                                         DEFAULT_CONSUMER_WINDOW_SIZE,
                                         DEFAULT_CONSUMER_MAX_RATE,
@@ -187,20 +176,13 @@
    @Override
    protected void tearDown() throws Exception
    {
-      messagingService.stop();
-
-      super.tearDown();
+      sf.close();
    }
 
    // Protected -----------------------------------------------------
 
    // Private -------------------------------------------------------
 
-   private void assertActiveConnections(int expectedActiveConnections) throws Exception
-   {
-      assertEquals(expectedActiveConnections, messagingService.getServer().getServerManagement().getConnectionCount());
-   }
-
    // Inner classes -------------------------------------------------
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientExitTest.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -29,15 +29,10 @@
 import org.jboss.messaging.core.client.ClientSessionFactory;
 import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
 import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.server.Messaging;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory;
 import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
 import org.jboss.messaging.tests.util.SpawnedVMSupport;
-import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.messaging.utils.SimpleString;
 
 /**
@@ -52,7 +47,7 @@
  *
  * $Id$
  */
-public class ClientExitTest extends UnitTestCase
+public class ClientExitTest extends ClientTestBase
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -66,8 +61,6 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
-   private MessagingService messagingService;
-
    private ClientSession session;
 
    private ClientConsumer consumer;   
@@ -94,6 +87,16 @@
       p.waitFor();
 
       assertEquals(0, p.exitValue());
+      
+      // the local session
+      assertActiveConnections(1);
+      assertActiveSession(1);
+      
+      session.close();
+      
+      Thread.sleep(1000);
+      assertActiveConnections(0);
+      assertActiveSession(0);
    }
 
    // Package protected ----------------------------------------------------------------------------
@@ -103,12 +106,6 @@
    {
       super.setUp();
       
-      ConfigurationImpl config = new ConfigurationImpl();
-      config.setSecurityEnabled(false);
-      config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
-      messagingService = Messaging.newNullStorageMessagingService(config);
-      messagingService.start();
-
       ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(NettyConnectorFactory.class.getName()));
       session = sf.createSession(false, true, true);
       session.createQueue(QUEUE, QUEUE, null, false, false);
@@ -116,17 +113,6 @@
       session.start();
    }
 
-   @Override
-   protected void tearDown() throws Exception
-   {
-      consumer.close();
-      session.close();
-
-      messagingService.stop();
-
-      super.tearDown();
-   }
-   
    // Protected ------------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------

Added: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientTestBase.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/ClientTestBase.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * 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.integration.clientcrash;
+
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.tests.util.ServiceTestBase;
+
+/**
+ * A ClientTestBase
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ *
+ */
+public class ClientTestBase extends ServiceTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingService messagingService;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      Configuration config = createDefaultConfig(true);
+      config.setSecurityEnabled(false);
+      messagingService = createService(false, config);
+      messagingService.start();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      messagingService.stop();
+
+      super.tearDown();
+   }
+   
+   protected void assertActiveConnections(int expectedActiveConnections) throws Exception
+   {
+      assertEquals(expectedActiveConnections, messagingService.getServer().getServerManagement().getConnectionCount());
+   }
+
+   protected void assertActiveSession(int expectedActiveSession) throws Exception
+   {
+      assertEquals(expectedActiveSession, messagingService.getServer().getSessions().size());
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/CrashClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/CrashClient.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/clientcrash/CrashClient.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -22,11 +22,28 @@
 
 package org.jboss.messaging.tests.integration.clientcrash;
 
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_RETRIES_AFTER_FAILOVER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_RETRIES_BEFORE_FAILOVER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE;
 import static org.jboss.messaging.tests.integration.clientcrash.ClientCrashTest.QUEUE;
 
 import java.util.Arrays;
 
-import org.jboss.messaging.core.client.ClientConsumer;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
@@ -60,39 +77,39 @@
       try
       {
          log.debug("args = " + Arrays.asList(args));
-
-         if (args.length != 1)
-         {
-            log.fatal("unexpected number of args (should be 1)");
-            System.exit(1);
-         }
-
-         int numberOfConnections = Integer.parseInt(args[0]);
          
-         ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"));
+         ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration("org.jboss.messaging.integration.transports.netty.NettyConnectorFactory"),
+                                           null,
+                                           DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
+                                           ClientCrashTest.PING_PERIOD,
+                                           ClientCrashTest.CONNECTION_TTL,
+                                           DEFAULT_CALL_TIMEOUT,
+                                           DEFAULT_CONSUMER_WINDOW_SIZE,
+                                           DEFAULT_CONSUMER_MAX_RATE,
+                                           DEFAULT_SEND_WINDOW_SIZE,
+                                           DEFAULT_PRODUCER_MAX_RATE,
+                                           DEFAULT_MIN_LARGE_MESSAGE_SIZE,
+                                           DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                           DEFAULT_BLOCK_ON_PERSISTENT_SEND,
+                                           DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND,
+                                           DEFAULT_AUTO_GROUP,
+                                           DEFAULT_MAX_CONNECTIONS,
+                                           DEFAULT_PRE_ACKNOWLEDGE,
+                                           DEFAULT_ACK_BATCH_SIZE,                                 
+                                           DEFAULT_RETRY_INTERVAL,
+                                           DEFAULT_RETRY_INTERVAL_MULTIPLIER,                                        
+                                           DEFAULT_MAX_RETRIES_BEFORE_FAILOVER,
+                                           DEFAULT_MAX_RETRIES_AFTER_FAILOVER);
          ClientSession session = sf.createSession(false, true, true);
          ClientProducer producer = session.createProducer(QUEUE);
-         ClientConsumer consumer = session.createConsumer(QUEUE);
-
-//         if (numberOfConnections > 1)
-//         {
-//            // create (num - 1) unused connections
-//            for (int i = 0; i < numberOfConnections - 1; i++)
-//            {
-//               cf.createConnection();         
-//            }
-//         }
          
          ClientMessage message = session.createClientMessage(JBossTextMessage.TYPE, false, 0,
                System.currentTimeMillis(), (byte) 1);
          message.getBody().putString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);
 
          producer.send(message);
-
-         session.start();
-         //consumer.receive(5000);
          
-         // crash
+         // exit without closing the session properly
          System.exit(9);
       }
       catch (Throwable t)

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSServerControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSServerControlTest.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSServerControlTest.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -343,6 +343,7 @@
          Thread.sleep(500);
 
          assertEquals(0, control.listRemoteAddresses().length);
+         assertEquals(0, control.listConnectionIDs().length);
       }
       finally
       {
@@ -389,6 +390,7 @@
          
          boolean gotException = exceptionLatch.await(1, TimeUnit.SECONDS);
          assertTrue("did not received the expected JMSException", gotException);
+         Thread.sleep(500);
          assertEquals(0, control.listRemoteAddresses().length);
          assertEquals(0, service.getServer().getConnectionCount());
       }
@@ -440,6 +442,10 @@
 
          assertEquals(1, control.listRemoteAddresses().length);
          assertEquals(1, service.getServer().getConnectionCount());
+         
+         connection.close();
+         Thread.sleep(1000);
+         assertEquals(0, service.getServer().getConnectionCount());
 
       }
       finally

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java	2009-02-26 10:12:21 UTC (rev 5935)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/management/JMSUtil.java	2009-02-26 13:52:34 UTC (rev 5936)
@@ -102,6 +102,37 @@
                                                              DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                                              DEFAULT_MAX_RETRIES_BEFORE_FAILOVER,
                                                              DEFAULT_MAX_RETRIES_AFTER_FAILOVER);
+      return cf.createConnection();
+   }
+   
+   public static Connection createConnection(final String connectorFactory,
+                                             final long pingPeriod,
+                                             final long connectionTTL) throws JMSException
+   {
+      JBossConnectionFactory cf = new JBossConnectionFactory(new TransportConfiguration(connectorFactory),
+                                                             null,
+                                                             DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
+                                                             DEFAULT_PING_PERIOD,
+                                                             connectionTTL,
+                                                             DEFAULT_CALL_TIMEOUT,
+                                                             null,
+                                                             DEFAULT_ACK_BATCH_SIZE,
+                                                             DEFAULT_ACK_BATCH_SIZE,
+                                                             DEFAULT_CONSUMER_WINDOW_SIZE,
+                                                             DEFAULT_CONSUMER_MAX_RATE,
+                                                             DEFAULT_SEND_WINDOW_SIZE,
+                                                             DEFAULT_PRODUCER_MAX_RATE,
+                                                             DEFAULT_MIN_LARGE_MESSAGE_SIZE,
+                                                             DEFAULT_BLOCK_ON_ACKNOWLEDGE,
+                                                             true,
+                                                             true,
+                                                             DEFAULT_AUTO_GROUP,
+                                                             DEFAULT_MAX_CONNECTIONS,
+                                                             DEFAULT_PRE_ACKNOWLEDGE,                                                  
+                                                             DEFAULT_RETRY_INTERVAL,
+                                                             DEFAULT_RETRY_INTERVAL_MULTIPLIER,
+                                                             DEFAULT_MAX_RETRIES_BEFORE_FAILOVER,
+                                                             DEFAULT_MAX_RETRIES_AFTER_FAILOVER);
 
       return cf.createConnection();
    }




More information about the jboss-cvs-commits mailing list