Search in sources :

Example 31 with TestCluster

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

the class SingleNodeTest method shouldStartCluster.

@Test
@InterruptAfter(20)
public void shouldStartCluster() {
    final TestCluster cluster = aCluster().withStaticNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    assertEquals(0, leader.index());
    assertEquals(Cluster.Role.LEADER, leader.role());
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 32 with TestCluster

use of io.aeron.test.cluster.TestCluster 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)

Example 33 with TestCluster

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

the class AppointedLeaderTest method shouldEchoMessagesViaService.

@Test
@InterruptAfter(20)
public void shouldEchoMessagesViaService() {
    final TestCluster cluster = aCluster().withStaticNodes(3).withAppointedLeader(LEADER_ID).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    assertEquals(LEADER_ID, leader.index());
    assertEquals(Cluster.Role.LEADER, leader.role());
    cluster.connectClient();
    final int messageCount = 10;
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 34 with TestCluster

use of io.aeron.test.cluster.TestCluster 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 35 with TestCluster

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

the class MultiNodeTest method shouldCatchUpWithAppointedLeaderWithThreeNodesWithNoSnapshot.

@Test
@InterruptAfter(20)
public void shouldCatchUpWithAppointedLeaderWithThreeNodesWithNoSnapshot() {
    final int appointedLeaderIndex = 1;
    final TestCluster cluster = aCluster().withStaticNodes(3).withAppointedLeader(appointedLeaderIndex).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    assertEquals(appointedLeaderIndex, leader.index());
    assertEquals(Cluster.Role.LEADER, leader.role());
    final int preCatchupMessageCount = 5;
    final int postCatchupMessageCount = 10;
    final int totalMessageCount = preCatchupMessageCount + postCatchupMessageCount;
    cluster.connectClient();
    cluster.sendMessages(preCatchupMessageCount);
    cluster.awaitResponseMessageCount(preCatchupMessageCount);
    cluster.awaitServicesMessageCount(preCatchupMessageCount);
    cluster.stopNode(cluster.node(0));
    cluster.sendMessages(postCatchupMessageCount);
    cluster.awaitResponseMessageCount(totalMessageCount);
    cluster.awaitServicesMessageCount(totalMessageCount);
    cluster.stopAllNodes();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    cluster.awaitServicesMessageCount(totalMessageCount);
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

TestCluster (io.aeron.test.cluster.TestCluster)54 InterruptAfter (io.aeron.test.InterruptAfter)52 Test (org.junit.jupiter.api.Test)50 TestNode (io.aeron.test.cluster.TestNode)48 SlowTest (io.aeron.test.SlowTest)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 AeronCluster (io.aeron.cluster.client.AeronCluster)4 TestBackupNode (io.aeron.test.cluster.TestBackupNode)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Disabled (org.junit.jupiter.api.Disabled)2 EnabledForJreRange (org.junit.jupiter.api.condition.EnabledForJreRange)2