From 8cc5386fbbe7a836ac9aef3cffcb56c0b9f65adc Mon Sep 17 00:00:00 2001 From: gtully Date: Mon, 15 Jun 2020 10:20:40 +0100 Subject: [PATCH] AMQ-7497 - further test to verify behaviour after ra.stop --- .../ra/ActiveMQConnectionFactoryTest.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java index c3af265f24..4e6e25234f 100644 --- a/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java +++ b/activemq-ra/src/test/java/org/apache/activemq/ra/ActiveMQConnectionFactoryTest.java @@ -224,4 +224,88 @@ public class ActiveMQConnectionFactoryTest { } + @Test + public void testXAResourceRefAfterStop() throws Exception { + + BrokerService brokerService = new BrokerService(); + brokerService.setPersistent(false); + brokerService.addConnector("tcp://localhost:0"); + brokerService.start(); + + try { + + final TransportConnector primary = brokerService.getTransportConnectors().get(0); + + String failoverUrl = String.format("failover:(%s)?maxReconnectAttempts=1&randomize=false", primary.getConnectUri()); + + ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); + ra.start(null); + ra.setServerUrl(failoverUrl); + ra.setUserName(user); + ra.setPassword(pwd); + + XAResource[] resources = ra.getXAResources(null); + assertEquals("one resource", 1, resources.length); + + assertEquals("no pending transactions", 0, resources[0].recover(100).length); + + ra.stop(); + + try { + resources[0].recover(100); + fail("Expect error on call after stop b/c of no reconnection"); + } catch (Exception expected) { + } + + } finally { + brokerService.stop(); + } + } + + @Test + public void testXAResourceRefAfterFailAndStop() throws Exception { + + BrokerService brokerService = new BrokerService(); + brokerService.setPersistent(false); + brokerService.addConnector("tcp://localhost:0"); + brokerService.start(); + + try { + + final TransportConnector primary = brokerService.getTransportConnectors().get(0); + + String failoverUrl = String.format("failover:(%s)?maxReconnectAttempts=1&randomize=false", primary.getConnectUri()); + + ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); + ra.start(null); + ra.setServerUrl(failoverUrl); + ra.setUserName(user); + ra.setPassword(pwd); + + XAResource[] resources = ra.getXAResources(null); + assertEquals("one resource", 1, resources.length); + + assertEquals("no pending transactions", 0, resources[0].recover(100).length); + + primary.stop(); + + assertTrue("no connections", Wait.waitFor(new Wait.Condition() { + @Override + public boolean isSatisified() throws Exception { + return primary.getConnections().isEmpty(); + } + })); + + ra.stop(); + + try { + resources[0].recover(100); + fail("Expect error on call after stop b/c of no reconnection"); + } catch (Exception expected) { + } + + } finally { + brokerService.stop(); + } + } }