use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosExceedsPreviousAppendedPos.
@Test
@InterruptAfter(60)
public void shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosExceedsPreviousAppendedPos() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
TestNode followerA = followers.get(0), followerB = followers.get(1);
cluster.connectClient();
cluster.stopNode(followerA);
cluster.stopNode(followerB);
cluster.sendUnexpectedMessages(10);
final long commitPosition = leader.commitPosition();
while (leader.appendPosition() <= commitPosition) {
Tests.yield();
}
final long targetPosition = leader.appendPosition();
cluster.stopNode(leader);
cluster.closeClient();
followerA = cluster.startStaticNode(followerA.index(), false);
followerB = cluster.startStaticNode(followerB.index(), false);
cluster.awaitLeader();
awaitElectionClosed(followerA);
awaitElectionClosed(followerB);
cluster.connectClient();
final int messageLength = 128;
int messageCount = 0;
while (followerA.commitPosition() < targetPosition) {
cluster.pollUntilMessageSent(messageLength);
messageCount++;
}
cluster.awaitResponseMessageCount(messageCount);
cluster.awaitServiceMessageCount(followerA, messageCount);
cluster.awaitServiceMessageCount(followerB, messageCount);
final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
cluster.awaitServiceMessageCount(oldLeader, messageCount);
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldRecoverWhenLastSnapshotIsInvalidBetweenTwoElections.
@Test
@InterruptAfter(50)
void shouldRecoverWhenLastSnapshotIsInvalidBetweenTwoElections() {
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);
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 2);
cluster.awaitServicesMessageCount(numMessages * 2);
cluster.takeSnapshot(leader1);
cluster.awaitSnapshotCount(1);
cluster.stopNode(leader1);
cluster.awaitLeader(leader1.index());
cluster.awaitNewLeadershipEvent(2);
awaitAvailableWindow(cluster.client().ingressPublication());
assertTrue(cluster.client().sendKeepAlive());
cluster.startStaticNode(leader1.index(), false);
cluster.sendMessages(numMessages);
cluster.awaitResponseMessageCount(numMessages * 3);
cluster.awaitServicesMessageCount(numMessages * 3);
// No snapshot for Term 2
cluster.terminationsExpected(true);
cluster.stopAllNodes();
cluster.invalidateLatestSnapshot();
cluster.restartAllNodes(false);
cluster.awaitLeader();
cluster.awaitServicesMessageCount(numMessages * 3);
}
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 shouldRejectTakeSnapshotRequestWithAnAuthorisationError.
@Test
@InterruptAfter(10)
void shouldRejectTakeSnapshotRequestWithAnAuthorisationError() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.UNAUTHORISED_ACCESS, "Execution of the " + AdminRequestType.SNAPSHOT + " request was not authorised");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
long time = System.nanoTime();
final long deadline = time + TimeUnit.SECONDS.toNanos(2);
do {
assertEquals(0, cluster.getSnapshotCount(leader));
for (final TestNode follower : followers) {
assertEquals(0, cluster.getSnapshotCount(follower));
}
Tests.sleep(10);
time = System.nanoTime();
} while (time < deadline);
}
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);
}
Aggregations