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