Search in sources :

Example 6 with TestNode

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

the class ClusterTest method shouldRecoverFollowerWhenRecordingStops.

@Test
@InterruptAfter(30)
public void shouldRecoverFollowerWhenRecordingStops() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final TestNode follower = cluster.followers().get(0);
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(follower.archive().context().localControlChannel()).controlResponseChannel(follower.archive().context().localControlChannel()).controlRequestStreamId(follower.archive().context().localControlStreamId()).aeronDirectoryName(follower.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(follower, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 7 with TestNode

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

the class ClusterTest method shouldRecoverWhenLastSnapshotIsMarkedInvalid.

@Test
@InterruptAfter(40)
void shouldRecoverWhenLastSnapshotIsMarkedInvalid() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader0 = cluster.awaitLeader();
    final int numMessages = 3;
    cluster.connectClient();
    cluster.sendMessages(numMessages);
    cluster.awaitServicesMessageCount(numMessages);
    cluster.takeSnapshot(leader0);
    cluster.awaitSnapshotCount(1);
    cluster.sendMessages(numMessages);
    cluster.awaitServicesMessageCount(numMessages * 2);
    cluster.takeSnapshot(leader0);
    cluster.awaitSnapshotCount(2);
    cluster.stopNode(leader0);
    cluster.awaitLeader(leader0.index());
    cluster.awaitNewLeadershipEvent(1);
    awaitAvailableWindow(cluster.client().ingressPublication());
    assertTrue(cluster.client().sendKeepAlive());
    cluster.startStaticNode(leader0.index(), false);
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 3);
    cluster.awaitServicesMessageCount(numMessages * 3);
    cluster.terminationsExpected(true);
    cluster.stopAllNodes();
    cluster.invalidateLatestSnapshot();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    cluster.awaitServicesMessageCount(numMessages * 3);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 8 with TestNode

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

the class ClusterTest method shouldHandleMultipleElections.

@Test
@InterruptAfter(60)
void shouldHandleMultipleElections() {
    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 : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 9 with TestNode

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

the class ClusterTest method shouldTerminateLeaderWhenServiceStops.

@Test
@InterruptAfter(30)
public void shouldTerminateLeaderWhenServiceStops() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.connectClient();
    leader.isTerminationExpected(true);
    leader.container().close();
    while (!leader.hasMemberTerminated()) {
        Tests.sleep(1);
    }
    cluster.awaitNewLeadershipEvent(1);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

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

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