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 shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll.
@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll() {
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
assertEquals(AdminRequestType.SNAPSHOT, type);
return true;
}).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminRequestControlledEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.controlledPollEgress();
Tests.yield();
}
cluster.awaitSnapshotCount(1);
cluster.awaitNeutralControlToggle(leader);
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldCloseClientOnTimeout.
@Test
@InterruptAfter(20)
public void shouldCloseClientOnTimeout() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final AeronCluster client = cluster.connectClient();
final ConsensusModule.Context context = leader.consensusModule().context();
assertEquals(0, context.timedOutClientCounter().get());
assertFalse(client.isClosed());
Tests.sleep(NANOSECONDS.toMillis(context.sessionTimeoutNs()));
cluster.shouldErrorOnClientClose(false);
while (!client.isClosed()) {
Tests.sleep(1);
client.pollEgress();
}
assertEquals(1, context.timedOutClientCounter().get());
}
use of io.aeron.test.cluster.TestNode in project Aeron by real-logic.
the class ClusterTest method shouldAcceptMessagesAfterSingleNodeCleanRestart.
@Test
@InterruptAfter(40)
public void shouldAcceptMessagesAfterSingleNodeCleanRestart() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
TestNode follower = cluster.followers().get(0);
awaitElectionClosed(follower);
cluster.stopNode(follower);
follower = cluster.startStaticNode(follower.index(), true);
awaitElectionClosed(cluster.node(follower.index()));
assertEquals(FOLLOWER, follower.role());
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 DynamicMembershipTest method shouldRemoveLeaderAfterDynamicNodeJoinedThenRestartCluster.
@Test
@InterruptAfter(30)
public void shouldRemoveLeaderAfterDynamicNodeJoinedThenRestartCluster(final TestInfo testInfo) {
cluster = aCluster().withStaticNodes(3).withDynamicNodes(1).start();
systemTestWatcher.cluster(cluster);
final TestNode initialLeader = cluster.awaitLeader();
final TestNode dynamicMember = cluster.startDynamicNode(3, true);
awaitElectionClosed(dynamicMember);
awaitMembershipSize(initialLeader, 4);
final int initialLeaderIndex = initialLeader.index();
initialLeader.isTerminationExpected(true);
initialLeader.removeMember(initialLeaderIndex, false);
cluster.awaitNodeTermination(initialLeader);
cluster.stopNode(initialLeader);
final TestNode newLeader = cluster.awaitLeader(initialLeaderIndex);
final ClusterMembership clusterMembership = awaitMembershipSize(newLeader, 3);
assertEquals(newLeader.index(), clusterMembership.leaderMemberId);
assertNotEquals(initialLeaderIndex, clusterMembership.leaderMemberId);
cluster.stopAllNodes();
for (int i = 0; i < 3; i++) {
if (initialLeaderIndex != i) {
cluster.startStaticNode(i, false);
}
}
cluster.awaitLeader();
assertEquals(1, cluster.followers().size());
awaitElectionClosed(cluster.followers().get(0));
}
Aggregations