qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [1/3] qpid-jms git commit: NO-JIRA: add some more tx session tests
Date Wed, 27 May 2015 14:22:53 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master 96ddae77b -> e8d568dfe


NO-JIRA: add some more tx session tests


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e8d568df
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e8d568df
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e8d568df

Branch: refs/heads/master
Commit: e8d568dfe52ce20082cf8d518ed2eeaf14e9304d
Parents: be5e851
Author: Robert Gemmell <robbie@apache.org>
Authored: Wed May 27 14:34:15 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Wed May 27 15:22:37 2015 +0100

----------------------------------------------------------------------
 .../transactions/JmsTransactedSessionTest.java  | 72 ++++++++++++++++++++
 1 file changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e8d568df/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/transactions/JmsTransactedSessionTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/transactions/JmsTransactedSessionTest.java
b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/transactions/JmsTransactedSessionTest.java
index 3dd0647..b8a5eb3 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/transactions/JmsTransactedSessionTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/transactions/JmsTransactedSessionTest.java
@@ -19,11 +19,15 @@ package org.apache.qpid.jms.transactions;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
+import javax.jms.Destination;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
+import javax.jms.TextMessage;
 
 import org.apache.activemq.broker.jmx.QueueViewMBean;
 import org.apache.qpid.jms.support.AmqpTestSupport;
@@ -95,4 +99,72 @@ public class JmsTransactedSessionTest extends AmqpTestSupport {
         session.close();
         assertEquals(2, proxy.getQueueSize());
     }
+
+    @Test(timeout = 60000)
+    public void testRollbackSentMessagesThenConsumeWithTopic() throws Exception {
+        doRollbackSentMessagesThenConsumeTestImpl(true);
+    }
+
+    @Test(timeout = 60000)
+    public void testRollbackSentMessagesThenConsumeWithQueue() throws Exception {
+        doRollbackSentMessagesThenConsumeTestImpl(false);
+    }
+
+    private void doRollbackSentMessagesThenConsumeTestImpl(boolean topic) throws Exception
{
+        connection = createAmqpConnection();
+        connection.start();
+
+        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+        Destination dest = null;
+        if(topic) {
+            dest = session.createTopic(getTestName());
+        } else {
+            dest = session.createQueue(getTestName());
+        }
+
+        MessageProducer producer = session.createProducer(dest);
+        MessageConsumer consumer = session.createConsumer(dest);
+
+        int messageCount = 3;
+        TextMessage msg = null;
+        // Send messages and call rollback
+        for (int i = 1; i <= messageCount; i++) {
+            String msgText = "Message " + i;
+            msg = session.createTextMessage(msgText);
+            producer.send(msg);
+            LOG.info(msgText + " sent");
+        }
+
+        session.rollback();
+
+        // Should not consume any messages since rollback() was called
+        msg = (TextMessage) consumer.receive(200);
+        if (msg != null) {
+            fail("Received unexpected message");
+        }
+
+        // Send messages and call commit
+        for (int i = 1; i <= messageCount; i++) {
+            String msgText = "Message " + i;
+            msg = session.createTextMessage(msgText);
+            producer.send(msg);
+            LOG.info(msgText + " sent again");
+        }
+
+        session.commit();
+
+        // consume all messages
+        for (int i = 1; i <= messageCount; i++) {
+            msg = (TextMessage) consumer.receive(2000);
+            if (msg == null) {
+                fail("receive() returned null, message " + i + " was not received");
+            } else if (!msg.getText().equals("Message " + i)) {
+                fail("Received '" + msg.getText() + "' but expected 'Message " + i + "'");
+            } else {
+                LOG.info("Received: " + msg.getText());
+            }
+        }
+
+        session.commit();
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message