NO-JIRA fix flaky test HeuristicXATest.testRecoverHeuristicCommitWithRestart

The below error is prevented by adding Wait.assertEquals,
where Assert.assertEquals was used previously. Timeout is
set to small increments, since we rarely need to wait more
than 100 ms for the condition to become true.

java.lang.AssertionError: expected:<1> but was:<0>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:743)
	at org.junit.Assert.assertEquals(Assert.java:118)
	at org.junit.Assert.assertEquals(Assert.java:555)
	at org.junit.Assert.assertEquals(Assert.java:542)
	at org.apache.activemq.artemis.tests.integration.client.HeuristicXATest.doRecoverHeuristicCompletedTxWithRestart(HeuristicXATest.java:306)
	at org.apache.activemq.artemis.tests.integration.client.HeuristicXATest.testRecoverHeuristicCommitWithRestart(HeuristicXATest.java:251)
This commit is contained in:
Jiri Danek 2018-07-22 10:57:14 +02:00 committed by Clebert Suconic
parent a92324be35
commit cb99b4a666
1 changed files with 20 additions and 39 deletions

View File

@ -35,6 +35,7 @@ import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
import org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.Wait;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -138,19 +139,7 @@ public class HeuristicXATest extends ActiveMQTestBase {
}
if (isCommit) {
Assert.assertEquals(1, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.acknowledge();
Assert.assertEquals(body, msg.getBodyBuffer().readString());
session.commit();
session.close();
assertMessageInQueueThenReceiveAndCheckContent(server, sf);
}
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
@ -213,19 +202,7 @@ public class HeuristicXATest extends ActiveMQTestBase {
Assert.assertEquals(0, preparedTransactions.length);
if (isCommit) {
Assert.assertEquals(1, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.acknowledge();
Assert.assertEquals(body, msg.getBodyBuffer().readString());
session.commit();
session.close();
assertMessageInQueueThenReceiveAndCheckContent(server, sf);
}
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
@ -303,19 +280,7 @@ public class HeuristicXATest extends ActiveMQTestBase {
Assert.assertEquals(0, preparedTransactions.length);
if (heuristicCommit) {
Assert.assertEquals(1, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.acknowledge();
Assert.assertEquals(body, msg.getBodyBuffer().readString());
session.commit();
session.close();
assertMessageInQueueThenReceiveAndCheckContent(server, sf);
}
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
@ -345,6 +310,22 @@ public class HeuristicXATest extends ActiveMQTestBase {
session.close();
}
private void assertMessageInQueueThenReceiveAndCheckContent(ActiveMQServer server, ClientSessionFactory sf) throws Exception {
Wait.assertEquals(1, () -> getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())), 5 * 1000, 100);
ClientSession session = sf.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(1000);
Assert.assertNotNull(msg);
msg.acknowledge();
Assert.assertEquals(body, msg.getBodyBuffer().readString());
session.commit();
session.close();
}
@Test
public void testForgetHeuristicCommitAndRestart() throws Exception {
doForgetHeuristicCompletedTxAndRestart(true);