Search in sources :

Example 31 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 32 with TestNode

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

the class ClusterTest method shouldAbortClusterAndRestart.

@Test
@InterruptAfter(30)
public void shouldAbortClusterAndRestart() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.node(0).isTerminationExpected(true);
    cluster.node(1).isTerminationExpected(true);
    cluster.node(2).isTerminationExpected(true);
    cluster.abortCluster(leader);
    cluster.awaitNodeTerminations();
    assertFalse(cluster.node(0).service().wasSnapshotTaken());
    assertFalse(cluster.node(1).service().wasSnapshotTaken());
    assertFalse(cluster.node(2).service().wasSnapshotTaken());
    cluster.stopAllNodes();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    assertEquals(2, cluster.followers().size());
    assertFalse(cluster.node(0).service().wasSnapshotLoaded());
    assertFalse(cluster.node(1).service().wasSnapshotLoaded());
    assertFalse(cluster.node(2).service().wasSnapshotLoaded());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 33 with TestNode

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

the class ClusterTest method shouldStopLeaderAndRestartAsFollowerWithSendingAfterThenStopLeader.

@Test
@InterruptAfter(60)
public void shouldStopLeaderAndRestartAsFollowerWithSendingAfterThenStopLeader() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode originalLeader = cluster.awaitLeader();
    cluster.stopNode(originalLeader);
    cluster.awaitLeader(originalLeader.index());
    final TestNode follower = cluster.startStaticNode(originalLeader.index(), false);
    awaitElectionClosed(follower);
    assertEquals(FOLLOWER, follower.role());
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    final TestNode leader = cluster.awaitLeader();
    cluster.stopNode(leader);
    cluster.awaitLeader(leader.index());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 34 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 35 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)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