use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog.
@Test
@InterruptAfter(40)
public void shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode originalLeader = cluster.awaitLeader();
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.stopNode(originalLeader);
final TestNode newLeader = cluster.awaitLeader();
cluster.reconnectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount * 2);
cluster.stopNode(newLeader);
cluster.startStaticNode(newLeader.index(), false);
cluster.awaitLeader();
cluster.reconnectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount * 3);
cluster.startStaticNode(originalLeader.index(), true);
final TestNode lateJoiningNode = cluster.node(originalLeader.index());
cluster.awaitServiceMessageCount(lateJoiningNode, messageCount * 3);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldLoseLeadershipWhenNoActiveQuorumOfFollowers.
@Test
@InterruptAfter(40)
public void shouldLoseLeadershipWhenNoActiveQuorumOfFollowers() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final TestNode.TestService service = leader.service();
final List<TestNode> followers = cluster.followers();
final TestNode followerA = followers.get(0);
final TestNode followerB = followers.get(1);
assertEquals(LEADER, leader.role());
assertEquals(LEADER, service.roleChangedTo());
awaitElectionClosed(followerA);
awaitElectionClosed(followerB);
cluster.stopNode(followerA);
cluster.stopNode(followerB);
while (service.roleChangedTo() != FOLLOWER) {
Tests.sleep(100);
}
assertEquals(FOLLOWER, leader.role());
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldShutdownClusterAndRestartWithSnapshots.
@Test
@InterruptAfter(30)
public void shouldShutdownClusterAndRestartWithSnapshots() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
cluster.node(0).isTerminationExpected(true);
cluster.node(1).isTerminationExpected(true);
cluster.node(2).isTerminationExpected(true);
cluster.shutdownCluster(leader);
cluster.awaitNodeTerminations();
assertTrue(cluster.node(0).service().wasSnapshotTaken());
assertTrue(cluster.node(1).service().wasSnapshotTaken());
assertTrue(cluster.node(2).service().wasSnapshotTaken());
cluster.stopAllNodes();
cluster.restartAllNodes(false);
cluster.awaitLeader();
assertEquals(2, cluster.followers().size());
cluster.awaitSnapshotsLoaded();
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverWhenLastSnapshotForShutdownIsMarkedInvalid.
@Test
@InterruptAfter(30)
void shouldRecoverWhenLastSnapshotForShutdownIsMarkedInvalid() {
cluster = aCluster().withStaticNodes(1).start();
systemTestWatcher.cluster(cluster);
TestNode leader = cluster.awaitLeader();
final int numMessages = 3;
cluster.connectClient();
cluster.sendMessages(numMessages);
cluster.awaitServicesMessageCount(numMessages);
cluster.stopNode(leader);
cluster.startStaticNode(leader.index(), false);
leader = cluster.awaitLeader();
cluster.terminationsExpected(true);
cluster.shutdownCluster(leader);
cluster.awaitNodeTerminations();
assertTrue(leader.service().wasSnapshotTaken());
cluster.stopNode(leader);
cluster.invalidateLatestSnapshot();
cluster.restartAllNodes(false);
leader = cluster.awaitLeader();
cluster.awaitServicesMessageCount(numMessages);
assertTrue(leader.service().wasSnapshotTaken());
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosIsLessThanPreviousAppendedPos.
@Test
@InterruptAfter(30)
public void shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosIsLessThanPreviousAppendedPos() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final TestNode followerA = followers.get(0);
final TestNode followerB = followers.get(1);
cluster.connectClient();
cluster.stopNode(followerA);
cluster.stopNode(followerB);
final int messageCount = 10;
cluster.sendUnexpectedMessages(messageCount);
final long commitPosition = leader.commitPosition();
while (leader.appendPosition() <= commitPosition) {
Tests.yield();
}
cluster.stopNode(leader);
cluster.closeClient();
cluster.startStaticNode(followerA.index(), false);
cluster.startStaticNode(followerB.index(), false);
cluster.awaitLeader();
final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
awaitElectionClosed(oldLeader);
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServicesMessageCount(messageCount);
}
Aggregations