[jboss-cvs] JBoss Messaging SVN: r6214 - trunk/tests/src/org/jboss/messaging/tests/integration/client.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 30 09:46:12 EDT 2009


Author: jmesnil
Date: 2009-03-30 09:46:12 -0400 (Mon, 30 Mar 2009)
New Revision: 6214

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientConsumerCloseTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientProducerCloseTest.java
Modified:
   trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientRequestorTest.java
Log:
integration tests for closing client resources

Added: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientConsumerCloseTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientConsumerCloseTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientConsumerCloseTest.java	2009-03-30 13:46:12 UTC (rev 6214)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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.client;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
+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.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.tests.util.ServiceTestBase;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ClientConsumerCloseTest extends ServiceTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServiceImpl service;
+   private ClientSession session;
+   private SimpleString queue;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testCanNotUseAClosedConsumer() throws Exception
+   {
+      final ClientConsumer consumer = session.createConsumer(queue);
+
+      consumer.close();
+
+      assertTrue(consumer.isClosed());
+
+      expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+      {
+         public void run() throws MessagingException
+         {
+            consumer.receive();
+         }
+      });
+      
+      expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+      {
+         public void run() throws MessagingException
+         {
+            consumer.receiveImmediate();
+         }
+      });
+
+      expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+      {
+         public void run() throws MessagingException
+         {
+            consumer.setMessageHandler(new MessageHandler()
+            {
+               public void onMessage(ClientMessage message)
+               {
+               }
+            });
+         }
+      });
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      Configuration config = new ConfigurationImpl();
+      config.setSecurityEnabled(false);
+      service = Messaging.newNullStorageMessagingService(config);
+      service.start();
+      
+      SimpleString address = randomSimpleString();
+      queue = randomSimpleString();
+
+      ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+      session = sf.createSession(false, true, true);
+      session.createQueue(address, queue, false);
+
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      session.deleteQueue(queue);
+      
+      session.close();
+      
+      service.stop();
+
+      super.tearDown();
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Added: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientProducerCloseTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientProducerCloseTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientProducerCloseTest.java	2009-03-30 13:46:12 UTC (rev 6214)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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.client;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
+
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
+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.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.ServiceTestBase;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ClientProducerCloseTest extends ServiceTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServiceImpl service;
+
+   private ClientSession session;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testCanNotUseAClosedProducer() throws Exception
+   {
+      final ClientProducer producer = session.createProducer(randomSimpleString());
+
+      assertFalse(producer.isClosed());
+
+      producer.close();
+
+      assertTrue(producer.isClosed());
+
+      expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
+      {
+         public void run() throws MessagingException
+         {
+            producer.send(session.createClientMessage(false));
+         }
+      });
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      Configuration config = new ConfigurationImpl();
+      config.setSecurityEnabled(false);
+      service = Messaging.newNullStorageMessagingService(config);
+      service.start();
+
+      ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+      session = sf.createSession(false, true, true);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      session.close();
+
+      service.stop();
+
+      super.tearDown();
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientRequestorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientRequestorTest.java	2009-03-30 13:45:41 UTC (rev 6213)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientRequestorTest.java	2009-03-30 13:46:12 UTC (rev 6214)
@@ -160,21 +160,19 @@
 
    public void testClientRequestorConstructorWithClosedSession() throws Exception
    {
-      SimpleString requestAddress = randomSimpleString();
+      final SimpleString requestAddress = randomSimpleString();
 
       ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
       final ClientSession session = sf.createSession(false, true, true);
 
       session.close();
 
-      try
-      {
-         new ClientRequestor(session, requestAddress);
-         fail("ClientRequestor's session must not be closed");
-      }
-      catch (Exception e)
-      {
-      }
+      expectMessagingException("ClientRequestor's session must not be closed", MessagingException.OBJECT_CLOSED, new MessagingAction(){
+         public void run() throws Exception
+         {
+            new ClientRequestor(session, requestAddress);
+         }
+      });
    }
 
    public void testClose() throws Exception
@@ -194,7 +192,7 @@
       ClientConsumer requestConsumer = session.createConsumer(requestQueue);
       requestConsumer.setMessageHandler(new SimpleMessageHandler(key, session));
 
-      ClientRequestor requestor = new ClientRequestor(session, requestAddress);
+      final ClientRequestor requestor = new ClientRequestor(session, requestAddress);
       ClientMessage request = session.createClientMessage(false);
       request.putLongProperty(key, value);
 
@@ -207,15 +205,13 @@
 
       requestor.close();
 
-      try
-      {
-         reply = requestor.request(request, 500);
-         fail("can not send a request on a closed ClientRequestor");
-      }
-      catch (Exception e)
-      {
+      expectMessagingException("can not send a request on a closed ClientRequestor", MessagingException.OBJECT_CLOSED, new MessagingAction(){
 
-      }
+         public void run() throws Exception
+         {
+            requestor.request(session.createClientMessage(false), 500);
+         }
+      });
    }
 
    // Package protected ---------------------------------------------




More information about the jboss-cvs-commits mailing list