Search in sources :

Example 56 with TestNode

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

the class ClusterToolTest method shouldSuspendAndResume.

@Test
@InterruptAfter(30)
void shouldSuspendAndResume() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final CapturingPrintStream capturingPrintStream = new CapturingPrintStream();
    assertTrue(ClusterTool.suspend(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("SUSPEND applied successfully"));
    assertTrue(ClusterTool.resume(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("RESUME applied successfully"));
}
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)

Example 57 with TestNode

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

the class FailedFirstElectionClusterTest method shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog.

@Test
@EnabledForJreRange(min = JRE.JAVA_11)
@InterruptAfter(60)
public void shouldRecoverWhenFollowerIsMultipleTermsBehindFromEmptyLog() {
    final int numNodes = 3;
    final int messageCount = 10;
    final int numTerms = 3;
    final TestCluster cluster = aCluster().withStaticNodes(numNodes).start(2);
    systemTestWatcher.cluster(cluster);
    systemTestWatcher.ignoreErrorsMatching((s) -> s.contains("Forced failure"));
    int totalMessages = 0;
    for (int i = 0; i < numTerms; i++) {
        final TestNode oldLeader = cluster.awaitLeader();
        cluster.connectClient();
        cluster.sendMessages(messageCount);
        totalMessages += messageCount;
        cluster.awaitResponseMessageCount(totalMessages);
        cluster.stopNode(oldLeader);
        cluster.startStaticNode(oldLeader.index(), false);
        cluster.awaitLeader();
    }
    cluster.startStaticNode(2, true);
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    totalMessages += messageCount;
    cluster.awaitResponseMessageCount(totalMessages);
    cluster.awaitServicesMessageCount(totalMessages);
    cluster.assertRecordingLogsEqual();
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) EnabledForJreRange(org.junit.jupiter.api.condition.EnabledForJreRange) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 58 with TestNode

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

the class ClusterTest method shouldRecoverWhenLastTwosSnapshotsAreInvalidAfterElection.

@Test
@InterruptAfter(50)
void shouldRecoverWhenLastTwosSnapshotsAreInvalidAfterElection() {
    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.takeSnapshot(leader0);
    cluster.awaitSnapshotCount(1);
    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);
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 2);
    cluster.awaitServicesMessageCount(numMessages * 2);
    cluster.takeSnapshot(leader1);
    for (int i = 0; i < 3; i++) {
        cluster.awaitSnapshotCount(cluster.node(i), leader0.index() == i ? 1 : 2);
    }
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 3);
    cluster.awaitServicesMessageCount(numMessages * 3);
    cluster.takeSnapshot(leader1);
    for (int i = 0; i < 3; i++) {
        cluster.awaitSnapshotCount(cluster.node(i), leader0.index() == i ? 2 : 3);
    }
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 4);
    cluster.awaitServicesMessageCount(numMessages * 4);
    cluster.terminationsExpected(true);
    cluster.stopAllNodes();
    cluster.invalidateLatestSnapshot();
    cluster.invalidateLatestSnapshot();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    cluster.awaitSnapshotCount(2);
    cluster.awaitServicesMessageCount(numMessages * 4);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 59 with TestNode

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

the class ClusterTest method shouldEnterElectionWhenRecordingStopsOnLeader.

@Test
@InterruptAfter(30)
public void shouldEnterElectionWhenRecordingStopsOnLeader() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    cluster.connectClient();
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(leader.archive().context().localControlChannel()).controlResponseChannel(leader.archive().context().localControlChannel()).controlRequestStreamId(leader.archive().context().localControlStreamId()).aeronDirectoryName(leader.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    cluster.awaitNewLeadershipEvent(1);
    cluster.followers(2);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 60 with TestNode

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

the class ClusterTest method shouldCatchupFromEmptyLogThenSnapshotAfterShutdownAndFollowerCleanStart.

@Test
@InterruptAfter(30)
public void shouldCatchupFromEmptyLogThenSnapshotAfterShutdownAndFollowerCleanStart() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers(2);
    final TestNode followerA = followers.get(0);
    final TestNode followerB = followers.get(1);
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    leader.isTerminationExpected(true);
    followerA.isTerminationExpected(true);
    followerB.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.startStaticNode(0, false);
    cluster.startStaticNode(1, false);
    cluster.startStaticNode(2, true);
    final TestNode newLeader = cluster.awaitLeader();
    assertNotEquals(2, newLeader.index());
    assertTrue(cluster.node(0).service().wasSnapshotLoaded());
    assertTrue(cluster.node(1).service().wasSnapshotLoaded());
    assertFalse(cluster.node(2).service().wasSnapshotLoaded());
    cluster.awaitServiceMessageCount(cluster.node(2), messageCount);
    cluster.awaitSnapshotCount(cluster.node(2), 1);
    assertTrue(cluster.node(2).service().wasSnapshotTaken());
}
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