use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldCallOnRoleChangeOnBecomingLeader.
@Test
@InterruptAfter(40)
public void shouldCallOnRoleChangeOnBecomingLeader() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leaderOne = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final TestNode followerA = followers.get(0);
final TestNode followerB = followers.get(1);
awaitElectionClosed(followerA);
awaitElectionClosed(followerB);
assertEquals(LEADER, leaderOne.service().roleChangedTo());
assertNull(followerA.service().roleChangedTo());
assertNull(followerB.service().roleChangedTo());
cluster.stopNode(leaderOne);
final TestNode leaderTwo = cluster.awaitLeader(leaderOne.index());
final TestNode follower = cluster.followers().get(0);
assertEquals(LEADER, leaderTwo.service().roleChangedTo());
assertNull(follower.service().roleChangedTo());
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverWhenLeaderHasAppendedMoreThanFollower.
@Test
@InterruptAfter(40)
public void shouldRecoverWhenLeaderHasAppendedMoreThanFollower() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final TestNode followerOne = followers.get(0);
final TestNode followerTwo = followers.get(1);
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.stopNode(followerOne);
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount * 2);
cluster.stopNode(followerTwo);
cluster.stopNode(leader);
cluster.startStaticNode(leader.index(), false);
cluster.startStaticNode(followerOne.index(), false);
cluster.awaitLeader();
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldCatchUpAfterFollowerMissesMessage.
private void shouldCatchUpAfterFollowerMissesMessage(final String message) {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
TestNode follower = cluster.followers().get(0);
cluster.stopNode(follower);
cluster.connectClient();
cluster.msgBuffer().putStringWithoutLengthAscii(0, message);
cluster.pollUntilMessageSent(message.length());
cluster.awaitResponseMessageCount(1);
follower = cluster.startStaticNode(follower.index(), false);
awaitElectionClosed(follower);
assertEquals(FOLLOWER, follower.role());
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldEchoMessagesThenContinueOnNewLeader.
@Test
@InterruptAfter(40)
public void shouldEchoMessagesThenContinueOnNewLeader() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode originalLeader = cluster.awaitLeader();
cluster.connectClient();
final int preFailureMessageCount = 10;
final int postFailureMessageCount = 7;
cluster.sendMessages(preFailureMessageCount);
cluster.awaitResponseMessageCount(preFailureMessageCount);
cluster.awaitServicesMessageCount(preFailureMessageCount);
assertEquals(originalLeader.index(), cluster.client().leaderMemberId());
cluster.stopNode(originalLeader);
final TestNode newLeader = cluster.awaitLeader(originalLeader.index());
cluster.awaitNewLeadershipEvent(1);
assertEquals(newLeader.index(), cluster.client().leaderMemberId());
cluster.sendMessages(postFailureMessageCount);
cluster.awaitResponseMessageCount(preFailureMessageCount + postFailureMessageCount);
final TestNode follower = cluster.followers().get(0);
cluster.awaitServiceMessageCount(newLeader, preFailureMessageCount + postFailureMessageCount);
cluster.awaitServiceMessageCount(follower, preFailureMessageCount + postFailureMessageCount);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldAcceptMessagesAfterTwoNodeCleanRestart.
@Test
@InterruptAfter(30)
public void shouldAcceptMessagesAfterTwoNodeCleanRestart() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
TestNode followerA = followers.get(0), followerB = followers.get(1);
awaitElectionClosed(followerA);
awaitElectionClosed(followerB);
cluster.stopNode(followerA);
cluster.stopNode(followerB);
followerA = cluster.startStaticNode(followerA.index(), true);
followerB = cluster.startStaticNode(followerB.index(), true);
awaitElectionClosed(followerA);
awaitElectionClosed(followerB);
assertEquals(FOLLOWER, followerA.role());
assertEquals(FOLLOWER, followerB.role());
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServiceMessageCount(followerA, messageCount);
cluster.awaitServiceMessageCount(followerB, messageCount);
}
Aggregations