NO-JIRA Fix activemq5-unit-tests with byteman

This commit is contained in:
Domenico Francesco Bruscino 2022-01-17 16:50:19 +01:00 committed by Bruscino Domenico Francesco
parent 10d93d9c92
commit 1b07c3222a
6 changed files with 2 additions and 130 deletions

View File

@ -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
</activemq-surefire-argline>
<activemq.basedir>${project.basedir}</activemq.basedir>
<skipOWASP>true</skipOWASP>

View File

@ -41,8 +41,6 @@
<jasypt-version>1.9.3</jasypt-version>
<directory-version>2.0.0-M6</directory-version>
<activeio-core-version>3.1.4</activeio-core-version>
<byteman.version>2.2.1</byteman.version>
</properties>
<dependencies>

View File

@ -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<TextMessage> 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();

View File

@ -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");

View File

@ -32,7 +32,6 @@
<name>ActiveMQ Artemis Extra Tests</name>
<properties>
<byteman.version>4.0.11</byteman.version>
<activemq.basedir>${project.basedir}/../..</activemq.basedir>
<jboss-jts.version>4.17.13.Final</jboss-jts.version>
<hornetq.version>2.4.7.Final</hornetq.version>

View File

@ -29,6 +29,7 @@
<properties>
<activemq.basedir>${project.basedir}/..</activemq.basedir>
<byteman.version>4.0.18</byteman.version>
</properties>
<dependencyManagement>