Search in sources :

Example 1 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.

the class ConsensusModuleHarness method makeRecordingLog.

public static long makeRecordingLog(final int numMessages, final int maxMessageLength, final Random random, final ConsensusModule.Context context) {
    try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, new StubClusteredService(), null, true, false)) {
        harness.awaitServiceOnStart();
        final AeronCluster aeronCluster = AeronCluster.connect(new AeronCluster.Context().lock(new NoOpLock()));
        final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
        final Publication publication = aeronCluster.ingressPublication();
        final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(maxMessageLength);
        for (int i = 0; i < numMessages; i++) {
            final long messageCorrelationId = aeronCluster.context().aeron().nextCorrelationId();
            final int length = (null == random) ? maxMessageLength : random.nextInt(maxMessageLength);
            msgBuffer.putInt(0, i);
            while (true) {
                final long result = sessionDecorator.offer(publication, messageCorrelationId, msgBuffer, 0, length);
                if (result > 0) {
                    break;
                }
                checkOfferResult(result);
                TestUtil.checkInterruptedStatus();
                Thread.yield();
            }
        }
        harness.awaitServiceOnMessageCounter(numMessages);
        return publication.position();
    }
}
Also used : NoOpLock(org.agrona.concurrent.NoOpLock) AeronCluster(io.aeron.cluster.client.AeronCluster) SessionDecorator(io.aeron.cluster.client.SessionDecorator) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 2 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class ClusterNodeTest method shouldEchoMessageViaServiceUsingTryClaim.

@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingTryClaim() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchEchoService();
    aeronCluster = connectToCluster(listener);
    final BufferClaim bufferClaim = new BufferClaim();
    long publicationResult;
    do {
        publicationResult = aeronCluster.tryClaim(msg.length(), bufferClaim);
        if (publicationResult > 0) {
            final int offset = bufferClaim.offset() + AeronCluster.SESSION_HEADER_LENGTH;
            bufferClaim.buffer().putBytes(offset, msgBuffer, 0, msg.length());
            bufferClaim.commit();
        } else {
            Tests.yield();
        }
    } while (publicationResult < 0);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) BufferClaim(io.aeron.logbuffer.BufferClaim) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 3 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class ClusterNodeTest method shouldEchoMessageViaServiceUsingDirectOffer.

@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingDirectOffer() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchEchoService();
    aeronCluster = connectToCluster(listener);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 4 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class ClusterBackupTest method shouldBackupClusterNoSnapshotsAndNonEmptyLogWithFailure.

@Test
@InterruptAfter(60)
public void shouldBackupClusterNoSnapshotsAndNonEmptyLogWithFailure() {
    final TestCluster cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leaderOne = cluster.awaitLeader();
    final int messageCount = 10;
    final AeronCluster aeronCluster = cluster.connectClient();
    cluster.sendMessages(messageCount);
    cluster.awaitResponseMessageCount(messageCount);
    cluster.awaitServicesMessageCount(messageCount);
    final long logPosition = leaderOne.service().cluster().logPosition();
    cluster.startClusterBackupNode(true);
    aeronCluster.sendKeepAlive();
    cluster.awaitBackupState(ClusterBackup.State.BACKING_UP);
    aeronCluster.sendKeepAlive();
    cluster.awaitBackupLiveLogPosition(logPosition);
    cluster.stopNode(leaderOne);
    final TestNode leaderTwo = cluster.awaitLeader();
    cluster.awaitNewLeadershipEvent(1);
    cluster.sendMessages(5);
    cluster.awaitResponseMessageCount(messageCount + 5);
    final long nextLogPosition = leaderTwo.service().cluster().logPosition();
    cluster.awaitBackupState(ClusterBackup.State.BACKING_UP);
    cluster.awaitBackupLiveLogPosition(nextLogPosition);
    cluster.stopAllNodes();
    final TestNode node = cluster.startStaticNodeFromBackup();
    cluster.awaitLeader();
    assertEquals(messageCount + 5, node.service().messageCount());
    assertFalse(node.service().wasSnapshotLoaded());
}
Also used : TestCluster(io.aeron.test.cluster.TestCluster) AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 5 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class ClusterNetworkTopologyTest method pollUntilConnected.

private AeronCluster pollUntilConnected(final AeronCluster.AsyncConnect asyncConnect, final Selector selector) {
    AeronCluster aeronCluster;
    while (null == (aeronCluster = asyncConnect.poll())) {
        pollSelector(selector);
        Tests.sleep(1);
    }
    return aeronCluster;
}
Also used : AeronCluster(io.aeron.cluster.client.AeronCluster)

Aggregations

AeronCluster (io.aeron.cluster.client.AeronCluster)38 Test (org.junit.jupiter.api.Test)30 MediaDriver (io.aeron.driver.MediaDriver)18 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)15 EgressListener (io.aeron.cluster.client.EgressListener)14 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)14 ThreadingMode (io.aeron.driver.ThreadingMode)14 DirectBuffer (org.agrona.DirectBuffer)14 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)14 Archive (io.aeron.archive.Archive)12 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)12 ClientSession (io.aeron.cluster.service.ClientSession)12 Header (io.aeron.logbuffer.Header)12 StubClusteredService (io.aeron.test.cluster.StubClusteredService)12 CloseHelper (org.agrona.CloseHelper)12 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)12 InterruptAfter (io.aeron.test.InterruptAfter)10 TestNode (io.aeron.test.cluster.TestNode)10 MutableBoolean (org.agrona.collections.MutableBoolean)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10