Search in sources :

Example 11 with AeronCluster

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

the class ClusterTests method startPublisherThread.

public static Thread startPublisherThread(final TestCluster testCluster, final MutableInteger messageCounter, final long backoffIntervalNs) {
    final Thread thread = new Thread(() -> {
        final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
        final AeronCluster client = testCluster.client();
        final ExpandableArrayBuffer msgBuffer = testCluster.msgBuffer();
        msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);
        while (!Thread.interrupted()) {
            final long result = client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length());
            if (result > 0) {
                messageCounter.increment();
            } else {
                if (Publication.CLOSED == result) {
                    break;
                }
                LockSupport.parkNanos(backoffIntervalNs);
            }
            idleStrategy.idle(client.pollEgress());
        }
    });
    thread.setDaemon(true);
    thread.setName("message-thread");
    thread.start();
    return thread;
}
Also used : YieldingIdleStrategy(org.agrona.concurrent.YieldingIdleStrategy) IdleStrategy(org.agrona.concurrent.IdleStrategy) AeronCluster(io.aeron.cluster.client.AeronCluster) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 12 with AeronCluster

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

the class BasicAuctionClusterClient method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
public static void main(final String[] args) {
    // <1>
    final int customerId = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.customerId"));
    // <2>
    final int numOfBids = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.numOfBids"));
    // <3>
    final int bidIntervalMs = Integer.parseInt(System.getProperty("aeron.cluster.tutorial.bidIntervalMs"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(",");
    final String ingressEndpoints = ingressEndpoints(Arrays.asList(hostnames));
    final BasicAuctionClusterClient client = new BasicAuctionClusterClient(customerId, numOfBids, bidIntervalMs);
    // tag::connect[]
    try (MediaDriver mediaDriver = MediaDriver.launchEmbedded(// <1>
    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(true));
        AeronCluster aeronCluster = AeronCluster.connect(new AeronCluster.Context().egressListener(// <2>
        client).egressChannel(// <3>
        "aeron:udp?endpoint=localhost:0").aeronDirectoryName(mediaDriver.aeronDirectoryName()).ingressChannel(// <4>
        "aeron:udp").ingressEndpoints(// <5>
        ingressEndpoints))) {
        // end::connect[]
        client.bidInAuction(aeronCluster);
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) AeronCluster(io.aeron.cluster.client.AeronCluster)

Example 13 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 14 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)

Example 15 with AeronCluster

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

the class MultiClusteredServicesTest method shouldSupportMultipleServicesPerNode.

@Test
@InterruptAfter(20)
public void shouldSupportMultipleServicesPerNode() {
    final List<TestCluster.NodeContext> nodeContexts = new ArrayList<>();
    final List<TestCluster.ServiceContext> serviceContexts = new ArrayList<>();
    final List<ClusteredMediaDriver> clusteredMediaDrivers = new ArrayList<>();
    final List<ClusteredServiceContainer> clusteredServiceContainers = new ArrayList<>();
    nodeContexts.add(TestCluster.nodeContext(0, true));
    nodeContexts.add(TestCluster.nodeContext(1, true));
    nodeContexts.add(TestCluster.nodeContext(2, true));
    serviceContexts.add(TestCluster.serviceContext(0, 0, nodeContexts.get(0), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(0, 1, nodeContexts.get(0), ServiceB::new));
    serviceContexts.add(TestCluster.serviceContext(1, 0, nodeContexts.get(1), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(1, 1, nodeContexts.get(1), ServiceB::new));
    serviceContexts.add(TestCluster.serviceContext(2, 0, nodeContexts.get(2), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(2, 1, nodeContexts.get(2), ServiceB::new));
    nodeContexts.forEach((context) -> {
        try {
            clusteredMediaDrivers.add(ClusteredMediaDriver.launch(context.mediaDriverCtx, context.archiveCtx, context.consensusModuleCtx));
        } finally {
            systemTestWatcher.dataCollector().add(context.mediaDriverCtx.aeronDirectory());
            systemTestWatcher.dataCollector().add(context.archiveCtx.archiveDir());
            systemTestWatcher.dataCollector().add(context.consensusModuleCtx.clusterDir());
        }
    });
    serviceContexts.forEach((context) -> {
        context.serviceContainerCtx.aeronDirectoryName(context.aeronCtx.aeronDirectoryName());
        try {
            clusteredServiceContainers.add(ClusteredServiceContainer.launch(context.serviceContainerCtx));
        } finally {
            systemTestWatcher.dataCollector().add(context.serviceContainerCtx.clusterDir());
        }
    });
    final String aeronDirName = CommonContext.getAeronDirectoryName();
    final MediaDriver clientMediaDriver = MediaDriver.launch(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)));
    final AeronCluster client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName).ingressChannel(CommonContext.UDP_CHANNEL).ingressEndpoints(TestCluster.ingressEndpoints(0, 3)));
    try {
        final DirectBuffer buffer = new UnsafeBuffer(new byte[100]);
        while (client.offer(buffer, 0, 100) < 0) {
            Tests.yield();
        }
        Tests.awaitValue(serviceAMessageCount, 3);
        Tests.awaitValue(serviceBMessageCount, 3);
    } finally {
        CloseHelper.closeAll(client, clientMediaDriver);
        clusteredMediaDrivers.forEach((clusteredMediaDriver) -> clusteredMediaDriver.consensusModule().close());
        CloseHelper.closeAll(clusteredServiceContainers);
        CloseHelper.closeAll(clusteredMediaDrivers);
        clientMediaDriver.context().deleteDirectory();
    }
}
Also used : CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) ArrayList(java.util.ArrayList) DirectBuffer(org.agrona.DirectBuffer) MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) Test(org.junit.jupiter.api.Test)

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