Search in sources :

Example 36 with TestNode

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());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 37 with TestNode

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);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 38 with TestNode

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());
}
Also used : AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 39 with TestNode

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);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 40 with TestNode

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));
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) SlowTest(io.aeron.test.SlowTest) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

TestNode (io.aeron.test.cluster.TestNode)83 Test (org.junit.jupiter.api.Test)81 InterruptAfter (io.aeron.test.InterruptAfter)36 SlowTest (io.aeron.test.SlowTest)28 TestCluster (io.aeron.test.cluster.TestCluster)25 AeronCluster (io.aeron.cluster.client.AeronCluster)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MutableBoolean (org.agrona.collections.MutableBoolean)4 AeronArchive (io.aeron.archive.client.AeronArchive)3 MutableInteger (org.agrona.collections.MutableInteger)2 Aeron (io.aeron.Aeron)1 Publication (io.aeron.Publication)1 ControlledEgressListener (io.aeron.cluster.client.ControlledEgressListener)1 EgressListener (io.aeron.cluster.client.EgressListener)1 io.aeron.cluster.codecs (io.aeron.cluster.codecs)1 FOLLOWER (io.aeron.cluster.service.Cluster.Role.FOLLOWER)1 LEADER (io.aeron.cluster.service.Cluster.Role.LEADER)1 EventLogExtension (io.aeron.log.EventLogExtension)1 ControlledFragmentHandler (io.aeron.logbuffer.ControlledFragmentHandler)1 FrameDescriptor.computeMaxMessageLength (io.aeron.logbuffer.FrameDescriptor.computeMaxMessageLength)1