Search in sources :

Example 1 with RedirectingNameResolver

use of io.aeron.test.driver.RedirectingNameResolver 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)

Example 2 with RedirectingNameResolver

use of io.aeron.test.driver.RedirectingNameResolver in project Aeron by real-logic.

the class TestCluster method nodeContext.

public static NodeContext nodeContext(final int index, final boolean cleanStart) {
    final String baseDirName = CommonContext.getAeronDirectoryName() + "-" + index;
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + index + "-driver";
    final NodeContext nodeCtx = new NodeContext();
    nodeCtx.mediaDriverCtx.aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).dirDeleteOnStart(true).dirDeleteOnShutdown(false).nameResolver(new RedirectingNameResolver(DEFAULT_NODE_MAPPINGS));
    nodeCtx.archiveCtx.catalogCapacity(CATALOG_CAPACITY).segmentFileLength(256 * 1024).archiveDir(new File(baseDirName, "archive")).controlChannel(archiveControlRequestChannel(index)).localControlChannel(ARCHIVE_LOCAL_CONTROL_CHANNEL).recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED).deleteArchiveOnStart(cleanStart);
    nodeCtx.aeronArchiveCtx.controlRequestChannel(nodeCtx.archiveCtx.localControlChannel()).controlResponseChannel(nodeCtx.archiveCtx.localControlChannel()).recordingEventsChannel(nodeCtx.archiveCtx.recordingEventsChannel()).aeronDirectoryName(aeronDirName);
    nodeCtx.consensusModuleCtx.clusterMemberId(index).clusterMembers(clusterMembers(0, 3)).startupCanvassTimeoutNs(STARTUP_CANVASS_TIMEOUT_NS).serviceCount(2).clusterDir(new File(baseDirName, "consensus-module")).ingressChannel(INGRESS_CHANNEL).logChannel(LOG_CHANNEL).archiveContext(nodeCtx.aeronArchiveCtx.clone()).snapshotChannel(SNAPSHOT_CHANNEL_DEFAULT + "|term-length=64k").sessionTimeoutNs(TimeUnit.SECONDS.toNanos(10)).deleteDirOnStart(cleanStart);
    return nodeCtx;
}
Also used : RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) File(java.io.File)

Example 3 with RedirectingNameResolver

use of io.aeron.test.driver.RedirectingNameResolver in project Aeron by real-logic.

the class TestCluster method connectClient.

public AeronCluster connectClient(final AeronCluster.Context clientCtx) {
    final String aeronDirName = CommonContext.getAeronDirectoryName();
    if (null == clientMediaDriver) {
        dataCollector.add(Paths.get(aeronDirName));
        final MediaDriver.Context ctx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(false).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(nodeNameMappings()));
        clientMediaDriver = MediaDriver.launch(ctx);
    }
    clientCtx.aeronDirectoryName(aeronDirName).isIngressExclusive(true).egressListener(egressListener).controlledEgressListener(controlledEgressListener).ingressEndpoints(staticClusterMemberEndpoints);
    try {
        CloseHelper.close(client);
        client = AeronCluster.connect(clientCtx.clone());
    } catch (final TimeoutException ex) {
        System.out.println("Warning: " + ex);
        CloseHelper.close(client);
        client = AeronCluster.connect(clientCtx);
    }
    return client;
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) TimeoutException(io.aeron.exceptions.TimeoutException)

Example 4 with RedirectingNameResolver

use of io.aeron.test.driver.RedirectingNameResolver in project Aeron by real-logic.

the class TestCluster method startClusterBackupNode.

public TestBackupNode startClusterBackupNode(final boolean cleanStart) {
    final int index = staticMemberCount + dynamicMemberCount;
    final String baseDirName = CommonContext.getAeronDirectoryName() + "-" + index;
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + index + "-driver";
    final TestBackupNode.Context context = new TestBackupNode.Context();
    context.aeronArchiveContext.controlRequestChannel(archiveControlRequestChannel(index)).controlResponseChannel(archiveControlResponseChannel(index)).aeronDirectoryName(aeronDirName);
    context.mediaDriverContext.aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).errorHandler(errorHandler(index)).dirDeleteOnStart(true).dirDeleteOnShutdown(false).nameResolver(new RedirectingNameResolver(nodeNameMappings()));
    context.archiveContext.catalogCapacity(CATALOG_CAPACITY).segmentFileLength(SEGMENT_FILE_LENGTH).archiveDir(new File(baseDirName, "archive")).controlChannel(context.aeronArchiveContext.controlRequestChannel()).localControlChannel(ARCHIVE_LOCAL_CONTROL_CHANNEL).recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED).deleteArchiveOnStart(cleanStart);
    final ChannelUri consensusChannelUri = ChannelUri.parse(context.clusterBackupContext.consensusChannel());
    final String backupStatusEndpoint = clusterBackupStatusEndpoint(0, index);
    consensusChannelUri.put(CommonContext.ENDPOINT_PARAM_NAME, backupStatusEndpoint);
    final AeronArchive.Context clusterArchiveContext = new AeronArchive.Context();
    final ChannelUri clusterArchiveResponseChannel = ChannelUri.parse(clusterArchiveContext.controlResponseChannel());
    clusterArchiveResponseChannel.put(CommonContext.ENDPOINT_PARAM_NAME, hostname(index) + ":0");
    clusterArchiveContext.controlResponseChannel(clusterArchiveResponseChannel.toString());
    context.clusterBackupContext.errorHandler(errorHandler(index)).clusterConsensusEndpoints(clusterConsensusEndpoints).consensusChannel(consensusChannelUri.toString()).clusterBackupCoolDownIntervalNs(TimeUnit.SECONDS.toNanos(1)).catchupEndpoint(hostname(index) + ":0").clusterArchiveContext(clusterArchiveContext).clusterDir(new File(baseDirName, "cluster-backup")).deleteDirOnStart(cleanStart);
    backupNode = new TestBackupNode(context, dataCollector);
    return backupNode;
}
Also used : RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) File(java.io.File) AeronArchive(io.aeron.archive.client.AeronArchive)

Example 5 with RedirectingNameResolver

use of io.aeron.test.driver.RedirectingNameResolver in project Aeron by real-logic.

the class MultiModuleSharedDriverTest method shouldSupportTwoSingleNodeClusters.

@Test
@InterruptAfter(20)
@SuppressWarnings({ "try", "methodlength" })
public void shouldSupportTwoSingleNodeClusters() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)).dirDeleteOnShutdown(false).dirDeleteOnStart(true);
    final Archive.Context archiveCtx = new Archive.Context().threadingMode(ArchiveThreadingMode.SHARED).archiveDir(new File(SystemUtil.tmpDirName(), "archive")).recordingEventsEnabled(false).deleteArchiveOnStart(true);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) {
        final ConsensusModule.Context moduleCtx0 = new ConsensusModule.Context().clusterId(0).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-0")).logChannel("aeron:ipc?term-length=64k").logStreamId(100).serviceStreamId(104).consensusModuleStreamId(105).ingressChannel("aeron:udp?endpoint=localhost:9020").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx0 = new ClusteredServiceContainer.Context().clusterId(moduleCtx0.clusterId()).clusteredService(new EchoService()).clusterDir(moduleCtx0.clusterDir()).serviceStreamId(moduleCtx0.serviceStreamId()).consensusModuleStreamId(moduleCtx0.consensusModuleStreamId());
        final ConsensusModule.Context moduleCtx1 = new ConsensusModule.Context().clusterId(1).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-1")).logChannel("aeron:ipc?term-length=64k").logStreamId(200).serviceStreamId(204).consensusModuleStreamId(205).ingressChannel("aeron:udp?endpoint=localhost:9021").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx1 = new ClusteredServiceContainer.Context().clusteredService(new EchoService()).clusterDir(moduleCtx1.clusterDir()).serviceStreamId(moduleCtx1.serviceStreamId()).consensusModuleStreamId(moduleCtx1.consensusModuleStreamId()).clusterId(moduleCtx1.clusterId());
        ConsensusModule consensusModule0 = null;
        ClusteredServiceContainer container0 = null;
        ConsensusModule consensusModule1 = null;
        ClusteredServiceContainer container1 = null;
        AeronCluster client0 = null;
        AeronCluster client1 = null;
        try {
            consensusModule0 = ConsensusModule.launch(moduleCtx0);
            consensusModule1 = ConsensusModule.launch(moduleCtx1);
            container0 = ClusteredServiceContainer.launch(containerCtx0);
            container1 = ClusteredServiceContainer.launch(containerCtx1);
            final MutableReference<String> egress = new MutableReference<>();
            final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
            client0 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx0.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            client1 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx1.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            echoMessage(client0, "Message 0", egress);
            echoMessage(client1, "Message 1", egress);
        } finally {
            systemTestWatcher.dataCollector().add(moduleCtx0.clusterDir());
            systemTestWatcher.dataCollector().add(moduleCtx1.clusterDir());
            CloseHelper.closeAll(client0, client1, consensusModule0, consensusModule1, container0, container1);
        }
    } finally {
        systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
        systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
    }
}
Also used : CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) io.aeron.test(io.aeron.test) SystemUtil(org.agrona.SystemUtil) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) MutableReference(org.agrona.collections.MutableReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) CommonContext(io.aeron.CommonContext) File(java.io.File) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) TestCluster(io.aeron.test.cluster.TestCluster) DirectBuffer(org.agrona.DirectBuffer) Archive(io.aeron.archive.Archive) AeronCluster(io.aeron.cluster.client.AeronCluster) MutableReference(org.agrona.collections.MutableReference) EgressListener(io.aeron.cluster.client.EgressListener) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) Test(org.junit.jupiter.api.Test)

Aggregations

RedirectingNameResolver (io.aeron.test.driver.RedirectingNameResolver)6 MediaDriver (io.aeron.driver.MediaDriver)4 File (java.io.File)3 CommonContext (io.aeron.CommonContext)2 AeronCluster (io.aeron.cluster.client.AeronCluster)2 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)2 DirectBuffer (org.agrona.DirectBuffer)2 Test (org.junit.jupiter.api.Test)2 Archive (io.aeron.archive.Archive)1 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)1 ArchivingMediaDriver (io.aeron.archive.ArchivingMediaDriver)1 AeronArchive (io.aeron.archive.client.AeronArchive)1 EgressListener (io.aeron.cluster.client.EgressListener)1 ClientSession (io.aeron.cluster.service.ClientSession)1 ThreadingMode (io.aeron.driver.ThreadingMode)1 TimeoutException (io.aeron.exceptions.TimeoutException)1 Header (io.aeron.logbuffer.Header)1 io.aeron.test (io.aeron.test)1 StubClusteredService (io.aeron.test.cluster.StubClusteredService)1 TestCluster (io.aeron.test.cluster.TestCluster)1