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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 25 06:03:04 EDT 2009


Author: jmesnil
Date: 2009-03-25 06:03:03 -0400 (Wed, 25 Mar 2009)
New Revision: 6156

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java
Log:
integration tests for message expiration

Added: trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java	2009-03-25 10:03:03 UTC (rev 6156)
@@ -0,0 +1,166 @@
+/*
+ * 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.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.ClientProducer;
+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.config.impl.ConfigurationImpl;
+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.core.settings.impl.AddressSettings;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * A MessageExpirationTest
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ *
+ */
+public class MessageExpirationTest extends UnitTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   private static final int EXPIRATION = 1000;
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServiceImpl service;
+
+   private ClientSession session;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testMessageExpiredWithoutExpiryAddress() throws Exception
+   {
+      SimpleString address = randomSimpleString();
+      SimpleString queue = randomSimpleString();
+
+      session.createQueue(address, queue, false);
+
+      ClientProducer producer = session.createProducer(address);
+      ClientMessage message = session.createClientMessage(false);
+      message.setExpiration(System.currentTimeMillis() + EXPIRATION);
+      producer.send(message);
+
+      Thread.sleep(EXPIRATION * 2);
+
+      session.start();
+
+      ClientConsumer consumer = session.createConsumer(queue);
+      ClientMessage message2 = consumer.receive(500);
+      assertNull(message2);
+
+      consumer.close();
+      session.deleteQueue(queue);
+   }
+
+   public void testMessageExpiredWithExpiryAddress() throws Exception
+   {
+      SimpleString address = randomSimpleString();
+      SimpleString queue = randomSimpleString();
+      final SimpleString expiryAddress = randomSimpleString();
+      SimpleString expiryQueue = randomSimpleString();
+
+      session.createQueue(address, queue, false);
+      session.createQueue(expiryAddress, expiryQueue, false);
+      service.getServer().getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings()
+      {
+         @Override
+         public SimpleString getExpiryAddress()
+         {
+            return expiryAddress;
+         }
+      });
+
+      ClientProducer producer = session.createProducer(address);
+      ClientMessage message = session.createClientMessage(false);
+      message.setExpiration(System.currentTimeMillis() + EXPIRATION);
+      producer.send(message);
+
+      Thread.sleep(EXPIRATION * 2);
+
+      session.start();
+
+      ClientConsumer consumer = session.createConsumer(queue);
+      ClientMessage message2 = consumer.receive(500);
+      assertNull(message2);
+
+      ClientConsumer expiryConsumer = session.createConsumer(expiryQueue);
+      ClientMessage expiredMessage = expiryConsumer.receive(500);
+      assertNotNull(expiredMessage);
+
+      consumer.close();
+      expiryConsumer.close();
+      session.deleteQueue(queue);
+      session.deleteQueue(expiryQueue);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      Configuration config = new ConfigurationImpl();
+      config.setSecurityEnabled(false);
+      service = Messaging.newMessagingService(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 -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list