[jboss-cvs] JBossAS SVN: r62607 - branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 27 06:49:50 EDT 2007


Author: wolfc
Date: 2007-04-27 06:49:50 -0400 (Fri, 27 Apr 2007)
New Revision: 62607

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationUnitTestCase.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328UnitTestCase.java
Removed:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationTestCase.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328TestCase.java
Log:
JBAS-4328: enabled tests

Deleted: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationTestCase.java	2007-04-27 10:49:32 UTC (rev 62606)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationTestCase.java	2007-04-27 10:49:50 UTC (rev 62607)
@@ -1,202 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jbossmq.test;
-
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.jms.DeliveryMode;
-import javax.jms.Queue;
-import javax.jms.QueueBrowser;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.management.Attribute;
-import javax.management.ObjectName;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.jboss.test.JBossTestSetup;
-import org.jboss.util.collection.CollectionsUtil;
-
-/**
- * ExpiryDestinationTestCase tests putting messages on a separate queue.
- *
- * @author Elias Ross <genman at noderunner.net>
- * @version $Revision$
- */
-public class ExpiryDestinationTestCase
-   extends JBossMQUnitTest
-{
-
-   static String DLQ_QUEUE = "queue/DLQ";
-   int times;
-   ObjectName dlq;
-   ObjectName tq;
-   
-   public ExpiryDestinationTestCase(String name) throws Exception
-   {
-      super(name);
-      getLog().debug(getName());
-   }
-
-   private List list(QueueSession session, Queue queue) throws Exception
-   {
-      QueueBrowser browser = session.createBrowser( queue );
-      Enumeration e = browser.getEnumeration();
-      return CollectionsUtil.list(e);
-   }
-
-   private int size(QueueSession session, Queue queue) throws Exception
-   {
-      List l = list(session, queue);
-      return l.size();
-   }
-
-   private void assertSize(QueueSession session, Queue queue, int size) throws Exception
-   {
-      assertEquals(size, size(session, queue));
-   }
-
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-      times = getIterationCount();
-      dlq = new ObjectName("jboss.mq.destination:service=Queue,name=DLQ");
-      tq = new ObjectName("jboss.mq.destination:service=Queue,name=testQueue");
-      getServer().invoke(dlq, "removeAllMessages", null, null);
-      getServer().invoke(tq, "removeAllMessages", null, null);
-      getServer().setAttribute(tq, new Attribute("ExpiryDestination", dlq));
-      getServer().invoke(tq, "stop", null, null);
-      getServer().invoke(tq, "start", null, null);
-
-      connect();
-      queueConnection.start();
-      drainQueue();
-   }
-
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-      getServer().invoke(dlq, "removeAllMessages", null, null);
-      getServer().invoke(tq, "removeAllMessages", null, null);
-      getServer().setAttribute(tq, new Attribute("ExpiryDestination", null));
-   }
-   
-   /**
-    * Test that expired messages are moved to a separate queue.
-    */
-   public void testExpiredMessagesMove() throws Exception
-   {
-      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-      Queue queue = (Queue)context.lookup(TEST_QUEUE);
-      QueueSender sender = session.createSender(queue);
-
-      Queue queue2 = (Queue)context.lookup(DLQ_QUEUE);
-      session.createBrowser( queue );
-
-      long now = System.currentTimeMillis();
-
-      TextMessage message = session.createTextMessage();
-      message.setStringProperty("foo", "bar");
-      String text = "expire on server";
-      message.setText(text);
-      sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
-
-      Thread.sleep(1000);
-
-      assertSize(session, queue,  0);
-      assertSize(session, queue2, 1);
-
-      QueueReceiver receiver = session.createReceiver(queue2);
-      message = (TextMessage) receiver.receiveNoWait();
-      assertEquals("QUEUE.testQueue", message.getStringProperty("JBOSS_ORIG_DESTINATION"));
-      assertTrue(message.getLongProperty("JBOSS_ORIG_EXPIRATION") > now);
-      assertEquals(0L, message.getJMSExpiration());
-      assertEquals(text, message.getText());
-      assertEquals("bar", message.getStringProperty("foo"));
-      receiver.close();
-      session.close();
-
-      disconnect();
-      getLog().debug("passed");
-   }
-
-   /**
-    * Test that expired messages are moved to a separate queue.
-    */
-   public void testSomeLoad() throws Exception
-   {
-      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-      Queue queue = (Queue)context.lookup(TEST_QUEUE);
-      Queue queue2 = (Queue)context.lookup(DLQ_QUEUE);
-      QueueSender sender = session.createSender(queue);
-      TextMessage message = session.createTextMessage();
-
-      for (int i = 0; i < times; i++)
-         sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
-
-      for (int tries = 0; tries < 60; tries++) {
-         Thread.sleep(1000);
-         if (size(session, queue) == 0 &&
-             size(session, queue2) == times)
-            break;
-      }
-      assertSize(session, queue, 0);
-      assertSize(session, queue2, times);
-
-      getLog().debug("test case where expired messages fail to move");
-      for (int i = 0; i < times; i++) {
-        if (i % 10 == 0)
-          getServer().invoke(dlq, "stop", null, null);
-        if (i % 10 == 5)
-          getServer().invoke(dlq, "start", null, null);
-        sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
-      }
-
-      Thread.sleep(1000);
-
-      getServer().invoke(dlq, "start", null, null);
-      getServer().invoke(tq, "stop", null, null);
-      getServer().invoke(tq, "start", null, null);
-
-      for (int tries = 0; tries < 60; tries++) {
-         Thread.sleep(1000);
-         if (size(session, queue) == 0 &&
-             size(session, queue2) == times * 2)
-            break;
-      }
-      assertSize(session, queue, 0);
-      assertSize(session, queue2, times * 2);
-   }
-   
-   public static Test suite() throws Exception
-   {
-      TestSuite suite = new TestSuite();
-      suite.addTest(new JBossTestSetup(new ExpiryDestinationTestCase("testExpiredMessagesMove")));
-      suite.addTest(new JBossTestSetup(new ExpiryDestinationTestCase("testSomeLoad")));
-      return suite;
-   }
-}

Copied: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationUnitTestCase.java (from rev 62599, branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationTestCase.java)
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/ExpiryDestinationUnitTestCase.java	2007-04-27 10:49:50 UTC (rev 62607)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jbossmq.test;
+
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.Attribute;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestSetup;
+import org.jboss.util.collection.CollectionsUtil;
+
+/**
+ * ExpiryDestinationTestCase tests putting messages on a separate queue.
+ *
+ * @author Elias Ross <genman at noderunner.net>
+ * @version $Revision$
+ */
+public class ExpiryDestinationUnitTestCase
+   extends JBossMQUnitTest
+{
+
+   static String DLQ_QUEUE = "queue/DLQ";
+   int times;
+   ObjectName dlq;
+   ObjectName tq;
+   
+   public ExpiryDestinationUnitTestCase(String name) throws Exception
+   {
+      super(name);
+      getLog().debug(getName());
+   }
+
+   private List list(QueueSession session, Queue queue) throws Exception
+   {
+      QueueBrowser browser = session.createBrowser( queue );
+      Enumeration e = browser.getEnumeration();
+      return CollectionsUtil.list(e);
+   }
+
+   private int size(QueueSession session, Queue queue) throws Exception
+   {
+      List l = list(session, queue);
+      return l.size();
+   }
+
+   private void assertSize(QueueSession session, Queue queue, int size) throws Exception
+   {
+      assertEquals(size, size(session, queue));
+   }
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      times = getIterationCount();
+      dlq = new ObjectName("jboss.mq.destination:service=Queue,name=DLQ");
+      tq = new ObjectName("jboss.mq.destination:service=Queue,name=testQueue");
+      getServer().invoke(dlq, "removeAllMessages", null, null);
+      getServer().invoke(tq, "removeAllMessages", null, null);
+      getServer().setAttribute(tq, new Attribute("ExpiryDestination", dlq));
+      getServer().invoke(tq, "stop", null, null);
+      getServer().invoke(tq, "start", null, null);
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      getServer().invoke(dlq, "removeAllMessages", null, null);
+      getServer().invoke(tq, "removeAllMessages", null, null);
+      getServer().setAttribute(tq, new Attribute("ExpiryDestination", null));
+   }
+   
+   /**
+    * Test that expired messages are moved to a separate queue.
+    */
+   public void testExpiredMessagesMove() throws Exception
+   {
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      Queue queue2 = (Queue)context.lookup(DLQ_QUEUE);
+      session.createBrowser( queue );
+
+      long now = System.currentTimeMillis();
+
+      TextMessage message = session.createTextMessage();
+      message.setStringProperty("foo", "bar");
+      String text = "expire on server";
+      message.setText(text);
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 1000);
+
+      Thread.sleep(2000);
+
+      assertSize(session, queue,  0);
+      assertSize(session, queue2, 1);
+
+      QueueReceiver receiver = session.createReceiver(queue2);
+      message = (TextMessage) receiver.receiveNoWait();
+      assertEquals("QUEUE.testQueue", message.getStringProperty("JBOSS_ORIG_DESTINATION"));
+      assertTrue(message.getLongProperty("JBOSS_ORIG_EXPIRATION") > now);
+      assertEquals(0L, message.getJMSExpiration());
+      assertEquals(text, message.getText());
+      assertEquals("bar", message.getStringProperty("foo"));
+      receiver.close();
+      session.close();
+
+      disconnect();
+      getLog().debug("passed");
+   }
+
+   /**
+    * Test that expired messages are moved to a separate queue.
+    */
+   public void testSomeLoad() throws Exception
+   {
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      Queue queue2 = (Queue)context.lookup(DLQ_QUEUE);
+      QueueSender sender = session.createSender(queue);
+      TextMessage message = session.createTextMessage();
+
+      for (int i = 0; i < times; i++)
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 1000);
+
+      for (int tries = 0; tries < 60; tries++) {
+         Thread.sleep(1000);
+         if (size(session, queue) == 0 &&
+             size(session, queue2) == times)
+            break;
+      }
+      assertSize(session, queue, 0);
+      assertSize(session, queue2, times);
+
+      getLog().debug("test case where expired messages fail to move");
+      for (int i = 0; i < times; i++) {
+        if (i % 10 == 0)
+          getServer().invoke(dlq, "stop", null, null);
+        if (i % 10 == 5)
+          getServer().invoke(dlq, "start", null, null);
+        sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+      }
+
+      Thread.sleep(1000);
+
+      getServer().invoke(dlq, "start", null, null);
+      getServer().invoke(tq, "stop", null, null);
+      getServer().invoke(tq, "start", null, null);
+
+      for (int tries = 0; tries < 60; tries++) {
+         Thread.sleep(1000);
+         if (size(session, queue) == 0 &&
+             size(session, queue2) == times * 2)
+            break;
+      }
+      assertSize(session, queue, 0);
+      assertSize(session, queue2, times * 2);
+   }
+   
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new JBossTestSetup(new ExpiryDestinationUnitTestCase("testExpiredMessagesMove")));
+      suite.addTest(new JBossTestSetup(new ExpiryDestinationUnitTestCase("testSomeLoad")));
+      return suite;
+   }
+}

Deleted: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328TestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328TestCase.java	2007-04-27 10:49:32 UTC (rev 62606)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328TestCase.java	2007-04-27 10:49:50 UTC (rev 62607)
@@ -1,261 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jbossmq.test;
-
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.ServerSession;
-import javax.jms.ServerSessionPool;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.log4j.Category;
-import org.jboss.test.JBossTestCase;
-
-/**
- * This test checks the expiration mechanism on an application server message listener.
- * 
- * @author carlo
- *
- */
-public class JBAS4328TestCase extends JBossTestCase
-{
-   /** The default TopicFactory jndi name */
-   static String TOPIC_FACTORY = "ConnectionFactory";
-   /** The default QueueFactory jndi name */
-   static String QUEUE_FACTORY = "ConnectionFactory";
-
-   static String TEST_QUEUE = "queue/testQueue";
-
-   static Context context;
-   static QueueConnection queueConnection;
-   static TopicConnection topicConnection;
-
-   public static Test suite() throws Exception
-   {
-      TestSuite suite = new TestSuite();
-      suite.addTest(new JBAS4328TestCase("testApplicationServerStuff"));
-      suite.addTest(new JBAS4328TestCase("testApplicationServerExpiration"));
-      
-      return suite;
-   }
-   
-   public JBAS4328TestCase(String name)
-   {
-      super(name);
-   }
-
-   protected void connect() throws Exception
-   {
-
-      if (context == null)
-      {
-
-         context = new InitialContext();
-
-      }
-      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
-      queueConnection = queueFactory.createQueueConnection();
-
-      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
-      topicConnection = topicFactory.createTopicConnection();
-
-      getLog().debug("Connection to spyderMQ established.");
-
-   }
-
-   protected void disconnect() throws Exception
-   {
-      queueConnection.close();
-      topicConnection.close();
-   }
-
-   private int processed = 0;
-   
-   /**
-    * Copy of JBossMQUnitTest.testApplicationServerStuff with a sleep of 5 seconds
-    * during processing of the message in the message listener.
-    * 
-    * @throws Exception
-    */
-   public void testApplicationServerExpiration() throws Exception
-   {
-      getLog().debug("Starting testing app server expiration");
-      connect();
-
-      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
-      final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      session.setMessageListener(new MessageListener()
-      {
-         @SuppressWarnings("deprecation")
-         public void onMessage(Message mess)
-         {
-            Category log = Category.getInstance(getClass().getName());
-            log.debug("Processing message");
-            try
-            {
-               if (System.currentTimeMillis() > mess.getJMSExpiration())
-                  log.warn("*** message is expired *** (" + System.currentTimeMillis() + " > " + mess.getJMSExpiration() + ")");
-               
-               if (mess instanceof TextMessage)
-                  log.debug(((TextMessage) mess).getText());
-               
-               // block consuming for 5 seconds
-               Thread.sleep(5000);
-               processed++;
-            }
-            catch (Exception e)
-            {
-               log.error("Error", e);
-            }
-         }
-      });
-
-      QueueSender sender = session.createSender(testQueue);
-      sender.send(session.createTextMessage("Hi"), DeliveryMode.NON_PERSISTENT, 4, 1000);
-      sender.send(session.createTextMessage("There"), DeliveryMode.NON_PERSISTENT, 4, 1000);
-      sender.send(session.createTextMessage("Guys"), DeliveryMode.NON_PERSISTENT, 4, 1000);
-      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
-      {
-         @SuppressWarnings("deprecation")
-         public ServerSession getServerSession()
-         {
-            Category.getInstance(getClass().getName()).debug("Getting server session.");
-            return new ServerSession()
-            {
-               public Session getSession()
-               {
-                  return session;
-               }
-               public void start()
-               {
-                  Category.getInstance(getClass().getName()).debug("Starting server session.");
-                  session.run();
-               }
-            };
-         }
-      }, 10);
-
-      queueConnection.start();
-
-      try
-      {
-         Thread.sleep(3 * 5000 + 5000);
-      }
-      catch (Exception e)
-      {
-      }
-
-      disconnect();
-      
-      assertEquals("Expected only one message, the rest should have expired", 1, processed);
-      
-      getLog().debug("Testing app server expiration passed");
-   }
-
-   /**
-    * Copy of JBossMQUnitTest.testApplicationServerStuff.
-    * 
-    * @throws Exception
-    */
-   public void testApplicationServerStuff() throws Exception
-   {
-      getLog().debug("Starting testing app server stuff");
-      connect();
-
-      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
-      final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      session.setMessageListener(new MessageListener()
-      {
-         @SuppressWarnings("deprecation")
-         public void onMessage(Message mess)
-         {
-            Category log = Category.getInstance(getClass().getName());
-            log.debug("Processing message");
-            try
-            {
-               if (mess instanceof TextMessage)
-                  log.debug(((TextMessage) mess).getText());
-            }
-            catch (Exception e)
-            {
-               log.error("Error", e);
-            }
-         }
-      });
-
-      QueueSender sender = session.createSender(testQueue);
-      sender.send(session.createTextMessage("Hi"));
-      sender.send(session.createTextMessage("There"));
-      sender.send(session.createTextMessage("Guys"));
-      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
-      {
-         @SuppressWarnings("deprecation")
-         public ServerSession getServerSession()
-         {
-            Category.getInstance(getClass().getName()).debug("Getting server session.");
-            return new ServerSession()
-            {
-               public Session getSession()
-               {
-                  return session;
-               }
-               public void start()
-               {
-                  Category.getInstance(getClass().getName()).debug("Starting server session.");
-                  session.run();
-               }
-            };
-         }
-      }, 10);
-
-      queueConnection.start();
-
-      try
-      {
-         Thread.sleep(5 * 1000);
-      }
-      catch (Exception e)
-      {
-      }
-
-      disconnect();
-      getLog().debug("Testing app server stuff passed");
-   }
-
-
-}

Copied: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328UnitTestCase.java (from rev 62599, branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328TestCase.java)
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328UnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jbossmq/test/JBAS4328UnitTestCase.java	2007-04-27 10:49:50 UTC (rev 62607)
@@ -0,0 +1,261 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jbossmq.test;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Category;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * This test checks the expiration mechanism on an application server message listener.
+ * 
+ * @author carlo
+ *
+ */
+public class JBAS4328UnitTestCase extends JBossTestCase
+{
+   /** The default TopicFactory jndi name */
+   static String TOPIC_FACTORY = "ConnectionFactory";
+   /** The default QueueFactory jndi name */
+   static String QUEUE_FACTORY = "ConnectionFactory";
+
+   static String TEST_QUEUE = "queue/testQueue";
+
+   static Context context;
+   static QueueConnection queueConnection;
+   static TopicConnection topicConnection;
+
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new JBAS4328UnitTestCase("testApplicationServerStuff"));
+      suite.addTest(new JBAS4328UnitTestCase("testApplicationServerExpiration"));
+      
+      return suite;
+   }
+   
+   public JBAS4328UnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected void connect() throws Exception
+   {
+
+      if (context == null)
+      {
+
+         context = new InitialContext();
+
+      }
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection();
+
+      getLog().debug("Connection to spyderMQ established.");
+
+   }
+
+   protected void disconnect() throws Exception
+   {
+      queueConnection.close();
+      topicConnection.close();
+   }
+
+   private int processed = 0;
+   
+   /**
+    * Copy of JBossMQUnitTest.testApplicationServerStuff with a sleep of 5 seconds
+    * during processing of the message in the message listener.
+    * 
+    * @throws Exception
+    */
+   public void testApplicationServerExpiration() throws Exception
+   {
+      getLog().debug("Starting testing app server expiration");
+      connect();
+
+      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+      final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      session.setMessageListener(new MessageListener()
+      {
+         @SuppressWarnings("deprecation")
+         public void onMessage(Message mess)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("Processing message");
+            try
+            {
+               if (System.currentTimeMillis() > mess.getJMSExpiration())
+                  log.warn("*** message is expired *** (" + System.currentTimeMillis() + " > " + mess.getJMSExpiration() + ")");
+               
+               if (mess instanceof TextMessage)
+                  log.debug(((TextMessage) mess).getText());
+               
+               // block consuming for 5 seconds
+               Thread.sleep(5000);
+               processed++;
+            }
+            catch (Exception e)
+            {
+               log.error("Error", e);
+            }
+         }
+      });
+
+      QueueSender sender = session.createSender(testQueue);
+      sender.send(session.createTextMessage("Hi"), DeliveryMode.NON_PERSISTENT, 4, 1000);
+      sender.send(session.createTextMessage("There"), DeliveryMode.NON_PERSISTENT, 4, 1000);
+      sender.send(session.createTextMessage("Guys"), DeliveryMode.NON_PERSISTENT, 4, 1000);
+      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+      {
+         @SuppressWarnings("deprecation")
+         public ServerSession getServerSession()
+         {
+            Category.getInstance(getClass().getName()).debug("Getting server session.");
+            return new ServerSession()
+            {
+               public Session getSession()
+               {
+                  return session;
+               }
+               public void start()
+               {
+                  Category.getInstance(getClass().getName()).debug("Starting server session.");
+                  session.run();
+               }
+            };
+         }
+      }, 10);
+
+      queueConnection.start();
+
+      try
+      {
+         Thread.sleep(3 * 5000 + 5000);
+      }
+      catch (Exception e)
+      {
+      }
+
+      disconnect();
+      
+      assertEquals("Expected only one message, the rest should have expired", 1, processed);
+      
+      getLog().debug("Testing app server expiration passed");
+   }
+
+   /**
+    * Copy of JBossMQUnitTest.testApplicationServerStuff.
+    * 
+    * @throws Exception
+    */
+   public void testApplicationServerStuff() throws Exception
+   {
+      getLog().debug("Starting testing app server stuff");
+      connect();
+
+      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+      final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      session.setMessageListener(new MessageListener()
+      {
+         @SuppressWarnings("deprecation")
+         public void onMessage(Message mess)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("Processing message");
+            try
+            {
+               if (mess instanceof TextMessage)
+                  log.debug(((TextMessage) mess).getText());
+            }
+            catch (Exception e)
+            {
+               log.error("Error", e);
+            }
+         }
+      });
+
+      QueueSender sender = session.createSender(testQueue);
+      sender.send(session.createTextMessage("Hi"));
+      sender.send(session.createTextMessage("There"));
+      sender.send(session.createTextMessage("Guys"));
+      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+      {
+         @SuppressWarnings("deprecation")
+         public ServerSession getServerSession()
+         {
+            Category.getInstance(getClass().getName()).debug("Getting server session.");
+            return new ServerSession()
+            {
+               public Session getSession()
+               {
+                  return session;
+               }
+               public void start()
+               {
+                  Category.getInstance(getClass().getName()).debug("Starting server session.");
+                  session.run();
+               }
+            };
+         }
+      }, 10);
+
+      queueConnection.start();
+
+      try
+      {
+         Thread.sleep(5 * 1000);
+      }
+      catch (Exception e)
+      {
+      }
+
+      disconnect();
+      getLog().debug("Testing app server stuff passed");
+   }
+
+
+}




More information about the jboss-cvs-commits mailing list