Search in sources :

Example 41 with TestCluster

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

the class ClusterBackupTest method shouldBackupClusterNoSnapshotsAndNonEmptyLog.

@Test
@InterruptAfter(30)
public void shouldBackupClusterNoSnapshotsAndNonEmptyLog() {
    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);
    final long logPosition = leader.service().cluster().logPosition();
    cluster.startClusterBackupNode(true);
    cluster.awaitBackupState(ClusterBackup.State.BACKING_UP);
    cluster.awaitBackupLiveLogPosition(logPosition);
    cluster.stopAllNodes();
    final TestNode node = cluster.startStaticNodeFromBackup();
    cluster.awaitLeader();
    assertEquals(messageCount, node.service().messageCount());
    assertFalse(node.service().wasSnapshotLoaded());
}
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 42 with TestCluster

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

the class ClusterBackupTest method shouldBackupClusterWithSnapshotThenSend.

@Test
@InterruptAfter(30)
public void shouldBackupClusterWithSnapshotThenSend() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final int preSnapshotMessageCount = 10;
    final int postSnapshotMessageCount = 7;
    final int totalMessageCount = preSnapshotMessageCount + postSnapshotMessageCount;
    cluster.connectClient();
    cluster.sendMessages(preSnapshotMessageCount);
    cluster.awaitResponseMessageCount(preSnapshotMessageCount);
    cluster.awaitServicesMessageCount(preSnapshotMessageCount);
    cluster.takeSnapshot(leader);
    cluster.awaitSnapshotCount(1);
    cluster.startClusterBackupNode(true);
    cluster.sendMessages(postSnapshotMessageCount);
    cluster.awaitResponseMessageCount(totalMessageCount);
    cluster.awaitServiceMessageCount(leader, totalMessageCount);
    final long logPosition = leader.service().cluster().logPosition();
    cluster.awaitBackupState(ClusterBackup.State.BACKING_UP);
    cluster.awaitBackupLiveLogPosition(logPosition);
    cluster.stopAllNodes();
    final TestNode node = cluster.startStaticNodeFromBackup();
    cluster.awaitLeader();
    cluster.awaitServiceMessageCount(node, totalMessageCount);
    assertEquals(totalMessageCount, node.service().messageCount());
    assertTrue(node.service().wasSnapshotLoaded());
}
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 43 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 44 with TestCluster

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

the class ClusterToolTest method shouldSuspendAndResume.

@Test
@InterruptAfter(30)
void shouldSuspendAndResume() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final CapturingPrintStream capturingPrintStream = new CapturingPrintStream();
    assertTrue(ClusterTool.suspend(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("SUSPEND applied successfully"));
    assertTrue(ClusterTool.resume(leader.consensusModule().context().clusterDir(), capturingPrintStream.resetAndGetPrintStream()));
    assertThat(capturingPrintStream.flushAndGetContent(), containsString("RESUME applied successfully"));
}
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 45 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)

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