Search in sources :

Example 61 with TestNode

use of io.aeron.test.cluster.TestNode in project aeron by real-logic.

the class ClusterTest method shouldCatchUpTwoFreshNodesAfterRestart.

@Test
@InterruptAfter(30)
public void shouldCatchUpTwoFreshNodesAfterRestart() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    final int messageCount = 50_000;
    cluster.connectClient();
    cluster.msgBuffer().putStringWithoutLengthAscii(0, NO_OP_MSG);
    for (int i = 0; i < messageCount; i++) {
        cluster.pollUntilMessageSent(NO_OP_MSG.length());
    }
    cluster.awaitResponseMessageCount(messageCount);
    cluster.terminationsExpected(true);
    cluster.abortCluster(leader);
    cluster.awaitNodeTerminations();
    cluster.stopAllNodes();
    final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
    final TestNode oldFollower1 = cluster.startStaticNode(followers.get(0).index(), true);
    final TestNode oldFollower2 = cluster.startStaticNode(followers.get(1).index(), true);
    cluster.awaitLeader();
    cluster.awaitServicesMessageCount(messageCount);
    assertEquals(0L, oldLeader.errors());
    assertEquals(0L, oldFollower1.errors());
    assertEquals(0L, oldFollower2.errors());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 62 with TestNode

use of io.aeron.test.cluster.TestNode in project aeron by real-logic.

the class ClusterTest method shouldRecoverWhenFollowerArrivesPartWayThroughTerm.

@Test
@InterruptAfter(40)
public void shouldRecoverWhenFollowerArrivesPartWayThroughTerm() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final TestNode followerOne = cluster.followers().get(0);
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.stopNode(followerOne);
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount * 2);
    cluster.startStaticNode(followerOne.index(), false);
    // Needs a little time to replay the transactions...
    Tests.await(() -> cluster.node(followerOne.index()).service().messageCount() >= messageCount * 2);
    assertEquals(messageCount * 2, cluster.node(followerOne.index()).service().messageCount());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 63 with TestNode

use of io.aeron.test.cluster.TestNode in project aeron by real-logic.

the class DynamicMembershipTest method shouldDynamicallyJoinClusterOfThreeNoSnapshotsThenSend.

@Test
@InterruptAfter(30)
public void shouldDynamicallyJoinClusterOfThreeNoSnapshotsThenSend(final TestInfo testInfo) {
    cluster = aCluster().withStaticNodes(3).withDynamicNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final TestNode dynamicMember = cluster.startDynamicNode(3, true);
    awaitElectionClosed(dynamicMember);
    assertEquals(FOLLOWER, dynamicMember.role());
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(leader, messageCount);
    cluster.awaitServiceMessageCount(dynamicMember, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) SlowTest(io.aeron.test.SlowTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 64 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)

Example 65 with TestNode

use of io.aeron.test.cluster.TestNode in project aeron by real-logic.

the class DynamicMembershipTest method shouldJoinDynamicNodeToSingleStaticLeader.

@Test
@InterruptAfter(30)
public void shouldJoinDynamicNodeToSingleStaticLeader(final TestInfo testInfo) {
    cluster = aCluster().withStaticNodes(1).withDynamicNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode initialLeader = cluster.awaitLeader();
    final TestNode dynamicMember = cluster.startDynamicNode(1, true);
    awaitElectionClosed(dynamicMember);
    awaitMembershipSize(initialLeader, 2);
}
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)166 Test (org.junit.jupiter.api.Test)162 InterruptAfter (io.aeron.test.InterruptAfter)72 SlowTest (io.aeron.test.SlowTest)56 TestCluster (io.aeron.test.cluster.TestCluster)50 AeronCluster (io.aeron.cluster.client.AeronCluster)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 MutableBoolean (org.agrona.collections.MutableBoolean)8 AeronArchive (io.aeron.archive.client.AeronArchive)6 MutableInteger (org.agrona.collections.MutableInteger)4 Aeron (io.aeron.Aeron)2 Publication (io.aeron.Publication)2 ControlledEgressListener (io.aeron.cluster.client.ControlledEgressListener)2 EgressListener (io.aeron.cluster.client.EgressListener)2 io.aeron.cluster.codecs (io.aeron.cluster.codecs)2 FOLLOWER (io.aeron.cluster.service.Cluster.Role.FOLLOWER)2 LEADER (io.aeron.cluster.service.Cluster.Role.LEADER)2 EventLogExtension (io.aeron.log.EventLogExtension)2 ControlledFragmentHandler (io.aeron.logbuffer.ControlledFragmentHandler)2 FrameDescriptor.computeMaxMessageLength (io.aeron.logbuffer.FrameDescriptor.computeMaxMessageLength)2