Skip to content

Commit

Permalink
fix flaky test: ReplicaAcknowledgeReplicationEventTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie-chenchrl committed Jan 30, 2024
1 parent 941d2b4 commit 714dcc0
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
import org.junit.Test;

import javax.jms.*;
import javax.management.MalformedObjectNameException;
import java.lang.IllegalStateException;
import java.net.MalformedURLException;
import java.net.URI;

import java.text.MessageFormat;
import java.util.LinkedList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
Expand All @@ -57,6 +57,8 @@
public class ReplicaAcknowledgeReplicationEventTest extends ReplicaPluginTestSupport {
static final int MAX_BATCH_LENGTH = 500;

private static final Logger LOG = LoggerFactory.getLogger(ReplicaAcknowledgeReplicationEventTest.class);

protected Connection firstBrokerConnection;

ActiveMQConnectionFactory mockConnectionFactorySpy;
Expand Down Expand Up @@ -131,6 +133,8 @@ public void testReplicaBrokerDoNotAckOnReplicaEvent() throws Exception {
secondBroker.start();
Thread.sleep(LONG_TIMEOUT * 2);

waitUntilReplicationQueueHasConsumer(firstBroker);

waitForCondition(() -> {
try {
QueueViewMBean firstBrokerQueueView = getQueueView(firstBroker, ReplicaSupport.MAIN_REPLICATION_QUEUE_NAME);
Expand All @@ -139,8 +143,8 @@ public void testReplicaBrokerDoNotAckOnReplicaEvent() throws Exception {

QueueViewMBean secondBrokerSequenceQueueView = getQueueView(secondBroker, ReplicaSupport.SEQUENCE_REPLICATION_QUEUE_NAME);
assertEquals(secondBrokerSequenceQueueView.browseMessages().size(), 1);
} catch (Exception urlException) {
urlException.printStackTrace();
} catch (Exception|Error urlException) {
LOG.error("Caught error during wait: " + urlException.getMessage());
throw new RuntimeException(urlException);
}
});
Expand Down Expand Up @@ -190,8 +194,8 @@ public void testReplicaSendCorrectAck() throws Exception {
QueueViewMBean firstBrokerMainQueueView = getQueueView(firstBroker, ReplicaSupport.MAIN_REPLICATION_QUEUE_NAME);
assertEquals(firstBrokerMainQueueView.getDequeueCount(), messagesToAck.size());
assertEquals(firstBrokerMainQueueView.getEnqueueCount(), messagesToAck.size());
} catch (Exception urlException) {
urlException.printStackTrace();
} catch (Exception|Error urlException) {
LOG.error("Caught error during wait: " + urlException.getMessage());
throw new RuntimeException(urlException);
}
});
Expand Down Expand Up @@ -246,8 +250,8 @@ public void onMessage(Message message) {
QueueViewMBean firstBrokerMainQueueView = getQueueView(firstBroker, ReplicaSupport.MAIN_REPLICATION_QUEUE_NAME);
assertEquals(firstBrokerMainQueueView.getDequeueCount(), 0);
assertTrue(firstBrokerMainQueueView.getEnqueueCount() >= 1);
} catch (Exception urlException) {
urlException.printStackTrace();
} catch (Exception|Error urlException) {
LOG.error("Caught error during wait: " + urlException.getMessage());
throw new RuntimeException(urlException);
}
});
Expand Down

0 comments on commit 714dcc0

Please sign in to comment.