io.aeron.driver.MediaDriver Java Examples

The following examples show how to use io.aeron.driver.MediaDriver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
static void enableLossGenerationOnReceive(
    final MediaDriver.Context context,
    final double rate,
    final long seed,
    final boolean loseDataMessages,
    final boolean loseControlMessages)
{
    if (shouldRunCMediaDriver())
    {
        CTestMediaDriver.enableLossGenerationOnReceive(context, rate, seed, loseDataMessages, loseControlMessages);
    }
    else
    {
        JavaTestMediaDriver.enableLossGenerationOnReceive(
            context, rate, seed, loseDataMessages, loseControlMessages);
    }
}
 
Example #2
Source File: JavaTestMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void enableLossGenerationOnReceive(
    final MediaDriver.Context context,
    final double rate,
    final long seed,
    final boolean loseDataMessages,
    final boolean loseControlMessages)
{
    final LossGenerator dataLossGenerator = loseDataMessages ?
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) :
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);

    final LossGenerator controlLossGenerator = loseControlMessages ?
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(rate, seed) :
        DebugChannelEndpointConfiguration.lossGeneratorSupplier(0, 0);

    context.receiveChannelEndpointSupplier((udpChannel, dispatcher, statusIndicator, ctx) ->
        new DebugReceiveChannelEndpoint(
        udpChannel, dispatcher, statusIndicator, ctx, dataLossGenerator, controlLossGenerator));
}
 
Example #3
Source File: AuthenticationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchClusteredMediaDriver(final AuthenticatorSupplier authenticatorSupplier)
{
    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .warnIfDirectoryExists(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true)
            .dirDeleteOnShutdown(false),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .recordingEventsEnabled(false)
            .deleteArchiveOnStart(true),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .authenticatorSupplier(authenticatorSupplier)
            .terminationHook(ClusterTests.TERMINATION_HOOK)
            .deleteDirOnStart(true));
}
 
Example #4
Source File: ClusterNodeTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    clusteredMediaDriver = ClusteredMediaDriver.launch(
        new MediaDriver.Context()
            .threadingMode(ThreadingMode.SHARED)
            .termBufferSparseFile(true)
            .errorHandler(ClusterTests.errorHandler(0))
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .threadingMode(ArchiveThreadingMode.SHARED)
            .recordingEventsEnabled(false)
            .deleteArchiveOnStart(true),
        new ConsensusModule.Context()
            .errorHandler(ClusterTests.errorHandler(0))
            .terminationHook(ClusterTests.TERMINATION_HOOK)
            .logChannel("aeron:ipc")
            .deleteDirOnStart(true));
}
 
Example #5
Source File: EmbeddedPingPong.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception
{
    loadPropertiesFiles(args);

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .threadingMode(ThreadingMode.DEDICATED)
        .conductorIdleStrategy(new BackoffIdleStrategy(1, 1, 1000, 1000))
        .receiverIdleStrategy(NoOpIdleStrategy.INSTANCE)
        .senderIdleStrategy(NoOpIdleStrategy.INSTANCE);

    try (MediaDriver ignored = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect())
    {
        final Thread pongThread = startPong(aeron);
        pongThread.start();

        runPing(aeron);
        RUNNING.set(false);
        pongThread.join();

        System.out.println("Shutdown Driver...");
    }
}
 
Example #6
Source File: LowLatencyMediaDriver.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
    MediaDriver.loadPropertiesFiles(args);

    setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
    setProperty("aeron.mtu.length", "16384");
    setProperty("aeron.socket.so_sndbuf", "2097152");
    setProperty("aeron.socket.so_rcvbuf", "2097152");
    setProperty("aeron.rcv.initial.window.length", "2097152");

    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.DEDICATED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());

    try (MediaDriver ignored = MediaDriver.launch(ctx)) {
        new SigIntBarrier().await();

    }
}
 
Example #7
Source File: DriverNameResolverTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
@Timeout(10)
public void shouldSeeNeighbor()
{
    addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context())
        .aeronDirectoryName(baseDir + "-A")
        .resolverName("A")
        .resolverInterface("0.0.0.0:8050"), testWatcher));

    addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context())
        .aeronDirectoryName(baseDir + "-B")
        .resolverName("B")
        .resolverInterface("0.0.0.0:8051")
        .resolverBootstrapNeighbor("localhost:8050"), testWatcher));
    startClients();

    final int aNeighborsCounterId = neighborsCounterId("A");
    final int bNeighborsCounterId = neighborsCounterId("B");

    awaitCounterValue("A", aNeighborsCounterId, 1);
    awaitCounterValue("B", bNeighborsCounterId, 1);
}
 
Example #8
Source File: LowLatencyMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args)
{
    loadPropertiesFiles(args);

    final MediaDriver.Context ctx = new MediaDriver.Context()
        .termBufferSparseFile(false)
        .useWindowsHighResTimer(true)
        .threadingMode(ThreadingMode.DEDICATED)
        .conductorIdleStrategy(BusySpinIdleStrategy.INSTANCE)
        .receiverIdleStrategy(NoOpIdleStrategy.INSTANCE)
        .senderIdleStrategy(NoOpIdleStrategy.INSTANCE);

    try (MediaDriver ignored = MediaDriver.launch(ctx))
    {
        new ShutdownSignalBarrier().await();

        System.out.println("Shutdown Driver...");
    }
}
 
Example #9
Source File: SingleNodeCluster.java    From aeron with Apache License 2.0 6 votes vote down vote up
void connectClientToCluster()
{
    final String aeronDirectoryName = CommonContext.getAeronDirectoryName() + "-client";

    clientMediaDriver = MediaDriver.launch(
        new MediaDriver.Context()
            .threadingMode(ThreadingMode.SHARED)
            .dirDeleteOnStart(true)
            .dirDeleteOnShutdown(true)
            .errorHandler(Throwable::printStackTrace)
            .aeronDirectoryName(aeronDirectoryName));

    client = AeronCluster.connect(
        new AeronCluster.Context()
            .errorHandler(Throwable::printStackTrace)
            .egressListener(egressMessageListener)
            .aeronDirectoryName(aeronDirectoryName));
}
 
Example #10
Source File: MultiModuleSharedDriverTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
MultiClusterNode(final int nodeId)
{
    this.nodeId = nodeId;

    final MediaDriver.Context driverCtx = new MediaDriver.Context()
        .aeronDirectoryName(CommonContext.getAeronDirectoryName() + "-" + nodeId)
        .threadingMode(ThreadingMode.SHARED)
        .errorHandler(Tests::onError)
        .dirDeleteOnStart(true);

    final Archive.Context archiveCtx = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .archiveDir(new File(SystemUtil.tmpDirName(), "archive-" + nodeId))
        .controlChannel("aeron:udp?endpoint=localhost:801" + nodeId)
        .errorHandler(Tests::onError)
        .recordingEventsEnabled(false)
        .deleteArchiveOnStart(true);

    archivingMediaDriver = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
    consensusModule0 = consensusModule(0, driverCtx.aeronDirectoryName());
    container0 = container(consensusModule0.context());
    consensusModule1 = consensusModule(1, driverCtx.aeronDirectoryName());
    container1 = container(consensusModule1.context());
}
 
Example #11
Source File: ParameterServerNodeTest.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
    mediaDriver = MediaDriver.launchEmbedded(AeronUtil.getMediaDriverContext(parameterLength));
    System.setProperty("play.server.dir", "/tmp");
    aeron = Aeron.connect(getContext());
    parameterServerNode = new ParameterServerNode(mediaDriver, statusPort);
    parameterServerNode.runMain(new String[] {"-m", "true", "-s", "1," + String.valueOf(parameterLength), "-p",
                    String.valueOf(masterStatusPort), "-h", "localhost", "-id", "11", "-md",
                    mediaDriver.aeronDirectoryName(), "-sp", String.valueOf(statusPort), "-sh", "localhost", "-u",
                    String.valueOf(Runtime.getRuntime().availableProcessors())});

    while (!parameterServerNode.subscriberLaunched()) {
        Thread.sleep(10000);
    }

}
 
Example #12
Source File: BuyerApplication.java    From artio with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws InterruptedException
{
    System.setProperty(CONTROL_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9010");
    System.setProperty(CONTROL_RESPONSE_CHANNEL_PROP_NAME, "aeron:udp?endpoint=localhost:9020");

    final MediaDriver.Context context = new MediaDriver.Context()
        .threadingMode(SHARED)
        .dirDeleteOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME);

    final Archive.Context archiveContext = new Archive.Context()
        .threadingMode(ArchiveThreadingMode.SHARED)
        .deleteArchiveOnStart(true)
        .aeronDirectoryName(AERON_DIRECTORY_NAME)
        .recordingEventsChannel(RECORDING_EVENTS_CHANNEL);

    try (ArchivingMediaDriver driver = ArchivingMediaDriver.launch(context, archiveContext))
    {
        SampleUtil.runAgentUntilSignal(
            new BuyerAgent(),
            driver.mediaDriver());
    }
}
 
Example #13
Source File: PongTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void before()
{
    driver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .errorHandler(Tests::onError)
            .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
            .threadingMode(ThreadingMode.SHARED),
        testWatcher);

    pingClient = Aeron.connect();
    pongClient = Aeron.connect();

    pingSubscription = pongClient.addSubscription(PING_URI, PING_STREAM_ID);
    pingPublication = pingClient.addPublication(PING_URI, PING_STREAM_ID);

    pongSubscription = pingClient.addSubscription(PONG_URI, PONG_STREAM_ID);
    pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
}
 
Example #14
Source File: StopStartSecondSubscriberTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launch(final String channelOne, final int streamOne, final String channelTwo, final int streamTwo)
{
    driverOne = MediaDriver.launchEmbedded(
        new MediaDriver.Context()
            .dirDeleteOnStart(true)
            .errorHandler(Tests::onError)
            .termBufferSparseFile(true));

    driverTwo = MediaDriver.launchEmbedded(
        new MediaDriver.Context()
            .dirDeleteOnStart(true)
            .errorHandler(Tests::onError)
            .termBufferSparseFile(true));

    publisherOne = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverOne.aeronDirectoryName()));
    subscriberOne = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverTwo.aeronDirectoryName()));
    publisherTwo = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverOne.aeronDirectoryName()));
    subscriberTwo = Aeron.connect(new Aeron.Context().aeronDirectoryName(driverTwo.aeronDirectoryName()));

    subscriptionOne = subscriberOne.addSubscription(channelOne, streamOne);
    subscriptionTwo = subscriberTwo.addSubscription(channelTwo, streamTwo);
    publicationOne = publisherOne.addPublication(channelOne, streamOne);
    publicationTwo = publisherTwo.addPublication(channelTwo, streamTwo);
}
 
Example #15
Source File: ArchivingMediaDriver.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Launch an {@link Archive} with an embedded {@link MediaDriver} and await a shutdown signal.
 *
 * @param args command line argument which is a list for properties files as URLs or filenames.
 */
public static void main(final String[] args)
{
    loadPropertiesFiles(args);

    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    final MediaDriver.Context ctx = new MediaDriver.Context();

    ctx.terminationHook(barrier::signal);

    try (ArchivingMediaDriver ignore = launch(ctx, new Archive.Context()))
    {
        barrier.await();

        System.out.println("Shutdown Archive...");
    }
}
 
Example #16
Source File: EmbeddedRecordingThroughput.java    From aeron with Apache License 2.0 6 votes vote down vote up
public EmbeddedRecordingThroughput()
{
    final String archiveDirName = Archive.Configuration.archiveDirName();
    final File archiveDir = ARCHIVE_DIR_DEFAULT.equals(archiveDirName) ?
        Samples.createTempDir() : new File(archiveDirName);

    archivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .recordingEventsEnabled(false)
            .archiveDir(archiveDir));

    aeron = Aeron.connect();

    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron));
}
 
Example #17
Source File: SpecifiedPositionPublicationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRejectSpecifiedPositionForConcurrentPublications()
{
    final ErrorHandler mockErrorHandler = mock(ErrorHandler.class);
    final MediaDriver.Context context = new MediaDriver.Context()
        .errorHandler(mockErrorHandler)
        .dirDeleteOnStart(true)
        .publicationTermBufferLength(LogBufferDescriptor.TERM_MIN_LENGTH)
        .threadingMode(ThreadingMode.SHARED);

    try (TestMediaDriver ignore = TestMediaDriver.launch(context, testWatcher);
        Aeron aeron = Aeron.connect())
    {
        final String channel = new ChannelUriStringBuilder()
            .media("ipc")
            .initialPosition(1024, -873648623, 65536)
            .build();

        assertThrows(RegistrationException.class, () -> aeron.addPublication(channel, 1001));
    }
    finally
    {
        context.deleteDirectory();
    }
}
 
Example #18
Source File: TermBufferLengthTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = {
    "aeron:udp?endpoint=localhost:24325|" + CommonContext.TERM_LENGTH_PARAM_NAME + "=" + TEST_TERM_LENGTH,
    "aeron:ipc?" + CommonContext.TERM_LENGTH_PARAM_NAME + "=" + TEST_TERM_LENGTH
})
public void shouldHaveCorrectTermBufferLength(final String channel)
{
    final MediaDriver.Context ctx = new MediaDriver.Context()
        .errorHandler(Tests::onError)
        .dirDeleteOnStart(true)
        .publicationTermBufferLength(TEST_TERM_LENGTH * 2)
        .ipcTermBufferLength(TEST_TERM_LENGTH * 2);

    try (TestMediaDriver ignore = TestMediaDriver.launch(ctx, testWatcher);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(channel, STREAM_ID))
    {
        assertEquals(TEST_TERM_LENGTH, publication.termBufferLength());
    }
    finally
    {
        ctx.deleteDirectory();
    }
}
 
Example #19
Source File: MultipleAddressSystemTest.java    From artio with Apache License 2.0 6 votes vote down vote up
@Before
public void launch()
{
    final int libraryAeronPort = unusedPort();

    final MediaDriver.Context context = mediaDriverContext(TestFixtures.TERM_BUFFER_LENGTH, true);
    mediaDriver = launchMediaDriver(context);

    acceptingEngine = FixEngine.launch(
        acceptingConfig(port, ACCEPTOR_ID, INITIATOR_ID)
            .scheduler(new LowResourceEngineScheduler())
            .deleteLogFileDirOnStart(true));

    final EngineConfiguration initiatingConfig = initiatingConfig(libraryAeronPort);
    initiatingConfig.deleteLogFileDirOnStart(true);
    initiatingConfig.printErrorMessages(false);
    initiatingEngine = FixEngine.launch(initiatingConfig);

    initiatingLibrary = newInitiatingLibrary(libraryAeronPort, initiatingHandler);
    testSystem = new TestSystem(initiatingLibrary);
}
 
Example #20
Source File: ArchiveAuthenticationTest.java    From aeron with Apache License 2.0 6 votes vote down vote up
private void launchArchivingMediaDriver(final AuthenticatorSupplier authenticatorSupplier)
{
    mediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(aeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(false)
            .dirDeleteOnStart(true),
        testWatcher);

    archive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(Common.MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(aeronDirectoryName)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "archive"))
            .fileSyncLevel(0)
            .authenticatorSupplier(authenticatorSupplier)
            .threadingMode(ArchiveThreadingMode.SHARED));
}
 
Example #21
Source File: LowLatencyMediaDriver.java    From rpc-bench with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:UncommentedMain")
public static void main(final String... args) {
  MediaDriver.loadPropertiesFiles(args);

  setProperty(DISABLE_BOUNDS_CHECKS_PROP_NAME, "true");
  setProperty("aeron.mtu.length", "16384");
  setProperty("aeron.socket.so_sndbuf", "2097152");
  setProperty("aeron.socket.so_rcvbuf", "2097152");
  setProperty("aeron.rcv.initial.window.length", "2097152");

  final MediaDriver.Context ctx = new MediaDriver.Context()
      .threadingMode(ThreadingMode.DEDICATED)
      .dirsDeleteOnStart(true)
      .termBufferSparseFile(false)
      .conductorIdleStrategy(new BusySpinIdleStrategy())
      .receiverIdleStrategy(new BusySpinIdleStrategy())
      .senderIdleStrategy(new BusySpinIdleStrategy());

  try (MediaDriver ignored = MediaDriver.launch(ctx)) {
    new SigIntBarrier().await();

  }
}
 
Example #22
Source File: AeronNDArrayResponseTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    final MediaDriver.Context ctx =
                    new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
                                    .termBufferSparseFile(false).conductorIdleStrategy(new BusySpinIdleStrategy())
                                    .receiverIdleStrategy(new BusySpinIdleStrategy())
                                    .senderIdleStrategy(new BusySpinIdleStrategy());
    mediaDriver = MediaDriver.launchEmbedded(ctx);
    System.out.println("Using media driver directory " + mediaDriver.aeronDirectoryName());
    System.out.println("Launched media driver");
}
 
Example #23
Source File: CounterTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    labelBuffer.putStringWithoutLengthAscii(0, COUNTER_LABEL);

    driver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .errorHandler(Tests::onError)
            .threadingMode(ThreadingMode.SHARED),
        testWatcher);

    clientA = Aeron.connect();
    clientB = Aeron.connect();
}
 
Example #24
Source File: WildcardPortsSystemTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void launch()
{
    buffer.putInt(0, 1);

    final MediaDriver.Context context = new MediaDriver.Context()
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    driver = TestMediaDriver.launch(context, testWatcher);
    client = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()));
}
 
Example #25
Source File: ArchiveLoggingAgentTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
private void testArchiveLogging(final String enabledEvents, final EnumSet<ArchiveEventCode> expectedEvents)
    throws InterruptedException
{
    before(enabledEvents, expectedEvents);

    final String aeronDirectoryName = testDir.toPath().resolve("media").toString();

    final MediaDriver.Context mediaDriverCtx = new MediaDriver.Context()
        .errorHandler(Tests::onError)
        .aeronDirectoryName(aeronDirectoryName)
        .dirDeleteOnStart(true)
        .threadingMode(ThreadingMode.SHARED);

    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context()
        .aeronDirectoryName(aeronDirectoryName)
        .controlRequestChannel("aeron:udp?term-length=64k|endpoint=localhost:8010")
        .controlRequestStreamId(100)
        .controlResponseChannel("aeron:udp?term-length=64k|endpoint=localhost:8020")
        .controlResponseStreamId(101)
        .recordingEventsChannel("aeron:udp?control-mode=dynamic|control=localhost:8030");

    final Archive.Context archiveCtx = new Archive.Context()
        .errorHandler(Tests::onError)
        .archiveDir(new File(testDir, "archive"))
        .deleteArchiveOnStart(true)
        .controlChannel(aeronArchiveContext.controlRequestChannel())
        .controlStreamId(aeronArchiveContext.controlRequestStreamId())
        .localControlStreamId(aeronArchiveContext.controlRequestStreamId())
        .recordingEventsChannel(aeronArchiveContext.recordingEventsChannel())
        .threadingMode(ArchiveThreadingMode.SHARED);

    try (ArchivingMediaDriver ignore1 = ArchivingMediaDriver.launch(mediaDriverCtx, archiveCtx))
    {
        try (AeronArchive ignore2 = AeronArchive.connect(aeronArchiveContext))
        {
            latch.await();
        }
    }
}
 
Example #26
Source File: LifecycleTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotifyOfClientTimestampCounter()
{
    final MediaDriver.Context driverCtx = new MediaDriver.Context()
        .dirDeleteOnStart(true)
        .errorHandler(Tests::onError);

    try (TestMediaDriver ignore = TestMediaDriver.launch(driverCtx, testWatcher))
    {
        final Aeron.Context clientCtxOne = new Aeron.Context()
            .aeronDirectoryName(driverCtx.aeronDirectoryName());

        final Aeron.Context clientCtxTwo = new Aeron.Context()
            .aeronDirectoryName(driverCtx.aeronDirectoryName());

        try (Aeron aeron = Aeron.connect(clientCtxOne))
        {
            final AvailableCounterHandler availableHandler = mock(AvailableCounterHandler.class);
            aeron.addAvailableCounterHandler(availableHandler);
            final UnavailableCounterHandler unavailableHandler = mock(UnavailableCounterHandler.class);
            aeron.addUnavailableCounterHandler(unavailableHandler);

            try (Aeron aeronTwo = Aeron.connect(clientCtxTwo))
            {
                aeronTwo.addSubscription("aeron:ipc", 1001);
                verify(availableHandler, timeout(5000))
                    .onAvailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
            }

            verify(unavailableHandler, timeout(5000))
                .onUnavailableCounter(any(), eq(clientCtxTwo.clientId()), anyInt());
        }
    }
    finally
    {
        driverCtx.deleteDirectory();
    }
}
 
Example #27
Source File: DriverNameResolverTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
@Timeout(20)
public void shouldSeeNeighborsViaGossip()
{
    addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context())
        .aeronDirectoryName(baseDir + "-B")
        .resolverName("B")
        .resolverInterface("0.0.0.0:8051")
        .resolverBootstrapNeighbor("localhost:8050"), testWatcher));

    addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context())
        .aeronDirectoryName(baseDir + "-C")
        .resolverName("C")
        .resolverInterface("0.0.0.0:8052")
        .resolverBootstrapNeighbor("localhost:8051"), testWatcher));

    addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context())
        .aeronDirectoryName(baseDir + "-A")
        .resolverName("A")
        .resolverInterface("0.0.0.0:8050"), testWatcher));

    startClients();

    final int aNeighborsCounterId = neighborsCounterId("A");
    final int bNeighborsCounterId = neighborsCounterId("B");
    final int cNeighborsCounterId = neighborsCounterId("C");

    awaitCounterValue("A", aNeighborsCounterId, 2);
    awaitCounterValue("B", bNeighborsCounterId, 2);
    awaitCounterValue("C", cNeighborsCounterId, 2);
}
 
Example #28
Source File: ReceiveDestinationTransport.java    From aeron with Apache License 2.0 5 votes vote down vote up
public ReceiveDestinationTransport(
    final UdpChannel udpChannel,
    final MediaDriver.Context context,
    final AtomicCounter localSocketAddressIndicator)
{
    super(udpChannel, udpChannel.remoteData(), udpChannel.remoteData(), null, context);

    this.timeOfLastActivityNs = context.cachedNanoClock().nanoTime();
    this.currentControlAddress = udpChannel.hasExplicitControl() ? udpChannel.localControl() : null;
    this.localSocketAddressIndicator = localSocketAddressIndicator;
}
 
Example #29
Source File: ChannelEndpointStatusTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before()
{
    final String baseDirA = ROOT_DIR + "A";
    final String baseDirB = ROOT_DIR + "B";

    buffer.putInt(0, 1);

    final MediaDriver.Context driverAContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirA)
        .errorHandler(driverErrorHandler)
        .threadingMode(THREADING_MODE);

    final MediaDriver.Context driverBContext = new MediaDriver.Context()
        .publicationTermBufferLength(TERM_BUFFER_LENGTH)
        .aeronDirectoryName(baseDirB)
        .errorHandler(driverErrorHandler)
        .threadingMode(THREADING_MODE);

    driverA = TestMediaDriver.launch(driverAContext, testWatcher);
    driverB = TestMediaDriver.launch(driverBContext, testWatcher);

    clientA = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverAContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientA));

    clientB = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverBContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientB));

    clientC = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(driverBContext.aeronDirectoryName())
            .errorHandler(errorHandlerClientC));
}
 
Example #30
Source File: DebugReceiveChannelEndpointSupplier.java    From aeron with Apache License 2.0 5 votes vote down vote up
public ReceiveChannelEndpoint newInstance(
    final UdpChannel udpChannel,
    final DataPacketDispatcher dispatcher,
    final AtomicCounter statusIndicator,
    final MediaDriver.Context context)
{
    return new DebugReceiveChannelEndpoint(udpChannel, dispatcher, statusIndicator, context);
}