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();
}
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations