use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldReplayMultipleSnapshotsWithEmptyFollowerLog.
@Test
@InterruptAfter(30)
public void shouldReplayMultipleSnapshotsWithEmptyFollowerLog() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
int messageCount = 2;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServicesMessageCount(messageCount);
cluster.takeSnapshot(leader);
final int memberCount = 3;
for (int memberId = 0; memberId < memberCount; memberId++) {
final TestNode node = cluster.node(memberId);
cluster.awaitSnapshotCount(node, 1);
assertTrue(node.service().wasSnapshotTaken());
node.service().resetSnapshotTaken();
}
cluster.sendMessages(1);
messageCount++;
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServicesMessageCount(messageCount);
cluster.terminationsExpected(true);
cluster.awaitNeutralControlToggle(leader);
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.startStaticNode(0, false);
cluster.startStaticNode(1, false);
cluster.startStaticNode(2, true);
final TestNode newLeader = cluster.awaitLeader();
assertNotEquals(2, newLeader.index());
assertTrue(cluster.node(0).service().wasSnapshotLoaded());
assertTrue(cluster.node(1).service().wasSnapshotLoaded());
assertFalse(cluster.node(2).service().wasSnapshotLoaded());
assertEquals(messageCount, cluster.node(0).service().messageCount());
assertEquals(messageCount, cluster.node(1).service().messageCount());
// Needs a little time to replay the transactions...
Tests.await(() -> cluster.node(2).service().messageCount() >= 3);
assertEquals(messageCount, cluster.node(2).service().messageCount());
final int messageCountAfterStart = 4;
cluster.reconnectClient();
cluster.sendMessages(messageCountAfterStart);
messageCount += messageCountAfterStart;
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServicesMessageCount(messageCount);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverFollowerWhenRecordingStops.
@Test
@InterruptAfter(30)
public void shouldRecoverFollowerWhenRecordingStops() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
final TestNode follower = cluster.followers().get(0);
final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(follower.archive().context().localControlChannel()).controlResponseChannel(follower.archive().context().localControlChannel()).controlRequestStreamId(follower.archive().context().localControlStreamId()).aeronDirectoryName(follower.mediaDriver().aeronDirectoryName());
try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
final int firstRecordingIdIsTheClusterLog = 0;
assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
}
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServiceMessageCount(follower, messageCount);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldStopLeaderAndRestartAsFollower.
@Test
@InterruptAfter(40)
public void shouldStopLeaderAndRestartAsFollower() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode originalLeader = cluster.awaitLeader();
cluster.stopNode(originalLeader);
cluster.awaitLeader(originalLeader.index());
final TestNode follower = cluster.startStaticNode(originalLeader.index(), false);
awaitElectionClosed(follower);
assertEquals(FOLLOWER, follower.role());
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class AppointedLeaderTest method shouldConnectAndSendKeepAlive.
@Test
@InterruptAfter(20)
public void shouldConnectAndSendKeepAlive() {
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();
assertTrue(cluster.client().sendKeepAlive());
}
use of io.aeron.test.cluster.TestNode 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);
}
Aggregations