Search in sources :

Example 41 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer in project aeron by real-logic.

the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMds.

@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMds() {
    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.addPublication("aeron:udp?endpoint=localhost:23424", 1000);
        final Publication pub2 = aeron.addPublication("aeron:udp?endpoint=localhost:23425", 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");
        }
        buffer.putLong(0, SENTINEL_VALUE);
        while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
            Tests.yieldingIdle("Failed to offer message");
        }
        while (0 > pub2.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 > mdsSub.poll(fragmentHandler, 1)) {
            Tests.yieldingIdle("Failed to receive message");
        }
        assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
        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 42 with MutableDirectBuffer

use of org.agrona.MutableDirectBuffer 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)

Aggregations

MutableDirectBuffer (org.agrona.MutableDirectBuffer)42 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)18 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Test (org.junit.jupiter.api.Test)12 DirectBuffer (org.agrona.DirectBuffer)11 MediaDriver (io.aeron.driver.MediaDriver)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 RegistrationException (io.aeron.exceptions.RegistrationException)8 FragmentHandler (io.aeron.logbuffer.FragmentHandler)8 InterruptAfter (io.aeron.test.InterruptAfter)8 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)8 SystemTestWatcher (io.aeron.test.SystemTestWatcher)8 Tests (io.aeron.test.Tests)8 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 MutableLong (org.agrona.collections.MutableLong)8 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)8 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)8 Assumptions.assumeTrue (org.junit.jupiter.api.Assumptions.assumeTrue)8