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());
}
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());
}
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"));
}
}
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"));
}
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());
}
Aggregations