Search in sources :

Example 86 with TestNode

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

the class ClusterTest method shouldReplayMultipleSnapshotsWithEmptyFollowerLog.

@Test
@InterruptAfter(30)
public void shouldReplayMultipleSnapshotsWithEmptyFollowerLog() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    int messageCount = 2;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
    cluster.takeSnapshot(leader);
    final int memberCount = 3;
    for (int memberId = 0; memberId < memberCount; memberId++) {
        final TestNode node = cluster.node(memberId);
        cluster.awaitSnapshotCount(node, 1);
        assertTrue(node.service().wasSnapshotTaken());
        node.service().resetSnapshotTaken();
    }
    cluster.sendMessages(1);
    messageCount++;
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
    cluster.terminationsExpected(true);
    cluster.awaitNeutralControlToggle(leader);
    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.startStaticNode(0, false);
    cluster.startStaticNode(1, false);
    cluster.startStaticNode(2, true);
    final TestNode newLeader = cluster.awaitLeader();
    assertNotEquals(2, newLeader.index());
    assertTrue(cluster.node(0).service().wasSnapshotLoaded());
    assertTrue(cluster.node(1).service().wasSnapshotLoaded());
    assertFalse(cluster.node(2).service().wasSnapshotLoaded());
    assertEquals(messageCount, cluster.node(0).service().messageCount());
    assertEquals(messageCount, cluster.node(1).service().messageCount());
    // Needs a little time to replay the transactions...
    Tests.await(() -> cluster.node(2).service().messageCount() >= 3);
    assertEquals(messageCount, cluster.node(2).service().messageCount());
    final int messageCountAfterStart = 4;
    cluster.reconnectClient();
    cluster.sendMessages(messageCountAfterStart);
    messageCount += messageCountAfterStart;
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 87 with TestNode

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

the class ClusterTest method shouldRecoverFollowerWhenRecordingStops.

@Test
@InterruptAfter(30)
public void shouldRecoverFollowerWhenRecordingStops() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final TestNode follower = cluster.followers().get(0);
    final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(follower.archive().context().localControlChannel()).controlResponseChannel(follower.archive().context().localControlChannel()).controlRequestStreamId(follower.archive().context().localControlStreamId()).aeronDirectoryName(follower.mediaDriver().aeronDirectoryName());
    try (AeronArchive archive = AeronArchive.connect(archiveCtx)) {
        final int firstRecordingIdIsTheClusterLog = 0;
        assertTrue(archive.tryStopRecordingByIdentity(firstRecordingIdIsTheClusterLog));
    }
    final int messageCount = 10;
    cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServiceMessageCount(follower, messageCount);
}
Also used : TestNode(io.aeron.test.cluster.TestNode) AeronArchive(io.aeron.archive.client.AeronArchive) Test(org.junit.jupiter.api.Test)

Example 88 with TestNode

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

the class ClusterTest method shouldStopLeaderAndRestartAsFollower.

@Test
@InterruptAfter(40)
public void shouldStopLeaderAndRestartAsFollower() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode originalLeader = cluster.awaitLeader();
    cluster.stopNode(originalLeader);
    cluster.awaitLeader(originalLeader.index());
    final TestNode follower = cluster.startStaticNode(originalLeader.index(), false);
    awaitElectionClosed(follower);
    assertEquals(FOLLOWER, follower.role());
}
Also used : TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 89 with TestNode

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

Example 90 with TestNode

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

the class AppointedLeaderTest method shouldEchoMessagesViaService.

@Test
@InterruptAfter(20)
public void shouldEchoMessagesViaService() {
    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();
    final int messageCount = 10;
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
}
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

TestNode (io.aeron.test.cluster.TestNode)166 Test (org.junit.jupiter.api.Test)162 InterruptAfter (io.aeron.test.InterruptAfter)72 SlowTest (io.aeron.test.SlowTest)56 TestCluster (io.aeron.test.cluster.TestCluster)50 AeronCluster (io.aeron.cluster.client.AeronCluster)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 MutableBoolean (org.agrona.collections.MutableBoolean)8 AeronArchive (io.aeron.archive.client.AeronArchive)6 MutableInteger (org.agrona.collections.MutableInteger)4 Aeron (io.aeron.Aeron)2 Publication (io.aeron.Publication)2 ControlledEgressListener (io.aeron.cluster.client.ControlledEgressListener)2 EgressListener (io.aeron.cluster.client.EgressListener)2 io.aeron.cluster.codecs (io.aeron.cluster.codecs)2 FOLLOWER (io.aeron.cluster.service.Cluster.Role.FOLLOWER)2 LEADER (io.aeron.cluster.service.Cluster.Role.LEADER)2 EventLogExtension (io.aeron.log.EventLogExtension)2 ControlledFragmentHandler (io.aeron.logbuffer.ControlledFragmentHandler)2 FrameDescriptor.computeMaxMessageLength (io.aeron.logbuffer.FrameDescriptor.computeMaxMessageLength)2