You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/27 23:23:39 UTC

qpid-jms git commit: Ensure rollback of already failed TX cleans up state, add test to cover.

Repository: qpid-jms
Updated Branches:
  refs/heads/master 16c8ffd69 -> a9f17a890


Ensure rollback of already failed TX cleans up state, add test to cover.

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

Branch: refs/heads/master
Commit: a9f17a890cd3c27d170bc8d3c29a58ae4f729e5a
Parents: 16c8ffd
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Jan 27 17:12:32 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Jan 27 17:12:32 2015 -0500

----------------------------------------------------------------------
 .../qpid/jms/JmsLocalTransactionContext.java    | 11 ++++++
 .../jms/failover/JmsTxProducerFailoverTest.java | 40 ++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/a9f17a89/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsLocalTransactionContext.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsLocalTransactionContext.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsLocalTransactionContext.java
index 0582c7c..886ac5f 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsLocalTransactionContext.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsLocalTransactionContext.java
@@ -117,6 +117,15 @@ public class JmsLocalTransactionContext implements JmsTransactionContext {
 
     @Override
     public void rollback() throws JMSException {
+
+        if (isFailed()) {
+            LOG.debug("Rollback of already failed TX: {} syncCount: {}", transactionId,
+                      (synchronizations != null ? synchronizations.size() : 0));
+
+            failed = false;
+            transactionId = null;
+        }
+
         if (isInTransaction()) {
             LOG.debug("Rollback: {} syncCount: {}", transactionId,
                       (synchronizations != null ? synchronizations.size() : 0));
@@ -136,6 +145,8 @@ public class JmsLocalTransactionContext implements JmsTransactionContext {
     @Override
     public void commit() throws JMSException {
         if (isFailed()) {
+            failed = false;
+            transactionId = null;
             throw new TransactionRolledBackException("Transaction failed and must be rolled back.");
         }
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/a9f17a89/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/failover/JmsTxProducerFailoverTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/failover/JmsTxProducerFailoverTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/failover/JmsTxProducerFailoverTest.java
index 7087a7e..928bd0a 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/failover/JmsTxProducerFailoverTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/failover/JmsTxProducerFailoverTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
 import java.net.URI;
 
 import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
@@ -143,6 +144,45 @@ public class JmsTxProducerFailoverTest extends AmqpTestSupport {
         assertEquals(0, proxy.getQueueSize());
     }
 
+    @Test
+    public void testTxProducerRollbackAfterFailoverGetsNoErrors() throws Exception {
+        URI brokerURI = new URI("failover://("+ getBrokerAmqpConnectionURI() +")?maxReconnectDelay=100");
+
+        connection = createAmqpConnection(brokerURI);
+        connection.start();
+
+        final int MSG_COUNT = 5;
+        final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+        Queue queue = session.createQueue(name.getMethodName());
+        final MessageProducer producer = session.createProducer(queue);
+        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+        QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
+        assertEquals(0, proxy.getQueueSize());
+
+        for (int i = 0; i < MSG_COUNT; ++i) {
+            LOG.debug("Producer sening message #{}", i + 1);
+            producer.send(session.createTextMessage("Message: " + i));
+        }
+
+        assertEquals(0, proxy.getQueueSize());
+
+        stopPrimaryBroker();
+        restartPrimaryBroker();
+
+        proxy = getProxyToQueue(name.getMethodName());
+        assertEquals(0, proxy.getQueueSize());
+
+        try {
+            session.rollback();
+            LOG.info("Transacted rollback after failover ok");
+        } catch (JMSException ex) {
+            fail("Session rollback should not have failed.");
+        }
+
+        assertEquals(0, proxy.getQueueSize());
+    }
+
     /*
      * Tests that if some sends happen and then a failover followed by additional
      * sends the commit will fail and no messages are left on the broker.


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