Search in sources :

Example 46 with TestNode

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

use of io.aeron.test.cluster.TestNode 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);
    }
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) TestNode(io.aeron.test.cluster.TestNode) InterruptAfter(io.aeron.test.InterruptAfter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with TestNode

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

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

the class ClusterBackupTest method shouldBackupClusterWithSnapshotAndNonEmptyLog.

@Test
@InterruptAfter(30)
public void shouldBackupClusterWithSnapshotAndNonEmptyLog() {
    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.sendMessages(postSnapshotMessageCount);
    cluster.awaitResponseMessageCount(totalMessageCount);
    cluster.awaitServiceMessageCount(leader, totalMessageCount);
    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();
    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)

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