org.agrona.concurrent.YieldingIdleStrategy Java Examples

The following examples show how to use org.agrona.concurrent.YieldingIdleStrategy. 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: SequenceNumberIndexTest.java    From artio with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
{
    mediaDriver = launchMediaDriver();
    aeronArchive = AeronArchive.connect();
    final Aeron aeron = aeronArchive.context().aeron();

    aeronArchive.startRecording(IPC_CHANNEL, STREAM_ID, SourceLocation.LOCAL);

    publication = aeron.addPublication(IPC_CHANNEL, STREAM_ID);
    subscription = aeron.addSubscription(IPC_CHANNEL, STREAM_ID);

    buffer = new UnsafeBuffer(new byte[512]);

    deleteFiles();

    recordingIdLookup = new RecordingIdLookup(new YieldingIdleStrategy(), aeron.countersReader());
    writer = newWriter(inMemoryBuffer);
    reader = new SequenceNumberIndexReader(inMemoryBuffer, errorHandler, recordingIdLookup, null);
}
 
Example #2
Source File: StableLibrary.java    From artio with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args)
{
    final LibraryConfiguration libraryConfiguration = new LibraryConfiguration()
        .libraryAeronChannels(singletonList(SoleEngine.AERON_CHANNEL))
        .libraryIdleStrategy(new YieldingIdleStrategy());

    libraryConfiguration.replyTimeoutInMs(1000);

    try (FixLibrary library = SampleUtil.blockingConnect(libraryConfiguration))
    {
        System.out.println("Connected");

        while (library.isConnected())
        {
            library.poll(1);

            Thread.yield();
        }
    }
}
 
Example #3
Source File: BenchmarkConfiguration.java    From artio with Apache License 2.0 6 votes vote down vote up
static IdleStrategy idleStrategy()
{
    final String strategyName = System.getProperty("fix.benchmark.engine_idle", "");
    switch (strategyName)
    {
        case "noop":
            return new NoOpIdleStrategy();

        case "yield":
            return new YieldingIdleStrategy();

        default:
        case "backoff":
            return backoffIdleStrategy();
    }
}
 
Example #4
Source File: ReplayIndexTest.java    From artio with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp()
{
    mediaDriver = TestFixtures.launchMediaDriver();
    aeronArchive = AeronArchive.connect();

    recordingIdLookup = new RecordingIdLookup(new YieldingIdleStrategy(), aeron().countersReader());

    aeronArchive.startRecording(CHANNEL, STREAM_ID, SourceLocation.LOCAL);

    final Aeron aeron = aeron();
    publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID);
    subscription = aeron.addSubscription(CHANNEL, STREAM_ID);

    IoUtil.deleteIfExists(logFile(SESSION_ID));
    IoUtil.deleteIfExists(logFile(SESSION_ID_2));

    newReplayIndex();
    query = new ReplayQuery(
        DEFAULT_LOG_FILE_DIR,
        DEFAULT_LOGGER_CACHE_NUM_SETS,
        DEFAULT_LOGGER_CACHE_SET_SIZE,
        existingBufferFactory,
        DEFAULT_OUTBOUND_LIBRARY_STREAM,
        new NoOpIdleStrategy(),
        aeronArchive,
        errorHandler,
        DEFAULT_ARCHIVE_REPLAY_STREAM);
}
 
Example #5
Source File: ReplayIndexTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private GatewayPublication newGatewayPublication(final ExclusivePublication otherPublication)
{
    return new GatewayPublication(
        otherPublication,
        mock(AtomicCounter.class),
        new YieldingIdleStrategy(),
        Clock.systemNanoTime(),
        DEFAULT_INBOUND_MAX_CLAIM_ATTEMPTS);
}
 
Example #6
Source File: TestFixtures.java    From artio with Apache License 2.0 5 votes vote down vote up
public static MediaDriver.Context mediaDriverContext(final int termBufferLength, final boolean dirsDeleteOnStart)
{
    return new MediaDriver.Context()
        .useWindowsHighResTimer(true)
        .threadingMode(SHARED)
        .sharedIdleStrategy(new YieldingIdleStrategy())
        .dirDeleteOnStart(dirsDeleteOnStart)
        .warnIfDirectoryExists(false)
        .publicationTermBufferLength(termBufferLength)
        .ipcTermBufferLength(termBufferLength);
}
 
Example #7
Source File: ConfigurationTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
@Test
void explicitOptions(final @TempDir Path tempDir)
{
    final Path outputDirectory = tempDir.resolve("my-output-dir");
    final Configuration configuration = new Builder()
        .warmUpIterations(3)
        .iterations(11)
        .numberOfMessages(666)
        .batchSize(4)
        .messageLength(119)
        .messageTransceiverClass(InMemoryMessageTransceiver.class)
        .sendIdleStrategy(NoOpIdleStrategy.INSTANCE)
        .receiveIdleStrategy(YieldingIdleStrategy.INSTANCE)
        .outputDirectory(outputDirectory)
        .outputFileNamePrefix("explicit-opts")
        .build();

    assertEquals(3, configuration.warmUpIterations());
    assertEquals(11, configuration.iterations());
    assertEquals(666, configuration.numberOfMessages());
    assertEquals(4, configuration.batchSize());
    assertEquals(119, configuration.messageLength());
    assertSame(InMemoryMessageTransceiver.class, configuration.messageTransceiverClass());
    assertSame(NoOpIdleStrategy.INSTANCE, configuration.sendIdleStrategy());
    assertSame(YieldingIdleStrategy.INSTANCE, configuration.receiveIdleStrategy());
    assertEquals(outputDirectory.toAbsolutePath(), configuration.outputDirectory());
    assertTrue(configuration.outputFileNamePrefix().startsWith("explicit-opts"));
}
 
Example #8
Source File: ConfigurationTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
@Test
void toStringPrintsConfiguredValues()
{
    final Configuration configuration = new Builder()
        .warmUpIterations(4)
        .iterations(10)
        .numberOfMessages(777)
        .batchSize(2)
        .messageLength(64)
        .messageTransceiverClass(InMemoryMessageTransceiver.class)
        .sendIdleStrategy(NoOpIdleStrategy.INSTANCE)
        .receiveIdleStrategy(YieldingIdleStrategy.INSTANCE)
        .outputFileNamePrefix("my-file")
        .systemProperties(props("java", "25"))
        .build();

    assertEquals("Configuration{" +
        "\n    warmUpIterations=4" +
        "\n    iterations=10" +
        "\n    numberOfMessages=777" +
        "\n    batchSize=2" +
        "\n    messageLength=64" +
        "\n    messageTransceiverClass=uk.co.real_logic.benchmarks.remote.InMemoryMessageTransceiver" +
        "\n    sendIdleStrategy=NoOpIdleStrategy{alias=noop}" +
        "\n    receiveIdleStrategy=YieldingIdleStrategy{alias=yield}" +
        "\n    outputDirectory=" + Paths.get("results").toAbsolutePath() +
        "\n    outputFileNamePrefix=my-file_777_2_64" +
        "_73ccec448ba12264acb12e7f9f36fddc73e8c62e43549b786a901c88891610c9" +
        "\n}",
        configuration.toString());
}
 
Example #9
Source File: ConfigurationTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
@Test
void fromSystemPropertiesOverrideAll(final @TempDir Path tempDir)
{
    setProperty(WARM_UP_ITERATIONS_PROP_NAME, "2");
    setProperty(ITERATIONS_PROP_NAME, "4");
    setProperty(MESSAGES_PROP_NAME, "200");
    setProperty(BATCH_SIZE_PROP_NAME, "3");
    setProperty(MESSAGE_LENGTH_PROP_NAME, "24");
    setProperty(MESSAGE_TRANSCEIVER_PROP_NAME, InMemoryMessageTransceiver.class.getName());
    setProperty(SEND_IDLE_STRATEGY_PROP_NAME, YieldingIdleStrategy.class.getName());
    setProperty(RECEIVE_IDLE_STRATEGY_PROP_NAME, BusySpinIdleStrategy.class.getName());
    final Path outputDirectory = tempDir.resolve("my-output-dir-prop");
    setProperty(OUTPUT_DIRECTORY_PROP_NAME, outputDirectory.toAbsolutePath().toString());
    setProperty(OUTPUT_FILE_NAME_PREFIX_PROP_NAME, "my-out-file");

    final Configuration configuration = fromSystemProperties();

    assertEquals(2, configuration.warmUpIterations());
    assertEquals(4, configuration.iterations());
    assertEquals(200, configuration.numberOfMessages());
    assertEquals(3, configuration.batchSize());
    assertEquals(24, configuration.messageLength());
    assertSame(InMemoryMessageTransceiver.class, configuration.messageTransceiverClass());
    assertTrue(configuration.sendIdleStrategy() instanceof YieldingIdleStrategy);
    assertTrue(configuration.receiveIdleStrategy() instanceof BusySpinIdleStrategy);
    assertEquals(outputDirectory.toAbsolutePath(), configuration.outputDirectory());
    assertTrue(configuration.outputFileNamePrefix().startsWith("my-out-file"));
}
 
Example #10
Source File: IndexedReplicatedRecording.java    From aeron with Apache License 2.0 5 votes vote down vote up
public void run()
{
    while (!subscription.isConnected() || !publication.isConnected())
    {
        try
        {
            Thread.sleep(1);
        }
        catch (final InterruptedException ignore)
        {
            Thread.currentThread().interrupt();
            return;
        }
    }

    final Image image = subscription.imageBySessionId(sessionId);
    this.image = image;
    if (null == image)
    {
        throw new IllegalStateException("session not found");
    }

    lastMessagePosition = image.joinPosition();

    final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
    while (true)
    {
        final int fragments = image.controlledPoll(this, FRAGMENT_LIMIT);
        if (0 == fragments)
        {
            if (Thread.interrupted() || image.isClosed())
            {
                return;
            }
        }

        idleStrategy.idle(fragments);
    }
}
 
Example #11
Source File: TestCluster.java    From aeron with Apache License 2.0 5 votes vote down vote up
static ServiceContext serviceContext(
    final int nodeIndex,
    final int serviceId,
    final NodeContext nodeContext,
    final Supplier<? extends TestNode.TestService> serviceSupplier)
{
    final int serviceIndex = 3 * nodeIndex + serviceId;
    final String baseDirName = CommonContext.getAeronDirectoryName() + "-" + nodeIndex + "-" + serviceIndex;
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeIndex + "-driver";
    final ServiceContext serviceCtx = new ServiceContext();

    serviceCtx.service = serviceSupplier.get();

    serviceCtx.aeronCtx
        .aeronDirectoryName(aeronDirName)
        .awaitingIdleStrategy(YieldingIdleStrategy.INSTANCE);

    serviceCtx.aeronArchiveCtx
        .controlRequestChannel(nodeContext.archiveCtx.controlChannel())
        .controlRequestStreamId(nodeContext.archiveCtx.controlStreamId())
        .controlResponseChannel(memberSpecificPort(ARCHIVE_CONTROL_RESPONSE_CHANNEL, serviceIndex))
        .controlResponseStreamId(1100 + serviceIndex)
        .recordingEventsChannel(nodeContext.archiveCtx.recordingEventsChannel());

    serviceCtx.serviceContainerCtx
        .archiveContext(serviceCtx.aeronArchiveCtx.clone())
        .clusterDir(new File(baseDirName, "service"))
        .clusteredService(serviceCtx.service)
        .serviceId(serviceId)
        .snapshotChannel(SNAPSHOT_CHANNEL_DEFAULT + "|term-length=64k")
        .errorHandler(ClusterTests.errorHandler(serviceIndex));

    return serviceCtx;
}
 
Example #12
Source File: ClusterTests.java    From aeron with Apache License 2.0 5 votes vote down vote up
public static Thread startMessageThread(final TestCluster cluster, final long backoffIntervalNs)
{
    final Thread thread = new Thread(
        () ->
        {
            final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
            final AeronCluster client = cluster.client();
            final ExpandableArrayBuffer msgBuffer = cluster.msgBuffer();
            msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);

            while (!Thread.interrupted())
            {
                if (client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length()) < 0)
                {
                    LockSupport.parkNanos(backoffIntervalNs);
                }

                idleStrategy.idle(client.pollEgress());
            }
        });

    thread.setDaemon(true);
    thread.setName("message-thread");
    thread.start();

    return thread;
}
 
Example #13
Source File: MemoryOrderingTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
public void run()
{
    final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;

    while (messageNum < NUM_MESSAGES && null == failedMessage)
    {
        idleStrategy.idle(subscription.poll(fragmentAssembler, FRAGMENT_COUNT_LIMIT));
    }
}
 
Example #14
Source File: EmbeddedRecordingThroughput.java    From aeron with Apache License 2.0 4 votes vote down vote up
public long streamMessagesForRecording()
{
    try (ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID))
    {
        final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
        while (!publication.isConnected())
        {
            idleStrategy.idle();
        }

        final long startNs = System.nanoTime();
        final UnsafeBuffer buffer = this.buffer;

        for (long i = 0; i < NUMBER_OF_MESSAGES; i++)
        {
            buffer.putLong(0, i);

            idleStrategy.reset();
            while (publication.offer(buffer, 0, MESSAGE_LENGTH) < 0)
            {
                idleStrategy.idle();
            }
        }

        final long stopPosition = publication.position();
        final CountersReader counters = aeron.countersReader();
        final int counterId = RecordingPos.findCounterIdBySession(counters, publication.sessionId());

        idleStrategy.reset();
        while (counters.getCounterValue(counterId) < stopPosition)
        {
            idleStrategy.idle();
        }

        final long durationMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
        final double dataRate = (stopPosition * 1000.0d / durationMs) / MEGABYTE;
        final double recordingMb = stopPosition / MEGABYTE;
        final long msgRate = (NUMBER_OF_MESSAGES / durationMs) * 1000L;

        System.out.printf(
            "Recorded %.02f MB @ %.02f MB/s - %,d msg/sec - %d byte payload + 32 byte header%n",
            recordingMb, dataRate, msgRate, MESSAGE_LENGTH);

        return RecordingPos.getRecordingId(counters, counterId);
    }
}
 
Example #15
Source File: IndexedReplicatedRecording.java    From aeron with Apache License 2.0 4 votes vote down vote up
public IndexedReplicatedRecording()
{
    final String srcAeronDirectoryName = getAeronDirectoryName() + "-src";
    System.out.println("srcAeronDirectoryName=" + srcAeronDirectoryName);
    final String dstAeronDirectoryName = getAeronDirectoryName() + "-dst";
    System.out.println("dstAeronDirectoryName=" + dstAeronDirectoryName);

    final File srcArchiveDir = new File(SystemUtil.tmpDirName(), "src-archive");
    System.out.println("srcArchiveDir=" + srcArchiveDir);
    srcArchivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(srcAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Throwable::printStackTrace)
            .spiesSimulateConnection(true)
            .dirDeleteOnShutdown(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .controlChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(SRC_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(srcArchiveDir)
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    final File dstArchiveDir = new File(SystemUtil.tmpDirName(), "dst-archive");
    System.out.println("dstArchiveDir=" + dstArchiveDir);
    dstArchivingMediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(dstAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Throwable::printStackTrace)
            .spiesSimulateConnection(true)
            .dirDeleteOnShutdown(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .controlChannel(DST_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(DST_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(dstArchiveDir)
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    srcAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(srcAeronDirectoryName));

    dstAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(dstAeronDirectoryName));

    srcAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL)
            .aeron(srcAeron));

    dstAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(DST_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL)
            .aeron(dstAeron));
}
 
Example #16
Source File: Tests.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void yieldingWait(final String message)
{
    wait(YieldingIdleStrategy.INSTANCE, message);
}
 
Example #17
Source File: Tests.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void yieldingWait(final String format, final Object... params)
{
    wait(YieldingIdleStrategy.INSTANCE, format, params);
}
 
Example #18
Source File: Tests.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static void yieldingWait(final Supplier<String> messageSupplier)
{
    wait(YieldingIdleStrategy.INSTANCE, messageSupplier);
}
 
Example #19
Source File: MemoryOrderingTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
@Test
@Timeout(10)
public void shouldReceiveMessagesInOrderWithFirstLongWordIntactFromExclusivePublication() throws Exception
{
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
    srcBuffer.setMemory(0, MESSAGE_LENGTH, (byte)7);

    try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
        ExclusivePublication publication = aeron.addExclusivePublication(CHANNEL, STREAM_ID))
    {
        final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
        final Thread subscriberThread = new Thread(new Subscriber(subscription));
        subscriberThread.setDaemon(true);
        subscriberThread.start();

        for (int i = 0; i < NUM_MESSAGES; i++)
        {
            if (null != failedMessage)
            {
                fail(failedMessage);
            }

            srcBuffer.putLong(0, i);

            while (publication.offer(srcBuffer) < 0L)
            {
                if (null != failedMessage)
                {
                    fail(failedMessage);
                }

                idleStrategy.idle();
                Tests.checkInterruptStatus();
            }

            if (i % BURST_LENGTH == 0)
            {
                final long timeoutNs = System.nanoTime() + INTER_BURST_DURATION_NS;
                long nowNs;
                do
                {
                    nowNs = System.nanoTime();
                }
                while ((timeoutNs - nowNs) > 0);
            }
        }

        subscriberThread.join();
    }
}
 
Example #20
Source File: MemoryOrderingTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
@Test
@Timeout(10)
public void shouldReceiveMessagesInOrderWithFirstLongWordIntact() throws Exception
{
    final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocate(MESSAGE_LENGTH));
    srcBuffer.setMemory(0, MESSAGE_LENGTH, (byte)7);

    try (Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID);
        Publication publication = aeron.addPublication(CHANNEL, STREAM_ID))
    {
        final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
        final Thread subscriberThread = new Thread(new Subscriber(subscription));
        subscriberThread.setDaemon(true);
        subscriberThread.start();

        for (int i = 0; i < NUM_MESSAGES; i++)
        {
            if (null != failedMessage)
            {
                fail(failedMessage);
            }

            srcBuffer.putLong(0, i);

            while (publication.offer(srcBuffer) < 0L)
            {
                if (null != failedMessage)
                {
                    fail(failedMessage);
                }

                idleStrategy.idle();
                Tests.checkInterruptStatus();
            }

            if (i % BURST_LENGTH == 0)
            {
                final long timeoutNs = System.nanoTime() + INTER_BURST_DURATION_NS;
                long nowNs;
                do
                {
                    nowNs = System.nanoTime();
                }
                while ((timeoutNs - nowNs) > 0);
            }
        }

        subscriberThread.join();
    }
}
 
Example #21
Source File: ArchiveTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
private void before(final ThreadingMode threadingMode, final ArchiveThreadingMode archiveThreadingMode)
{
    if (threadingMode == ThreadingMode.INVOKER)
    {
        TestMediaDriver.notSupportedOnCMediaDriver("C driver does not integrate with Java Invoker");
    }

    rnd.setSeed(seed);
    requestedInitialTermId = rnd.nextInt(1234);

    final int termLength = 1 << (16 + rnd.nextInt(10)); // 1M to 8M
    final int mtu = 1 << (10 + rnd.nextInt(3)); // 1024 to 8096
    final int requestedStartTermOffset = BitUtil.align(rnd.nextInt(termLength), FrameDescriptor.FRAME_ALIGNMENT);
    final int requestedStartTermId = requestedInitialTermId + rnd.nextInt(1000);
    final int segmentFileLength = termLength << rnd.nextInt(4);

    publishUri = new ChannelUriStringBuilder()
        .media("udp")
        .endpoint("localhost:24325")
        .termLength(termLength)
        .mtu(mtu)
        .initialTermId(requestedInitialTermId)
        .termId(requestedStartTermId)
        .termOffset(requestedStartTermOffset)
        .build();

    requestedStartPosition =
        ((requestedStartTermId - requestedInitialTermId) * (long)termLength) + requestedStartTermOffset;

    driver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .termBufferSparseFile(true)
            .threadingMode(threadingMode)
            .sharedIdleStrategy(YieldingIdleStrategy.INSTANCE)
            .spiesSimulateConnection(true)
            .errorHandler(Tests::onError)
            .dirDeleteOnStart(true),
        testWatcher);

    final Archive.Context archiveContext = new Archive.Context()
        .maxCatalogEntries(MAX_CATALOG_ENTRIES)
        .fileSyncLevel(SYNC_LEVEL)
        .deleteArchiveOnStart(true)
        .archiveDir(new File(SystemUtil.tmpDirName(), "archive-test"))
        .segmentFileLength(segmentFileLength)
        .threadingMode(archiveThreadingMode)
        .idleStrategySupplier(YieldingIdleStrategy::new)
        .errorHandler(Tests::onError);

    if (threadingMode == ThreadingMode.INVOKER)
    {
        archiveContext.mediaDriverAgentInvoker(driver.sharedAgentInvoker());
    }

    archive = Archive.launch(archiveContext);
    client = Aeron.connect();

    recorded = 0;
}
 
Example #22
Source File: ReplicateRecordingTest.java    From aeron with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void before()
{
    final String srcAeronDirectoryName = generateRandomDirName();
    final String dstAeronDirectoryName = generateRandomDirName();

    srcMediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(srcAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true), testWatcher);

    srcArchive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(srcAeronDirectoryName)
            .controlChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(SRC_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "src-archive"))
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    dstMediaDriver = TestMediaDriver.launch(
        new MediaDriver.Context()
            .aeronDirectoryName(dstAeronDirectoryName)
            .termBufferSparseFile(true)
            .threadingMode(ThreadingMode.SHARED)
            .errorHandler(Tests::onError)
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true), testWatcher);

    dstArchive = Archive.launch(
        new Archive.Context()
            .maxCatalogEntries(MAX_CATALOG_ENTRIES)
            .aeronDirectoryName(dstAeronDirectoryName)
            .controlChannel(DST_CONTROL_REQUEST_CHANNEL)
            .archiveClientContext(new AeronArchive.Context().controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL))
            .recordingEventsEnabled(false)
            .replicationChannel(DST_REPLICATION_CHANNEL)
            .deleteArchiveOnStart(true)
            .archiveDir(new File(SystemUtil.tmpDirName(), "dst-archive"))
            .fileSyncLevel(0)
            .threadingMode(ArchiveThreadingMode.SHARED));

    srcAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(srcAeronDirectoryName));

    dstAeron = Aeron.connect(
        new Aeron.Context()
            .aeronDirectoryName(dstAeronDirectoryName));

    srcAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(SRC_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(SRC_CONTROL_RESPONSE_CHANNEL)
            .aeron(srcAeron));

    dstAeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .idleStrategy(YieldingIdleStrategy.INSTANCE)
            .controlRequestChannel(DST_CONTROL_REQUEST_CHANNEL)
            .controlResponseChannel(DST_CONTROL_RESPONSE_CHANNEL)
            .aeron(dstAeron));
}
 
Example #23
Source File: AeronUtilTest.java    From benchmarks with Apache License 2.0 4 votes vote down vote up
@Test
void explicitConfigurationValues()
{
    final String senderChannel = "sender";
    final int senderStreamId = Integer.MIN_VALUE;
    final String receiverChannel = "receiver";
    final int receiverStreamId = Integer.MAX_VALUE;
    final String archiveChannel = "archive";
    final int archiveStreamId = 777;
    final boolean embeddedMediaDriver = true;
    final int fragmentLimit = 111;

    setProperty(SEND_CHANNEL_PROP_NAME, senderChannel);
    setProperty(SEND_STREAM_ID_PROP_NAME, valueOf(senderStreamId));
    setProperty(RECEIVE_CHANNEL_PROP_NAME, receiverChannel);
    setProperty(RECEIVE_STREAM_ID_PROP_NAME, valueOf(receiverStreamId));
    setProperty(ARCHIVE_CHANNEL_PROP_NAME, archiveChannel);
    setProperty(ARCHIVE_STREAM_ID_PROP_NAME, valueOf(archiveStreamId));
    setProperty(EMBEDDED_MEDIA_DRIVER_PROP_NAME, valueOf(embeddedMediaDriver));
    setProperty(FRAGMENT_LIMIT_PROP_NAME, valueOf(fragmentLimit));
    setProperty(IDLE_STRATEGY, YieldingIdleStrategy.class.getName());

    try
    {
        assertEquals(senderChannel, sendChannel());
        assertEquals(senderStreamId, sendStreamId());
        assertEquals(receiverChannel, receiveChannel());
        assertEquals(receiverStreamId, receiveStreamId());
        assertEquals(embeddedMediaDriver, embeddedMediaDriver());
        assertEquals(fragmentLimit, fragmentLimit());
        assertEquals(YieldingIdleStrategy.class, idleStrategy().getClass());
    }
    finally
    {
        clearProperty(SEND_CHANNEL_PROP_NAME);
        clearProperty(SEND_STREAM_ID_PROP_NAME);
        clearProperty(RECEIVE_CHANNEL_PROP_NAME);
        clearProperty(RECEIVE_STREAM_ID_PROP_NAME);
        clearProperty(ARCHIVE_CHANNEL_PROP_NAME);
        clearProperty(ARCHIVE_STREAM_ID_PROP_NAME);
        clearProperty(EMBEDDED_MEDIA_DRIVER_PROP_NAME);
        clearProperty(FRAGMENT_LIMIT_PROP_NAME);
        clearProperty(IDLE_STRATEGY);
    }
}