Search in sources :

Example 16 with TestNode

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

the class ClusterToolTest method shouldNotSnapshotWhenSuspendedOnly.

@Test
@InterruptAfter(30)
void shouldNotSnapshotWhenSuspendedOnly() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final long initialSnapshotCount = leader.consensusModule().context().snapshotCounter().get();
    final CapturingPrintStream capturingPrintStream = new CapturingPrintStream();
    assertTrue(ClusterTool.suspend(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("SUSPEND applied successfully"));
    assertFalse(ClusterTool.snapshot(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    final String expectedMessage = "Unable to SNAPSHOT as the state of the consensus module is SUSPENDED, but needs to be ACTIVE";
    assertThat(capturingPrintStream.flushAndGetContent(), containsString(expectedMessage));
    assertEquals(initialSnapshotCount, leader.consensusModule().context().snapshotCounter().get());
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) Matchers.containsString(org.hamcrest.Matchers.containsString) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 17 with TestNode

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

the class DynamicMembershipTest method shouldJoinDynamicNodeToSingleStaticLeader.

@Test
@InterruptAfter(30)
public void shouldJoinDynamicNodeToSingleStaticLeader(final TestInfo testInfo) {
    cluster = aCluster().withStaticNodes(1).withDynamicNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode initialLeader = cluster.awaitLeader();
    final TestNode dynamicMember = cluster.startDynamicNode(1, true);
    awaitElectionClosed(dynamicMember);
    awaitMembershipSize(initialLeader, 2);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) SlowTest(io.aeron.test.SlowTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 18 with TestNode

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

the class DynamicMembershipTest method shouldDynamicallyJoinClusterOfThreeWithSnapshot.

@Test
@InterruptAfter(30)
public void shouldDynamicallyJoinClusterOfThreeWithSnapshot(final TestInfo testInfo) {
    cluster = aCluster().withStaticNodes(3).withDynamicNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(1);
    final TestNode dynamicMember = cluster.startDynamicNode(3, true);
    awaitElectionClosed(dynamicMember);
    assertEquals(FOLLOWER, dynamicMember.role());
    cluster.awaitSnapshotLoadedForService(dynamicMember);
    assertEquals(messageCount, dynamicMember.service().messageCount());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) SlowTest(io.aeron.test.SlowTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 19 with TestNode

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

the class ClusterTest method shouldRecoverWhenFollowersIsMultipleTermsBehindFromEmptyLogAndPartialLogWithoutCommittedLogEntry.

@Test
@InterruptAfter(40)
public void shouldRecoverWhenFollowersIsMultipleTermsBehindFromEmptyLogAndPartialLogWithoutCommittedLogEntry() {
    cluster = aCluster().withStaticNodes(5).start(4);
    systemTestWatcher.cluster(cluster);
    final int messageCount = 10;
    final int numTerms = 3;
    int totalMessages = 0;
    int partialNode = Aeron.NULL_VALUE;
    for (int i = 0; i < numTerms; i++) {
        final TestNode oldLeader = cluster.awaitLeader();
        cluster.connectClient();
        cluster.sendMessages(messageCount);
        totalMessages += messageCount;
        cluster.awaitResponseMessageCount(totalMessages);
        if (Aeron.NULL_VALUE == partialNode) {
            partialNode = (oldLeader.index() + 1) % 4;
            cluster.stopNode(cluster.node(partialNode));
        }
        cluster.stopNode(oldLeader);
        cluster.startStaticNode(oldLeader.index(), false);
        cluster.awaitLeader();
    }
    final TestNode lateJoiningNode = cluster.startStaticNode(4, true);
    cluster.awaitServiceMessageCount(lateJoiningNode, totalMessages);
    final TestNode node = cluster.startStaticNode(partialNode, false);
    cluster.awaitServiceMessageCount(node, totalMessages);
    cluster.awaitLeader();
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    totalMessages += messageCount;
    cluster.awaitResponseMessageCount(totalMessages);
    cluster.awaitServiceMessageCount(node, totalMessages);
    cluster.assertRecordingLogsEqual();
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 20 with TestNode

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

the class ClusterTest method shouldTolerateMultipleLeaderFailures.

@Test
@InterruptAfter(50)
public void shouldTolerateMultipleLeaderFailures() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode firstLeader = cluster.awaitLeader();
    cluster.stopNode(firstLeader);
    final TestNode secondLeader = cluster.awaitLeader();
    final long commitPos = secondLeader.commitPosition();
    final TestNode newFollower = cluster.startStaticNode(firstLeader.index(), false);
    cluster.awaitCommitPosition(newFollower, commitPos);
    awaitElectionClosed(newFollower);
    cluster.stopNode(secondLeader);
    cluster.awaitLeader();
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
}
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