use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterToolTest method shouldSuspendAndResume.
@Test
@InterruptAfter(30)
void shouldSuspendAndResume() {
final TestCluster cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final CapturingPrintStream capturingPrintStream = new CapturingPrintStream();
assertTrue(ClusterTool.suspend(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
assertThat(capturingPrintStream.flushAndGetContent(), containsString("SUSPEND applied successfully"));
assertTrue(ClusterTool.resume(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
assertThat(capturingPrintStream.flushAndGetContent(), containsString("RESUME applied successfully"));
}
use of io.aeron.test.cluster.TestNode 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.TestNode in project aeron by real-logic.
the class ClusterTest method shouldRecoverWhenLastTwosSnapshotsAreInvalidAfterElection.
@Test
@InterruptAfter(50)
void shouldRecoverWhenLastTwosSnapshotsAreInvalidAfterElection() {
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.takeSnapshot(leader0);
cluster.awaitSnapshotCount(1);
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);
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 2);
cluster.awaitServicesMessageCount(numMessages * 2);
cluster.takeSnapshot(leader1);
for (int i = 0; i < 3; i++) {
cluster.awaitSnapshotCount(cluster.node(i), leader0.index() == i ? 1 : 2);
}
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 3);
cluster.awaitServicesMessageCount(numMessages * 3);
cluster.takeSnapshot(leader1);
for (int i = 0; i < 3; i++) {
cluster.awaitSnapshotCount(cluster.node(i), leader0.index() == i ? 2 : 3);
}
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 4);
cluster.awaitServicesMessageCount(numMessages * 4);
cluster.terminationsExpected(true);
cluster.stopAllNodes();
cluster.invalidateLatestSnapshot();
cluster.invalidateLatestSnapshot();
cluster.restartAllNodes(false);
cluster.awaitLeader();
cluster.awaitSnapshotCount(2);
cluster.awaitServicesMessageCount(numMessages * 4);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldEnterElectionWhenRecordingStopsOnLeader.
@Test
@InterruptAfter(30)
public void shouldEnterElectionWhenRecordingStopsOnLeader() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
cluster.connectClient();
final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(leader.archive().context().localControlChannel()).controlResponseChannel(leader.archive().context().localControlChannel()).controlRequestStreamId(leader.archive().context().localControlStreamId()).aeronDirectoryName(leader.mediaDriver().aeronDirectoryName());
try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
final int firstRecordingIdIsTheClusterLog = 0;
assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
}
cluster.awaitNewLeadershipEvent(1);
cluster.followers(2);
}
use of io.aeron.test.cluster.TestNode in project aeron by real-logic.
the class ClusterTest method shouldCatchupFromEmptyLogThenSnapshotAfterShutdownAndFollowerCleanStart.
@Test
@InterruptAfter(30)
public void shouldCatchupFromEmptyLogThenSnapshotAfterShutdownAndFollowerCleanStart() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers(2);
final TestNode followerA = followers.get(0);
final TestNode followerB = followers.get(1);
final int messageCount = 10;
cluster.connectClient();
cluster.sendMessages(messageCount);
cluster.awaitResponseMessageCount(messageCount);
leader.isTerminationExpected(true);
followerA.isTerminationExpected(true);
followerB.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.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());
cluster.awaitServiceMessageCount(cluster.node(2), messageCount);
cluster.awaitSnapshotCount(cluster.node(2), 1);
assertTrue(cluster.node(2).service().wasSnapshotTaken());
}
Aggregations