[jboss-cvs] JBoss Messaging SVN: r5238 - 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 02:02:04 EST 2008
Author: gaohoward
Date: 2008-11-03 02:02:03 -0500 (Mon, 03 Nov 2008)
New Revision: 5238
Modified:
branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java
Log:
JBMESSAGING-1416
Modified: 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 2008-11-03 06:28:48 UTC (rev 5237)
+++ branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java 2008-11-03 07:02:03 UTC (rev 5238)
@@ -26,10 +26,12 @@
import java.util.ArrayList;
import javax.jms.Connection;
+import javax.jms.DeliveryMode;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
+import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.management.ObjectName;
@@ -195,9 +197,122 @@
}
}
}
-
- public void testOrderingWithExpiryQueue()
+
+ /*
+ * Sending 5 messages and letting the 3rd and 5th messages expire and
+ * the others (1st, 2nd and 4th) should go to the receiver
+ */
+ public void testOrderingWithExpiryQueue() throws Exception
{
+ final int NUM_MESSAGES = 5;
+
+ Connection conn = null;
+
+ ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+ try
+ {
+ ServerManagement.deployQueue("DefaultExpiry");
+
+ ServerManagement.deployQueue("TestOrderingQueue");
+
+ String defaultExpiryObjectName = "jboss.messaging.destination:service=Queue,name=DefaultExpiry";
+
+ String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=TestOrderingQueue";
+
+ ServerManagement.setAttribute(serverPeerObjectName, "DefaultExpiryQueue", defaultExpiryObjectName);
+
+ ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "ExpiryQueue", "");
+
+ Queue testQueue = (Queue)ic.lookup("/queue/TestOrderingQueue");
+
+ Queue defaultExpiry = (Queue)ic.lookup("/queue/DefaultExpiry");
+
+ conn = cf.createConnection();
+
+ {
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ JBossMessageProducer prod = (JBossMessageProducer)sess.createProducer(testQueue);
+
+ conn.start();
+
+ for (int i = 0; i < NUM_MESSAGES; i++)
+ {
+ TextMessage tm = sess.createTextMessage("Message:" + i);
+
+ if (i == 2 || i == 4)
+ {
+ // Send messages with time to live of 2000 enough time to get to client consumer - so
+ // they won't be expired on the server side
+ prod.send(tm, DeliveryMode.PERSISTENT, 4, 2000);
+ }
+ else
+ {
+ prod.send(tm);
+ }
+ }
+
+ Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ MessageConsumer cons = sess2.createConsumer(testQueue);
+
+ // The messages should now be sitting in the consumer buffer
+ // Now give them enough time to expire
+ Thread.sleep(2500);
+
+ //this moment, only first message is delivered but waiting for ack.
+ //3rd and 5th message still in queue, but when they are delivered
+ //they will be expired and won't be received by this consumer.
+ TextMessage rm1 = (TextMessage)cons.receive(1000);
+ assertNotNull(rm1);
+ assertEquals("Message:0", rm1.getText());
+ rm1.acknowledge();
+
+ TextMessage rm2 = (TextMessage)cons.receive(1000);
+ assertNotNull(rm2);
+ assertEquals("Message:1", rm2.getText());
+ rm2.acknowledge();
+
+ TextMessage rm3 = (TextMessage)cons.receive(1000);
+ assertNotNull(rm3);
+ assertEquals("Message:3", rm3.getText());
+ rm3.acknowledge();
+
+ TextMessage rm4 = (TextMessage)cons.receive(1000);
+ assertNull(rm4);
+
+ // Message should all be in the default expiry queue - let's check
+
+ MessageConsumer cons3 = sess.createConsumer(defaultExpiry);
+
+ TextMessage dm1 = (TextMessage)cons3.receive(1000);
+ assertNotNull(dm1);
+ assertEquals("Message:2", dm1.getText());
+
+ TextMessage dm2 = (TextMessage)cons3.receive(1000);
+ assertNotNull(dm2);
+ assertEquals("Message:4", dm2.getText());
+
+ conn.close();
+ }
+
+ }
+ finally
+ {
+ ServerManagement.setAttribute(serverPeerObjectName,
+ "DefaultExpiryQueue",
+ "jboss.messaging.destination:service=Queue,name=ExpiryQueue");
+
+ ServerManagement.undeployQueue("DefaultExpiry");
+
+ ServerManagement.undeployQueue("TestOrderingQueue");
+
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
// Package protected ---------------------------------------------
More information about the jboss-cvs-commits
mailing list