Search in sources :

Example 76 with TestNode

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

the class ClusterTest method shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog.

@Test
@InterruptAfter(40)
public void shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode originalLeader = cluster.awaitLeader();
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.stopNode(originalLeader);
    final TestNode newLeader = cluster.awaitLeader();
    cluster.reconnectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount * 2);
    cluster.stopNode(newLeader);
    cluster.startStaticNode(newLeader.index(), false);
    cluster.awaitLeader();
    cluster.reconnectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount * 3);
    cluster.startStaticNode(originalLeader.index(), true);
    final TestNode lateJoiningNode = cluster.node(originalLeader.index());
    cluster.awaitServiceMessageCount(lateJoiningNode, messageCount * 3);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 77 with TestNode

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

the class ClusterTest method shouldLoseLeadershipWhenNoActiveQuorumOfFollowers.

@Test
@InterruptAfter(40)
public void shouldLoseLeadershipWhenNoActiveQuorumOfFollowers() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final TestNode.TestService service = leader.service();
    final List<TestNode> followers = cluster.followers();
    final TestNode followerA = followers.get(0);
    final TestNode followerB = followers.get(1);
    assertEquals(LEADER, leader.role());
    assertEquals(LEADER, service.roleChangedTo());
    awaitElectionClosed(followerA);
    awaitElectionClosed(followerB);
    cluster.stopNode(followerA);
    cluster.stopNode(followerB);
    while (service.roleChangedTo() != FOLLOWER) {
        Tests.sleep(100);
    }
    assertEquals(FOLLOWER, leader.role());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 78 with TestNode

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

the class ClusterTest method shouldShutdownClusterAndRestartWithSnapshots.

@Test
@InterruptAfter(30)
public void shouldShutdownClusterAndRestartWithSnapshots() {
    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.shutdownCluster(leader);
    cluster.awaitNodeTerminations();
    assertTrue(cluster.node(0).service().wasSnapshotTaken());
    assertTrue(cluster.node(1).service().wasSnapshotTaken());
    assertTrue(cluster.node(2).service().wasSnapshotTaken());
    cluster.stopAllNodes();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    assertEquals(2, cluster.followers().size());
    cluster.awaitSnapshotsLoaded();
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 79 with TestNode

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

the class ClusterTest method shouldRecoverWhenLastSnapshotForShutdownIsMarkedInvalid.

@Test
@InterruptAfter(30)
void shouldRecoverWhenLastSnapshotForShutdownIsMarkedInvalid() {
    cluster = aCluster().withStaticNodes(1).start();
    systemTestWatcher.cluster(cluster);
    TestNode leader = cluster.awaitLeader();
    final int numMessages = 3;
    cluster.connectClient();
    cluster.sendMessages(numMessages);
    cluster.awaitServicesMessageCount(numMessages);
    cluster.stopNode(leader);
    cluster.startStaticNode(leader.index(), false);
    leader = cluster.awaitLeader();
    cluster.terminationsExpected(true);
    cluster.shutdownCluster(leader);
    cluster.awaitNodeTerminations();
    assertTrue(leader.service().wasSnapshotTaken());
    cluster.stopNode(leader);
    cluster.invalidateLatestSnapshot();
    cluster.restartAllNodes(false);
    leader = cluster.awaitLeader();
    cluster.awaitServicesMessageCount(numMessages);
    assertTrue(leader.service().wasSnapshotTaken());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 80 with TestNode

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

the class ClusterTest method shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosIsLessThanPreviousAppendedPos.

@Test
@InterruptAfter(30)
public void shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosIsLessThanPreviousAppendedPos() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    final TestNode followerA = followers.get(0);
    final TestNode followerB = followers.get(1);
    cluster.connectClient();
    cluster.stopNode(followerA);
    cluster.stopNode(followerB);
    final int messageCount = 10;
    cluster.sendUnexpectedMessages(messageCount);
    final long commitPosition = leader.commitPosition();
    while (leader.appendPosition() <= commitPosition) {
        Tests.yield();
    }
    cluster.stopNode(leader);
    cluster.closeClient();
    cluster.startStaticNode(followerA.index(), false);
    cluster.startStaticNode(followerB.index(), false);
    cluster.awaitLeader();
    final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
    awaitElectionClosed(oldLeader);
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(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