[jboss-cvs] JBoss Messaging SVN: r5237 - branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 3 01:28:49 EST 2008


Author: gaohoward
Date: 2008-11-03 01:28:48 -0500 (Mon, 03 Nov 2008)
New Revision: 5237

Added:
   branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java
Log:
JBMESSAGING-1416


Added: branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java
===================================================================
--- branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java	                        (rev 0)
+++ branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java	2008-11-03 06:28:48 UTC (rev 5237)
@@ -0,0 +1,230 @@
+/*
+ * 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.test.messaging.jms;
+
+import java.util.ArrayList;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.ObjectName;
+
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ * A OrderingGroupMiscTest
+ *
+ * @author HowardGao
+ * 
+ * Created Oct 31, 2008 10:44:48 AM
+ *
+ *
+ */
+public class OrderingGroupMiscTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+   private final int NUM_MESSAGES = 100;
+
+   // Attributes ----------------------------------------------------
+   private ArrayList<TextMessage> recvMsgs = new ArrayList<TextMessage>();
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public OrderingGroupMiscTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+   public void tearDown() throws Exception
+   {     
+      super.tearDown();
+      recvMsgs.clear();
+   }
+
+   /*
+    * Sending 5 messages and letting the 3rd and 5th messages go to dlq and 
+    * the others (1st, 2nd and 4th) should go to the receiver
+    */
+   public void testOrderingWithDLQ() throws Exception
+   {
+      if (ServerManagement.isRemote())
+      {
+         return;
+      }
+
+      final int NUM_MESSAGES = 5;
+
+      final int MAX_DELIVERIES = 8;
+
+      ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+      String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=Queue1";
+
+      Connection conn = null;
+
+      try
+      {
+         String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+         ServerManagement.setAttribute(serverPeerObjectName,
+                                       "DefaultMaxDeliveryAttempts",
+                                       String.valueOf(MAX_DELIVERIES));
+
+         ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+         ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
+         conn = cf.createConnection();
+
+         {
+            Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            JBossMessageProducer prod = (JBossMessageProducer)sess.createProducer(queue1);
+
+            for (int i = 0; i < NUM_MESSAGES; i++)
+            {
+               TextMessage tm = sess.createTextMessage("Message:" + i);
+
+               prod.send(tm);
+            }
+
+            Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+            MessageConsumer cons = sess2.createConsumer(queue1);
+
+            conn.start();
+
+            //first
+            TextMessage rm1 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm1);
+            assertEquals("Message:0", rm1.getText());
+            rm1.acknowledge();
+            
+            //second
+            TextMessage rm2 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm2);
+            assertEquals("Message:1", rm2.getText());
+            rm2.acknowledge();
+            
+            //third, leaving a hole
+            for (int i = 0; i < MAX_DELIVERIES; i++)
+            {
+               TextMessage rm3 = (TextMessage)cons.receive(1000);
+               assertNotNull(rm3);
+               assertEquals("Message:2", rm3.getText());
+               sess2.recover();
+            }
+
+            //fourth
+            TextMessage rm4 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm4);
+            assertEquals("Message:3", rm4.getText());
+            rm4.acknowledge();
+
+            //fifth, leaving another hole
+            for (int i = 0; i < MAX_DELIVERIES; i++)
+            {
+               TextMessage rm5 = (TextMessage)cons.receive(1000);
+               assertNotNull(rm5);
+               assertEquals("Message:4", rm5.getText());
+               sess2.recover();
+            }
+            
+            TextMessage rmx = (TextMessage)cons.receive(1000);
+            assertNull(rmx);
+
+            // At this point all the messages have been delivered exactly MAX_DELIVERIES times
+
+            checkEmpty(queue1);
+
+            // Now should be in default dlq
+            MessageConsumer cons3 = sess.createConsumer(queue2);
+
+            TextMessage dm3 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm3);
+            assertEquals("Message:2", dm3.getText());
+
+            TextMessage dm5 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm5);
+            assertEquals("Message:4", dm5.getText());
+
+            conn.close();
+         }
+      }
+      finally
+      {
+         ServerManagement.setAttribute(serverPeerObjectName,
+                                       "DefaultDLQ",
+                                       "jboss.messaging.destination:service=Queue,name=DLQ");
+
+         ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+   
+   public void testOrderingWithExpiryQueue()
+   {
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private static void doze(long tm)
+   {
+      try
+      {
+         Thread.sleep(tm);
+      }
+      catch (InterruptedException e)
+      {
+      }
+   }
+   
+   // Inner classes -------------------------------------------------
+   class MessageListenerForSelector implements MessageListener
+   {
+
+      public void onMessage(Message rmsg)
+      {
+         recvMsgs.add((TextMessage)rmsg);
+      }
+      
+   }
+}




More information about the jboss-cvs-commits mailing list