Search in sources :

Example 46 with TestCluster

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

the class ClusterToolTest method shouldHandleSnapshotOnLeaderOnly.

@Test
@InterruptAfter(30)
void shouldHandleSnapshotOnLeaderOnly() {
    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.snapshot(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("SNAPSHOT applied successfully"));
    final long expectedSnapshotCount = initialSnapshotCount + 1;
    cluster.awaitSnapshotCount(expectedSnapshotCount);
    for (final TestNode follower : cluster.followers()) {
        assertFalse(ClusterTool.snapshot(follower.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
        assertThat(capturingPrintStream.flushAndGetContent(), containsString("Current node is not the leader"));
    }
}
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 47 with TestCluster

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

the class SingleNodeTest method shouldReplayLog.

@Test
@InterruptAfter(20)
public void shouldReplayLog() {
    final TestCluster cluster = aCluster().withStaticNodes(1).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(leader, messageCount);
    cluster.stopNode(leader);
    cluster.startStaticNode(0, false);
    final TestNode newLeader = cluster.awaitLeader();
    cluster.awaitServiceMessageCount(newLeader, messageCount);
}
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 48 with TestCluster

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

the class SingleNodeTest method shouldSendMessagesToCluster.

@ParameterizedTest
@ValueSource(booleans = { false, true })
@InterruptAfter(20)
public void shouldSendMessagesToCluster(final boolean preTouch) {
    System.setProperty(PRE_TOUCH_MAPPED_MEMORY_PROP_NAME, Boolean.toString(preTouch));
    try {
        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());
        cluster.connectClient();
        cluster.sendMessages(10);
        cluster.awaitResponseMessageCount(10);
        cluster.awaitServiceMessageCount(leader, 10);
    } finally {
        System.clearProperty(PRE_TOUCH_MAPPED_MEMORY_PROP_NAME);
    }
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) InterruptAfter(io.aeron.test.InterruptAfter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 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 50 with TestCluster

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

the class MultiNodeTest method shouldElectAppointedLeaderWithThreeNodesWithNoReplayNoSnapshot.

@Test
@InterruptAfter(20)
public void shouldElectAppointedLeaderWithThreeNodesWithNoReplayNoSnapshot() {
    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());
    assertEquals(Cluster.Role.FOLLOWER, cluster.node(0).role());
    assertEquals(Cluster.Role.FOLLOWER, cluster.node(2).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)

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