use of io.aeron.test.cluster.TestCluster in project Aeron by real-logic.
the class SingleNodeTest method shouldStartCluster.
@Test
@InterruptAfter(20)
public void shouldStartCluster() {
final TestCluster cluster = aCluster().withStaticNodes(1).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
assertEquals(0, leader.index());
assertEquals(Cluster.Role.LEADER, leader.role());
}
use of io.aeron.test.cluster.TestCluster in project Aeron by real-logic.
the class StalledLeaderLogReplicationClusterTest method shouldHandleMultipleElections.
@Test
@InterruptAfter(60)
void shouldHandleMultipleElections() {
final TestCluster cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader0 = cluster.awaitLeader();
final int numMessages = 3;
cluster.connectClient();
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages);
cluster.awaitServicesMessageCount(numMessages);
cluster.stopNode(leader0);
final TestNode leader1 = cluster.awaitLeader(leader0.index());
cluster.awaitNewLeadershipEvent(1);
awaitAvailableWindow(cluster.client().ingressPublication());
assertTrue(cluster.client().sendKeepAlive());
cluster.startStaticNode(leader0.index(), false);
awaitElectionClosed(cluster.node(leader0.index()));
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 2);
cluster.awaitServicesMessageCount(numMessages * 2);
cluster.stopNode(leader1);
cluster.awaitLeader(leader1.index());
cluster.awaitNewLeadershipEvent(2);
awaitAvailableWindow(cluster.client().ingressPublication());
assertTrue(cluster.client().sendKeepAlive());
cluster.startStaticNode(leader1.index(), false);
awaitElectionClosed(cluster.node(leader1.index()));
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 3);
cluster.awaitServicesMessageCount(numMessages * 3);
}
use of io.aeron.test.cluster.TestCluster in project Aeron by real-logic.
the class AppointedLeaderTest method shouldEchoMessagesViaService.
@Test
@InterruptAfter(20)
public void shouldEchoMessagesViaService() {
final TestCluster cluster = aCluster().withStaticNodes(3).withAppointedLeader(LEADER_ID).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
assertEquals(LEADER_ID, leader.index());
assertEquals(Cluster.Role.LEADER, leader.role());
cluster.connectClient();
final int messageCount = 10;
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServicesMessageCount(messageCount);
}
use of io.aeron.test.cluster.TestCluster in project Aeron by real-logic.
the class FailedFirstElectionClusterTest method shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog.
@Test
@EnabledForJreRange(min = JRE.JAVA_11)
@InterruptAfter(60)
public void shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog() {
final int numNodes = 3;
final int messageCount = 10;
final int numTerms = 3;
final TestCluster cluster = aCluster().withStaticNodes(numNodes).start(2);
systemTestWatcher.cluster(cluster);
systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("Forced failure"));
int totalMessages = 0;
for (int i = 0; i < numTerms; i++) {
final TestNode oldLeader = cluster.awaitLeader();
cluster.connectClient();
cluster.sendMessages(messageCount);
totalMessages += messageCount;
cluster.awaitResponseMessageCount(totalMessages);
cluster.stopNode(oldLeader);
cluster.startStaticNode(oldLeader.index(), false);
cluster.awaitLeader();
}
cluster.startStaticNode(2, true);
cluster.connectClient();
cluster.sendMessages(messageCount);
totalMessages += messageCount;
cluster.awaitResponseMessageCount(totalMessages);
cluster.awaitServicesMessageCount(totalMessages);
cluster.assertRecordingLogsEqual();
}
use of io.aeron.test.cluster.TestCluster in project Aeron by real-logic.
the class MultiNodeTest method shouldCatchUpWithAppointedLeaderWithThreeNodesWithNoSnapshot.
@Test
@InterruptAfter(20)
public void shouldCatchUpWithAppointedLeaderWithThreeNodesWithNoSnapshot() {
final int appointedLeaderIndex = 1;
final TestCluster cluster = aCluster().withStaticNodes(3).withAppointedLeader(appointedLeaderIndex).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
assertEquals(appointedLeaderIndex, leader.index());
assertEquals(Cluster.Role.LEADER, leader.role());
final int preCatchupMessageCount = 5;
final int postCatchupMessageCount = 10;
final int totalMessageCount = preCatchupMessageCount + postCatchupMessageCount;
cluster.connectClient();
cluster.sendMessages(preCatchupMessageCount);
cluster.awaitResponseMessageCount(preCatchupMessageCount);
cluster.awaitServicesMessageCount(preCatchupMessageCount);
cluster.stopNode(cluster.node(0));
cluster.sendMessages(postCatchupMessageCount);
cluster.awaitResponseMessageCount(totalMessageCount);
cluster.awaitServicesMessageCount(totalMessageCount);
cluster.stopAllNodes();
cluster.restartAllNodes(false);
cluster.awaitLeader();
cluster.awaitServicesMessageCount(totalMessageCount);
}
Aggregations