Search in sources :

Example 6 with TestCluster

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

the class ClusterBackupTest method shouldBackupClusterAfterCleanShutdown.

@Test
@InterruptAfter(30)
public void shouldBackupClusterAfterCleanShutdown() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
    cluster.node(0).isTerminationExpected(true);
    cluster.node(1).isTerminationExpected(true);
    cluster.node(2).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.restartAllNodes(false);
    final TestNode newLeader = cluster.awaitLeader();
    final long logPosition = newLeader.service().cluster().logPosition();
    cluster.startClusterBackupNode(true);
    cluster.awaitBackupState(ClusterBackup.State.BACKING_UP);
    cluster.awaitBackupLiveLogPosition(logPosition);
}
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 7 with TestCluster

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

Example 9 with TestCluster

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

the class MultiNodeTest method shouldReplayWithAppointedLeaderWithThreeNodesWithNoSnapshot.

@Test
@InterruptAfter(20)
public void shouldReplayWithAppointedLeaderWithThreeNodesWithNoSnapshot() {
    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 messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
    cluster.stopAllNodes();
    cluster.restartAllNodes(false);
    cluster.awaitLeader();
    cluster.awaitServicesMessageCount(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 10 with TestCluster

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

the class AppointedLeaderTest method shouldConnectAndSendKeepAlive.

@Test
@InterruptAfter(20)
public void shouldConnectAndSendKeepAlive() {
    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();
    assertTrue(cluster.client().sendKeepAlive());
}
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)

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