Search in sources :

Example 91 with TestNode

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

the class ClusterTest method shouldStopLeaderAndFollowersThenRestartAllWithSnapshot.

@Test
@InterruptAfter(30)
public void shouldStopLeaderAndFollowersThenRestartAllWithSnapshot() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(1);
    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 92 with TestNode

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

the class ClusterTest method shouldStopFollowerAndRestartFollower.

@Test
@InterruptAfter(30)
public void shouldStopFollowerAndRestartFollower() {
    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(), false);
    awaitElectionClosed(follower);
    assertEquals(FOLLOWER, follower.role());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 93 with TestNode

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

the class ClusterTest method shouldReplaySnapshotTakenWhileDown.

@Test
@InterruptAfter(40)
public void shouldReplaySnapshotTakenWhileDown() {
    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);
    TestNode followerB = followers.get(1);
    awaitElectionClosed(followerB);
    cluster.stopNode(followerB);
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(leader, 1);
    cluster.awaitSnapshotCount(followerA, 1);
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    followerB = cluster.startStaticNode(followerB.index(), false);
    cluster.awaitSnapshotCount(followerB, 1);
    assertEquals(FOLLOWER, followerB.role());
    cluster.awaitServiceMessageCount(followerB, messageCount);
    assertEquals(0L, followerB.errors());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 94 with TestNode

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

the class ClusterTest method shouldRecoverWhenFollowerIsMultipleTermsBehind.

@Test
@InterruptAfter(40)
public void shouldRecoverWhenFollowerIsMultipleTermsBehind() {
    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(), false);
    final TestNode lateJoiningNode = cluster.node(originalLeader.index());
    while (lateJoiningNode.service().messageCount() < messageCount * 3) {
        Tests.yieldingIdle("Waiting for late joining follower to catch up");
    }
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 95 with TestNode

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

the class StalledLeaderLogReplicationClusterTest method shouldHandleMultipleElections.

@Test
@InterruptAfter(60)
void shouldHandleMultipleElections() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader0 = cluster.awaitLeader();
    final int numMessages = 3;
    cluster.connectClient();
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages);
    cluster.awaitServicesMessageCount(numMessages);
    cluster.stopNode(leader0);
    final TestNode leader1 = cluster.awaitLeader(leader0.index());
    cluster.awaitNewLeadershipEvent(1);
    awaitAvailableWindow(cluster.client().ingressPublication());
    assertTrue(cluster.client().sendKeepAlive());
    cluster.startStaticNode(leader0.index(), false);
    awaitElectionClosed(cluster.node(leader0.index()));
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 2);
    cluster.awaitServicesMessageCount(numMessages * 2);
    cluster.stopNode(leader1);
    cluster.awaitLeader(leader1.index());
    cluster.awaitNewLeadershipEvent(2);
    awaitAvailableWindow(cluster.client().ingressPublication());
    assertTrue(cluster.client().sendKeepAlive());
    cluster.startStaticNode(leader1.index(), false);
    awaitElectionClosed(cluster.node(leader1.index()));
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 3);
    cluster.awaitServicesMessageCount(numMessages * 3);
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) 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