fix AMQ1924Test
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/2774f692 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/2774f692 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/2774f692 Branch: refs/heads/refactor-openwire Commit: 2774f69245b8fda997ccbd8cde7e599b5463ed09 Parents: 9e8c1e5 Author: Howard Gao <[email protected]> Authored: Tue Mar 15 23:11:39 2016 +0800 Committer: Clebert Suconic <[email protected]> Committed: Tue Mar 15 16:21:23 2016 -0400 ---------------------------------------------------------------------- .../openwire/OpenWireProtocolManager.java | 5 ++ .../transport/failover/AMQ1925Test.java | 54 +++++++++++--------- 2 files changed, 34 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2774f692/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java ---------------------------------------------------------------------- diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java index abfcca5..3cb1215 100644 --- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java +++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireProtocolManager.java @@ -488,6 +488,11 @@ public class OpenWireProtocolManager implements ProtocolManager<Interceptor>, Cl if (txSession != null) { txSession.rollback(info); } + else if (info.getTransactionId().isLocalTransaction()) { + //during a broker restart, recovered local transaction may not be registered + //in that case we ignore and let the tx removed silently by connection. + //see AMQ1925Test.testAMQ1925_TXBegin + } else { throw newXAException("Transaction '" + info.getTransactionId() + "' has not been started.", XAException.XAER_NOTA); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2774f692/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java index 3d75905..564fd86 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/AMQ1925Test.java @@ -33,8 +33,6 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.TransactionRolledBackException; -import javax.management.MBeanServer; -import javax.management.MBeanServerFactory; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.artemis.api.core.SimpleString; @@ -235,32 +233,39 @@ public class AMQ1925Test extends OpenwireArtemisBaseTest implements ExceptionLis MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE_NAME)); boolean restartDone = false; - for (int i = 0; i < MESSAGE_COUNT; i++) { - Message message = consumer.receive(5000); - Assert.assertNotNull(message); + try { + for (int i = 0; i < MESSAGE_COUNT; i++) { + Message message = consumer.receive(5000); + Assert.assertNotNull(message); - if (i == 222 && !restartDone) { - // Simulate broker failure & restart - bs.stop(); - bs = createNewServer(); - bs.start(); - restartDone = true; - } + if (i == 222 && !restartDone) { + // Simulate broker failure & restart + bs.stop(); + bs = createNewServer(); + bs.start(); + restartDone = true; + } - Assert.assertEquals(i, message.getIntProperty(PROPERTY_MSG_NUMBER)); - try { - session.commit(); - } - catch (TransactionRolledBackException expectedOnOccasion) { - log.info("got rollback: " + expectedOnOccasion); - i--; + Assert.assertEquals(i, message.getIntProperty(PROPERTY_MSG_NUMBER)); + try { + session.commit(); + } + catch (TransactionRolledBackException expectedOnOccasion) { + log.info("got rollback: " + expectedOnOccasion); + i--; + } } + Assert.assertNull(consumer.receive(500)); + } + catch (Exception eee) { + log.error("got exception", eee); + throw eee; + } + finally { + consumer.close(); + session.close(); + connection.close(); } - Assert.assertNull(consumer.receive(500)); - - consumer.close(); - session.close(); - connection.close(); assertQueueEmpty(); Assert.assertNull("no exception on connection listener: " + exception, exception); @@ -368,7 +373,6 @@ public class AMQ1925Test extends OpenwireArtemisBaseTest implements ExceptionLis } catch (Exception e) { log.error(e); } - } public void onException(JMSException exception) {
