Search in sources :

Example 11 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class EmbeddedReplayThroughput method findRecordingId.

private long findRecordingId(final String expectedChannel) {
    final MutableLong foundRecordingId = new MutableLong();
    final RecordingDescriptorConsumer consumer = (controlSessionId, correlationId, recordingId, startTimestamp, stopTimestamp, startPosition, stopPosition, initialTermId, segmentFileLength, termBufferLength, mtuLength, sessionId, streamId, strippedChannel, originalChannel, sourceIdentity) -> foundRecordingId.set(recordingId);
    final int recordingsFound = aeronArchive.listRecordingsForUri(0L, 10, expectedChannel, STREAM_ID, consumer);
    if (1 != recordingsFound) {
        throw new IllegalStateException("should have been only one recording");
    }
    return foundRecordingId.get();
}
Also used : RecordingPos(io.aeron.archive.status.RecordingPos) MediaDriver(io.aeron.driver.MediaDriver) CACHE_LINE_LENGTH(org.agrona.BitUtil.CACHE_LINE_LENGTH) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer) SampleConfiguration(io.aeron.samples.SampleConfiguration) Archive(io.aeron.archive.Archive) SystemUtil.loadPropertiesFiles(org.agrona.SystemUtil.loadPropertiesFiles) CountersReader(org.agrona.concurrent.status.CountersReader) org.agrona.concurrent(org.agrona.concurrent) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) io.aeron(io.aeron) BufferUtil.allocateDirectAligned(org.agrona.BufferUtil.allocateDirectAligned) Header(io.aeron.logbuffer.Header) MutableLong(org.agrona.collections.MutableLong) NOOP_FRAGMENT_HANDLER(io.aeron.samples.archive.Samples.NOOP_FRAGMENT_HANDLER) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) SourceLocation(io.aeron.archive.codecs.SourceLocation) MEGABYTE(io.aeron.samples.archive.Samples.MEGABYTE) AeronArchive(io.aeron.archive.client.AeronArchive) ContinueBarrier(org.agrona.console.ContinueBarrier) CloseHelper(org.agrona.CloseHelper) DirectBuffer(org.agrona.DirectBuffer) ARCHIVE_DIR_DEFAULT(io.aeron.archive.Archive.Configuration.ARCHIVE_DIR_DEFAULT) MutableLong(org.agrona.collections.MutableLong) RecordingDescriptorConsumer(io.aeron.archive.client.RecordingDescriptorConsumer)

Example 12 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class TimestampingSystemTest method shouldSupportChannelSendTimestampsOnMdc.

@Test
@InterruptAfter(10)
void shouldSupportChannelSendTimestampsOnMdc() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Publication mdcPub = aeron.addPublication("aeron:udp?control-mode=manual|channel-snd-ts-offset=0", 1000);
        final Subscription sub1 = aeron.addSubscription("aeron:udp?endpoint=localhost:23424", 1000);
        final Subscription sub2 = aeron.addSubscription("aeron:udp?endpoint=localhost:23425", 1000);
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdcPub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!sub1.isConnected() || !sub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > mdcPub.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
        while (1 > sub1.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        while (1 > sub2.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 13 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMergedMds.

@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMergedMds() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription mdsSub = aeron.addSubscription("aeron:udp?control-mode=manual|channel-rcv-ts-offset=0", 1000);
        final Publication pub1 = aeron.addExclusivePublication("aeron:udp?endpoint=localhost:23424", 1000);
        final String pub2Uri = new ChannelUriStringBuilder("aeron:udp?endpoint=localhost:23425").initialPosition(0L, pub1.initialTermId(), pub1.termBufferLength()).sessionId(pub1.sessionId()).build();
        final Publication pub2 = aeron.addExclusivePublication(pub2Uri, 1000);
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23424");
        mdsSub.addDestination("aeron:udp?endpoint=localhost:23425");
        while (!pub1.isConnected() || !pub2.isConnected()) {
            Tests.yieldingIdle("Failed to connect");
        }
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
        while (1 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        sendTimestamp.set(SENTINEL_VALUE);
        while (1 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 14 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class TimestampingSystemTest method shouldSupportSendReceiveTimestamps.

@Test
@InterruptAfter(10)
void shouldSupportSendReceiveTimestamps() {
    final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
    try (TestMediaDriver driver = driver();
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
        final Subscription sub = aeron.addSubscription(CHANNEL_WITH_CHANNEL_TIMESTAMPS, 1000);
        while (null == sub.resolvedEndpoint()) {
            Tests.yieldingIdle("Failed to resolve endpoint");
        }
        final String uri = new ChannelUriStringBuilder(CHANNEL_WITH_CHANNEL_TIMESTAMPS).endpoint(requireNonNull(sub.resolvedEndpoint())).build();
        final Publication pub = aeron.addPublication(uri, 1000);
        Tests.awaitConnected(pub);
        buffer.putLong(0, SENTINEL_VALUE);
        buffer.putLong(8, SENTINEL_VALUE);
        while (0 > pub.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        final MutableLong receiveTimestamp = new MutableLong(SENTINEL_VALUE);
        final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
        final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> {
            receiveTimestamp.set(buffer1.getLong(offset));
            sendTimestamp.set(buffer1.getLong(offset + 8));
        };
        while (1 > sub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, receiveTimestamp.longValue());
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) RegistrationException(io.aeron.exceptions.RegistrationException) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) OS(org.junit.jupiter.api.condition.OS) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) MutableLong(org.agrona.collections.MutableLong) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) DirectBuffer(org.agrona.DirectBuffer) MutableLong(org.agrona.collections.MutableLong) FragmentHandler(io.aeron.logbuffer.FragmentHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableDirectBuffer(org.agrona.MutableDirectBuffer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 15 with MutableLong

use of org.agrona.collections.MutableLong in project Aeron by real-logic.

the class MultiDestinationSubscriptionTest method shouldMergeStreamsFromMultiplePublicationsWithSameParams.

@Test
@InterruptAfter(10)
void shouldMergeStreamsFromMultiplePublicationsWithSameParams() {
    final int numMessagesToSend = 30;
    final int numMessagesToSendForA = numMessagesToSend / 2;
    final int numMessagesToSendForB = numMessagesToSend / 2;
    launch(Tests::onError);
    launchSecond();
    final String publicationChannelA = new ChannelUriStringBuilder().media(CommonContext.UDP_MEDIA).endpoint(UNICAST_ENDPOINT_A).build();
    final String destinationB = new ChannelUriStringBuilder().media(CommonContext.UDP_MEDIA).endpoint(UNICAST_ENDPOINT_B).build();
    subscription = clientA.addSubscription(SUB_URI, STREAM_ID);
    subscription.addDestination(publicationChannelA);
    subscription.addDestination(destinationB);
    publicationA = clientA.addExclusivePublication(publicationChannelA, STREAM_ID);
    final String publicationChannelB = new ChannelUriStringBuilder().media(CommonContext.UDP_MEDIA).initialPosition(0L, publicationA.initialTermId(), publicationA.termBufferLength()).sessionId(publicationA.sessionId()).endpoint(UNICAST_ENDPOINT_B).build();
    publicationB = clientB.addExclusivePublication(publicationChannelB, STREAM_ID);
    final MutableLong position = new MutableLong(Long.MIN_VALUE);
    final Supplier<String> offerFailure = () -> "Failed to offer: " + position;
    for (int i = 0; i < numMessagesToSendForA; i++) {
        while (publicationA.offer(buffer, 0, buffer.capacity()) < 0L) {
            Tests.yield();
        }
        pollForFragment(subscription, fragmentHandler);
        while ((position.value = publicationB.offer(buffer, 0, buffer.capacity())) < 0L) {
            Tests.yieldingIdle(offerFailure);
        }
        assertEquals(0, subscription.poll(fragmentHandler, 10));
    }
    for (int i = 0; i < numMessagesToSendForB; i++) {
        while (publicationB.offer(buffer, 0, buffer.capacity()) < 0L) {
            Tests.yield();
        }
        pollForFragment(subscription, fragmentHandler);
        while (publicationA.offer(buffer, 0, buffer.capacity()) < 0L) {
            Tests.yield();
        }
        assertEquals(0, subscription.poll(fragmentHandler, 10));
    }
    assertEquals(1, subscription.imageCount());
    assertEquals(2, subscription.imageAtIndex(0).activeTransportCount());
    verifyFragments(fragmentHandler, numMessagesToSend);
}
Also used : MutableLong(org.agrona.collections.MutableLong) Test(org.junit.jupiter.api.Test)

Aggregations

MutableLong (org.agrona.collections.MutableLong)82 Test (org.junit.jupiter.api.Test)68 InterruptAfter (io.aeron.test.InterruptAfter)44 MutableReference (org.agrona.collections.MutableReference)28 CountersReader (org.agrona.concurrent.status.CountersReader)19 RecordingSignal (io.aeron.archive.codecs.RecordingSignal)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 MediaDriver (io.aeron.driver.MediaDriver)14 FragmentHandler (io.aeron.logbuffer.FragmentHandler)14 DirectBuffer (org.agrona.DirectBuffer)13 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)11 RegistrationException (io.aeron.exceptions.RegistrationException)10 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 AeronArchive (io.aeron.archive.client.AeronArchive)8 Authenticator (io.aeron.security.Authenticator)8 CredentialsSupplier (io.aeron.security.CredentialsSupplier)8