Search in sources :

Example 26 with TestNode

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

the class ClusterTest method shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosExceedsPreviousAppendedPos.

@Test
@InterruptAfter(60)
public void shouldRecoverWithUncommittedMessagesAfterRestartWhenNewCommitPosExceedsPreviousAppendedPos() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    TestNode followerA = followers.get(0), followerB = followers.get(1);
    cluster.connectClient();
    cluster.stopNode(followerA);
    cluster.stopNode(followerB);
    cluster.sendUnexpectedMessages(10);
    final long commitPosition = leader.commitPosition();
    while (leader.appendPosition() <= commitPosition) {
        Tests.yield();
    }
    final long targetPosition = leader.appendPosition();
    cluster.stopNode(leader);
    cluster.closeClient();
    followerA = cluster.startStaticNode(followerA.index(), false);
    followerB = cluster.startStaticNode(followerB.index(), false);
    cluster.awaitLeader();
    awaitElectionClosed(followerA);
    awaitElectionClosed(followerB);
    cluster.connectClient();
    final int messageLength = 128;
    int messageCount = 0;
    while (followerA.commitPosition() < targetPosition) {
        cluster.pollUntilMessageSent(messageLength);
        messageCount++;
    }
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(followerA, messageCount);
    cluster.awaitServiceMessageCount(followerB, messageCount);
    final TestNode oldLeader = cluster.startStaticNode(leader.index(), false);
    cluster.awaitServiceMessageCount(oldLeader, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 27 with TestNode

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

the class ClusterTest method shouldRecoverWhenLastSnapshotIsInvalidBetweenTwoElections.

@Test
@InterruptAfter(50)
void shouldRecoverWhenLastSnapshotIsInvalidBetweenTwoElections() {
    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);
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 2);
    cluster.awaitServicesMessageCount(numMessages * 2);
    cluster.takeSnapshot(leader1);
    cluster.awaitSnapshotCount(1);
    cluster.stopNode(leader1);
    cluster.awaitLeader(leader1.index());
    cluster.awaitNewLeadershipEvent(2);
    awaitAvailableWindow(cluster.client().ingressPublication());
    assertTrue(cluster.client().sendKeepAlive());
    cluster.startStaticNode(leader1.index(), false);
    cluster.sendMessages(numMessages);
    cluster.awaitResponseMessageCount(numMessages * 3);
    cluster.awaitServicesMessageCount(numMessages * 3);
    // No snapshot for Term 2
    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 28 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 29 with TestNode

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

the class ClusterTest method shouldRejectTakeSnapshotRequestWithAnAuthorisationError.

@Test
@InterruptAfter(10)
void shouldRejectTakeSnapshotRequestWithAnAuthorisationError() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.UNAUTHORISED_ACCESS, "Execution of the " + AdminRequestType.SNAPSHOT + " request was not authorised");
    final AeronCluster client = cluster.connectClient();
    while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.pollEgress();
        Tests.yield();
    }
    long time = System.nanoTime();
    final long deadline = time + TimeUnit.SECONDS.toNanos(2);
    do {
        assertEquals(0, cluster.getSnapshotCount(leader));
        for (final TestNode follower : followers) {
            assertEquals(0, cluster.getSnapshotCount(follower));
        }
        Tests.sleep(10);
        time = System.nanoTime();
    } while (time < deadline);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

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

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