[jboss-cvs] JBoss Messaging SVN: r5191 - 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
Tue Oct 28 03:55:48 EDT 2008
Author: gaohoward
Date: 2008-10-28 03:55:48 -0400 (Tue, 28 Oct 2008)
New Revision: 5191
Added:
branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java
Log:
JBMESSAGING-1416
Added: branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java
===================================================================
--- branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java (rev 0)
+++ branches/Branch_JBMESSAGING_1416/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java 2008-10-28 07:55:48 UTC (rev 5191)
@@ -0,0 +1,215 @@
+/*
+ * 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 javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.QueueConnection;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.client.JBossMessageProducer;
+
+/**
+ * A OrderingGroupAckTest
+ *
+ * @author howard
+ *
+ * Created Oct 28, 2008 2:30:18 PM
+ *
+ *
+ */
+public class OrderingGroupAckTest extends JMSTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+ public OrderingGroupAckTest(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+ /*
+ * This test shows how ordering group delivery handles transactions.
+ * A rollback will cause the first message to be re-delivered.
+ * A commit will cause the second message to be available for delivery.
+ */
+ public void testRollbackCommit() throws Exception
+ {
+ QueueConnection conn = null;
+
+ try
+ {
+ conn = cf.createQueueConnection();
+ QueueSession sess = conn.createQueueSession(true, 0);
+ JBossMessageProducer producer = (JBossMessageProducer)sess.createProducer(queue1);
+ producer.enableOrderingGroup(null);
+
+ QueueReceiver cons = sess.createReceiver(queue1);
+
+ conn.start();
+
+ Message m1 = sess.createTextMessage("testing1");
+ Message m2 = sess.createTextMessage("testing2");
+ producer.send(m1);
+ producer.send(m2);
+
+ sess.commit();
+
+ TextMessage mr = (TextMessage)cons.receive(3000);
+ assertNotNull(mr);
+ assertEquals("testing1", mr.getText());
+
+ sess.rollback();
+
+ mr = (TextMessage)cons.receive(3000);
+ assertNotNull(mr);
+ assertEquals("testing1", mr.getText());
+
+ //second message cannot be received
+ //if the first message is not committed.
+ mr = (TextMessage)cons.receive(3000);
+ assertNull(mr);
+
+ sess.commit();
+
+ mr = (TextMessage)cons.receive(3000);
+ assertNotNull(mr);
+ assertEquals("testing2", mr.getText());
+
+ sess.commit();
+
+ checkEmpty(queue1);
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+
+ /*
+ * This test shows how ordering group handle client acknowledge.
+ * the second message will never be sent out unless the first message is acked.
+ */
+ public void testClientAcknowledge() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ JBossMessageProducer producer = (JBossMessageProducer)producerSess.createProducer(queue1);
+ producer.enableOrderingGroup(null);
+
+ Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ MessageConsumer consumer = consumerSess.createConsumer(queue1);
+ conn.start();
+
+ final int NUM_MSG = 100;
+
+ //Send some messages
+ for (int i = 0; i < 100; ++i)
+ {
+ TextMessage tm = producerSess.createTextMessage("ordering" + i);
+ producer.send(tm);
+ }
+
+ assertRemainingMessages(NUM_MSG);
+
+ log.trace("Sent messages");
+
+ int count = 0;
+ while (true)
+ {
+ Message m = consumer.receive(400);
+ if (m == null) break;
+ count++;
+ }
+
+ assertRemainingMessages(NUM_MSG);
+
+ log.trace("Received " + count + " messages");
+
+ //if ordering group, count should be 1.
+ assertEquals(1, count);
+
+ consumerSess.recover();
+
+ assertRemainingMessages(NUM_MSG);
+
+ log.trace("Session recover called");
+
+ TextMessage m = null;
+
+ int i = 0;
+ for (; i < 100; ++i)
+ {
+ m = (TextMessage)consumer.receive();
+ log.trace("Received message " + i);
+ m.acknowledge();
+ assertTrue(m.getText().equals("ordering" + i));
+ }
+
+ assertRemainingMessages(0);
+
+ // make sure I don't receive anything else
+
+ checkEmpty(queue1);
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list