Search in sources :

Example 71 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 72 with TestNode

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

the class ClusterTest method shouldRecoverWhenLeaderHasAppendedMoreThanFollower.

@Test
@InterruptAfter(40)
public void shouldRecoverWhenLeaderHasAppendedMoreThanFollower() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    final TestNode followerOne = followers.get(0);
    final TestNode followerTwo = followers.get(1);
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.stopNode(followerOne);
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount * 2);
    cluster.stopNode(followerTwo);
    cluster.stopNode(leader);
    cluster.startStaticNode(leader.index(), false);
    cluster.startStaticNode(followerOne.index(), false);
    cluster.awaitLeader();
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 73 with TestNode

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

the class ClusterTest method shouldCatchUpAfterFollowerMissesMessage.

private void shouldCatchUpAfterFollowerMissesMessage(final String message) {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    TestNode follower = cluster.followers().get(0);
    cluster.stopNode(follower);
    cluster.connectClient();
    cluster.msgBuffer().putStringWithoutLengthAscii(0, message);
    cluster.pollUntilMessageSent(message.length());
    cluster.awaitResponseMessageCount(1);
    follower = cluster.startStaticNode(follower.index(), false);
    awaitElectionClosed(follower);
    assertEquals(FOLLOWER, follower.role());
}
Also used : TestNode(io.aeron.test.cluster.TestNode)

Example 74 with TestNode

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

the class ClusterTest method shouldEchoMessagesThenContinueOnNewLeader.

@Test
@InterruptAfter(40)
public void shouldEchoMessagesThenContinueOnNewLeader() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode originalLeader = cluster.awaitLeader();
    cluster.connectClient();
    final int preFailureMessageCount = 10;
    final int postFailureMessageCount = 7;
    cluster.sendMessages(preFailureMessageCount);
    cluster.awaitResponseMessageCount(preFailureMessageCount);
    cluster.awaitServicesMessageCount(preFailureMessageCount);
    assertEquals(originalLeader.index(), cluster.client().leaderMemberId());
    cluster.stopNode(originalLeader);
    final TestNode newLeader = cluster.awaitLeader(originalLeader.index());
    cluster.awaitNewLeadershipEvent(1);
    assertEquals(newLeader.index(), cluster.client().leaderMemberId());
    cluster.sendMessages(postFailureMessageCount);
    cluster.awaitResponseMessageCount(preFailureMessageCount + postFailureMessageCount);
    final TestNode follower = cluster.followers().get(0);
    cluster.awaitServiceMessageCount(newLeader, preFailureMessageCount + postFailureMessageCount);
    cluster.awaitServiceMessageCount(follower, preFailureMessageCount + postFailureMessageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 75 with TestNode

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

the class ClusterTest method shouldAcceptMessagesAfterTwoNodeCleanRestart.

@Test
@InterruptAfter(30)
public void shouldAcceptMessagesAfterTwoNodeCleanRestart() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    TestNode followerA = followers.get(0), followerB = followers.get(1);
    awaitElectionClosed(followerA);
    awaitElectionClosed(followerB);
    cluster.stopNode(followerA);
    cluster.stopNode(followerB);
    followerA = cluster.startStaticNode(followerA.index(), true);
    followerB = cluster.startStaticNode(followerB.index(), true);
    awaitElectionClosed(followerA);
    awaitElectionClosed(followerB);
    assertEquals(FOLLOWER, followerA.role());
    assertEquals(FOLLOWER, followerB.role());
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(followerA, messageCount);
    cluster.awaitServiceMessageCount(followerB, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

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