From 1b07c3222a331e1cc18617240509a386ed00b373 Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Mon, 17 Jan 2022 16:50:19 +0100 Subject: [PATCH] NO-JIRA Fix activemq5-unit-tests with byteman --- pom.xml | 1 + tests/activemq5-unit-tests/pom.xml | 2 - ...FailoverConsumerOutstandingCommitTest.java | 126 ------------------ .../failover/FailoverTransactionTest.java | 1 - tests/extra-tests/pom.xml | 1 - tests/pom.xml | 1 + 6 files changed, 2 insertions(+), 130 deletions(-) diff --git a/pom.xml b/pom.xml index f8d44d5ec4..bccd7247a8 100644 --- a/pom.xml +++ b/pom.xml @@ -210,6 +210,7 @@ -Dlogging.configuration="file:${activemq.basedir}/tests/config/${logging.config}" -Djava.library.path="${activemq.basedir}/target/bin/lib/linux-x86_64:${activemq.basedir}/target/bin/lib/linux-i686" -Djgroups.bind_addr=localhost -Djava.net.preferIPv4Stack=true -Dbasedir=${basedir} + -Djdk.attach.allowAttachSelf=true ${project.basedir} true diff --git a/tests/activemq5-unit-tests/pom.xml b/tests/activemq5-unit-tests/pom.xml index dfd8ec96b4..b1029bff03 100644 --- a/tests/activemq5-unit-tests/pom.xml +++ b/tests/activemq5-unit-tests/pom.xml @@ -41,8 +41,6 @@ 1.9.3 2.0.0-M6 3.1.4 - 2.2.1 - diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverConsumerOutstandingCommitTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverConsumerOutstandingCommitTest.java index ed397dd2dd..be53d6fe7f 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverConsumerOutstandingCommitTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverConsumerOutstandingCommitTest.java @@ -24,7 +24,6 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -43,7 +42,6 @@ import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -161,130 +159,6 @@ public class FailoverConsumerOutstandingCommitTest extends OpenwireArtemisBaseTe connection.close(); } - @Test - @BMRules( - rules = {@BMRule( - name = "set no return response", - targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", - targetMethod = "processCommitTransactionOnePhase", - targetLocation = "ENTRY", - binding = "owconn:OpenWireConnection = $0; context = owconn.getContext()", - action = "org.apache.activemq.transport.failover.FailoverConsumerOutstandingCommitTest.holdResponse($0)"), - - @BMRule( - name = "stop broker before commit", - targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", - targetMethod = "processCommitTransactionOnePhase", - targetLocation = "ENTRY", - action = "org.apache.activemq.transport.failover.FailoverConsumerOutstandingCommitTest.stopServerInTransaction();return null")}) - public void TestFailoverConsumerOutstandingSendTxIncomplete() throws Exception { - doTestFailoverConsumerOutstandingSendTx(false); - } - - @Test - @BMRules( - rules = {@BMRule( - name = "set no return response", - targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", - targetMethod = "processCommitTransactionOnePhase", - targetLocation = "ENTRY", - action = "org.apache.activemq.transport.failover.FailoverConsumerOutstandingCommitTest.holdResponse($0)"), @BMRule( - name = "stop broker after commit", - targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", - targetMethod = "processCommitTransactionOnePhase", - targetLocation = "AT EXIT", - action = "org.apache.activemq.transport.failover.FailoverConsumerOutstandingCommitTest.stopServerInTransaction()")}) - public void TestFailoverConsumerOutstandingSendTxComplete() throws Exception { - doTestFailoverConsumerOutstandingSendTx(true); - } - - public void doTestFailoverConsumerOutstandingSendTx(final boolean doActualBrokerCommit) throws Exception { - final boolean watchTopicAdvisories = true; - server = createBroker(); - server.start(); - brokerStopLatch = new CountDownLatch(1); - - ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")"); - cf.setWatchTopicAdvisories(watchTopicAdvisories); - cf.setDispatchAsync(false); - - final ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); - connection.start(); - - final Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final Queue destination = producerSession.createQueue(QUEUE_NAME + "?consumer.prefetchSize=" + prefetch); - - final Queue signalDestination = producerSession.createQueue(QUEUE_NAME + ".signal" + "?consumer.prefetchSize=" + prefetch); - - final Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED); - - final CountDownLatch commitDoneLatch = new CountDownLatch(1); - final CountDownLatch messagesReceived = new CountDownLatch(3); - final AtomicBoolean gotCommitException = new AtomicBoolean(false); - final ArrayList receivedMessages = new ArrayList<>(); - final MessageConsumer testConsumer = consumerSession.createConsumer(destination); - doByteman.set(true); - testConsumer.setMessageListener(new MessageListener() { - - @Override - public void onMessage(Message message) { - LOG.info("consume one: " + message); - assertNotNull("got message", message); - receivedMessages.add((TextMessage) message); - try { - LOG.info("send one"); - produceMessage(consumerSession, signalDestination, 1); - LOG.info("commit session"); - consumerSession.commit(); - } catch (JMSException e) { - LOG.info("commit exception", e); - gotCommitException.set(true); - } - commitDoneLatch.countDown(); - messagesReceived.countDown(); - LOG.info("done commit"); - } - }); - - // may block if broker shutdown happens quickly - new Thread() { - @Override - public void run() { - LOG.info("producer started"); - try { - produceMessage(producerSession, destination, prefetch * 2); - } catch (javax.jms.IllegalStateException SessionClosedExpectedOnShutdown) { - } catch (JMSException e) { - e.printStackTrace(); - fail("unexpceted ex on producer: " + e); - } - LOG.info("producer done"); - } - }.start(); - - // will be stopped by the plugin - brokerStopLatch.await(); - doByteman.set(false); - server.stop(); - server = createBroker(); - server.start(); - - assertTrue("commit done through failover", commitDoneLatch.await(20, TimeUnit.SECONDS)); - assertTrue("commit failed", gotCommitException.get()); - assertTrue("another message was received after failover", messagesReceived.await(20, TimeUnit.SECONDS)); - int receivedIndex = 0; - assertEquals("get message 0 first", MESSAGE_TEXT + "0", receivedMessages.get(receivedIndex++).getText()); - if (!doActualBrokerCommit) { - // it will be redelivered and not tracked as a duplicate - assertEquals("get message 0 second", MESSAGE_TEXT + "0", receivedMessages.get(receivedIndex++).getText()); - } - assertTrue("another message was received", messagesReceived.await(20, TimeUnit.SECONDS)); - assertEquals("get message 1 eventually", MESSAGE_TEXT + "1", receivedMessages.get(receivedIndex++).getText()); - - connection.close(); - server.stop(); - } - @Test public void testRollbackFailoverConsumerTx() throws Exception { server = createBroker(); diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverTransactionTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverTransactionTest.java index d1f91d0013..218e20c5a7 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverTransactionTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverTransactionTest.java @@ -232,7 +232,6 @@ public class FailoverTransactionTest extends OpenwireArtemisBaseTest { targetClass = "org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor", targetMethod = "processMessage", targetLocation = "EXIT", - binding = "owconn:OpenWireConnection = $0; context = owconn.getContext()", action = "org.apache.activemq.transport.failover.FailoverTransactionTest.holdResponseAndStopBroker($0)")}) public void testFailoverSendReplyLost() throws Exception { LOG.info(this + " running test testFailoverSendReplyLost"); diff --git a/tests/extra-tests/pom.xml b/tests/extra-tests/pom.xml index 14febed83e..70eac22dfa 100644 --- a/tests/extra-tests/pom.xml +++ b/tests/extra-tests/pom.xml @@ -32,7 +32,6 @@ ActiveMQ Artemis Extra Tests - 4.0.11 ${project.basedir}/../.. 4.17.13.Final 2.4.7.Final diff --git a/tests/pom.xml b/tests/pom.xml index a01df13dd2..8713c1c42a 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -29,6 +29,7 @@ ${project.basedir}/.. + 4.0.18