Search in sources :

Example 81 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class TermBufferLengthTest method shouldHaveCorrectTermBufferLength.

@Theory
@Test(timeout = 10000)
public void shouldHaveCorrectTermBufferLength(final String channel) throws Exception {
    final MediaDriver.Context ctx = new MediaDriver.Context();
    ctx.publicationTermBufferLength(TEST_TERM_LENGTH * 2);
    ctx.ipcTermBufferLength(TEST_TERM_LENGTH * 2);
    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(channel, STREAM_ID)) {
        assertThat(publication.termBufferLength(), is(TEST_TERM_LENGTH));
    } finally {
        ctx.deleteAeronDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 82 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class BufferClaimMessageTest method shouldTransferReservedValue.

@Theory
@Test(timeout = 10000)
public void shouldTransferReservedValue(final String channel) throws Exception {
    final BufferClaim bufferClaim = new BufferClaim();
    final MediaDriver.Context ctx = new MediaDriver.Context();
    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(channel, STREAM_ID);
        Subscription subscription = aeron.addSubscription(channel, STREAM_ID)) {
        while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
            Thread.yield();
        }
        final long reservedValue = System.currentTimeMillis();
        bufferClaim.reservedValue(reservedValue);
        bufferClaim.commit();
        final boolean[] done = new boolean[1];
        while (!done[0]) {
            subscription.poll((buffer, offset, length, header) -> {
                assertThat(length, is(MESSAGE_LENGTH));
                assertThat(header.reservedValue(), is(reservedValue));
                done[0] = true;
            }, FRAGMENT_COUNT_LIMIT);
        }
    } finally {
        ctx.deleteAeronDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) BufferClaim(io.aeron.logbuffer.BufferClaim) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 83 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class ControlledMessageTest method shouldReceivePublishedMessage.

@Theory
@Test(timeout = 10000)
public void shouldReceivePublishedMessage() throws Exception {
    final MediaDriver.Context ctx = new MediaDriver.Context();
    ctx.threadingMode(ThreadingMode.SHARED);
    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(CHANNEL, STREAM_ID);
        Subscription subscription = aeron.addSubscription(CHANNEL, STREAM_ID)) {
        final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[PAYLOAD_LENGTH * 4]);
        for (int i = 0; i < 4; i++) {
            srcBuffer.setMemory(i * PAYLOAD_LENGTH, PAYLOAD_LENGTH, (byte) (65 + i));
        }
        for (int i = 0; i < 4; i++) {
            while (publication.offer(srcBuffer, i * PAYLOAD_LENGTH, PAYLOAD_LENGTH) < 0L) {
                Thread.yield();
            }
        }
        final FragmentCollector fragmentCollector = new FragmentCollector();
        int numFragments = 0;
        do {
            numFragments += subscription.controlledPoll(fragmentCollector, FRAGMENT_COUNT_LIMIT);
        } while (numFragments < 4);
        final UnsafeBuffer collectedBuffer = fragmentCollector.collectedBuffer();
        for (int i = 0; i < srcBuffer.capacity(); i++) {
            assertThat("same at i=" + i, collectedBuffer.getByte(i), is(srcBuffer.getByte(i)));
        }
    } finally {
        ctx.deleteAeronDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 84 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class ExclusivePublicationTest method shouldPublishFromIndependentExclusivePublications.

@Theory
@Test(timeout = 10000)
public void shouldPublishFromIndependentExclusivePublications(final String channel) throws Exception {
    final AtomicInteger imageCounter = new AtomicInteger();
    final AvailableImageHandler availableImageHandler = (image) -> imageCounter.getAndIncrement();
    final MediaDriver.Context driverCtx = new MediaDriver.Context();
    final Aeron.Context clientCtx = new Aeron.Context().availableImageHandler(availableImageHandler);
    try (MediaDriver ignore = MediaDriver.launch(driverCtx);
        Aeron aeron = Aeron.connect(clientCtx);
        ExclusivePublication publicationOne = aeron.addExclusivePublication(channel, STREAM_ID);
        ExclusivePublication publicationTwo = aeron.addExclusivePublication(channel, STREAM_ID);
        Subscription subscription = aeron.addSubscription(channel, STREAM_ID)) {
        final int expectedNumberOfFragments = 10;
        for (int i = 0; i < expectedNumberOfFragments; i += 2) {
            publishMessage(srcBuffer, publicationOne);
            publishMessage(srcBuffer, publicationTwo);
        }
        int totalFragmentsRead = 0;
        do {
            final int fragmentsRead = subscription.poll(mockFragmentHandler, FRAGMENT_COUNT_LIMIT);
            if (0 == fragmentsRead) {
                Thread.yield();
            }
            totalFragmentsRead += fragmentsRead;
        } while (totalFragmentsRead < expectedNumberOfFragments);
        verify(mockFragmentHandler, times(expectedNumberOfFragments)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
        assertThat(imageCounter.get(), is(2));
    } finally {
        driverCtx.deleteAeronDirectory();
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MediaDriver(io.aeron.driver.MediaDriver) RunWith(org.junit.runner.RunWith) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.Test) ByteBuffer(java.nio.ByteBuffer) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Header(io.aeron.logbuffer.Header) DataPoint(org.junit.experimental.theories.DataPoint) Theories(org.junit.experimental.theories.Theories) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FragmentHandler(io.aeron.logbuffer.FragmentHandler) DirectBuffer(org.agrona.DirectBuffer) Theory(org.junit.experimental.theories.Theory) DataPoint(org.junit.experimental.theories.DataPoint) DirectBuffer(org.agrona.DirectBuffer) MediaDriver(io.aeron.driver.MediaDriver) Header(io.aeron.logbuffer.Header) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 85 with Theory

use of org.junit.experimental.theories.Theory in project Aeron by real-logic.

the class FragmentedMessageTest method shouldReceivePublishedMessage.

@Theory
@Test(timeout = 10000)
public void shouldReceivePublishedMessage(final String channel, final ThreadingMode threadingMode) throws Exception {
    final MediaDriver.Context ctx = new MediaDriver.Context();
    ctx.threadingMode(threadingMode);
    final FragmentAssembler adapter = new FragmentAssembler(mockFragmentHandler);
    try (MediaDriver ignore = MediaDriver.launch(ctx);
        Aeron aeron = Aeron.connect();
        Publication publication = aeron.addPublication(channel, STREAM_ID);
        Subscription subscription = aeron.addSubscription(channel, STREAM_ID)) {
        final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[ctx.mtuLength() * 4]);
        final int offset = 0;
        final int length = srcBuffer.capacity() / 4;
        for (int i = 0; i < 4; i++) {
            srcBuffer.setMemory(i * length, length, (byte) (65 + i));
        }
        while (publication.offer(srcBuffer, offset, srcBuffer.capacity()) < 0L) {
            Thread.yield();
        }
        final int expectedFragmentsBecauseOfHeader = 5;
        int numFragments = 0;
        do {
            numFragments += subscription.poll(adapter, FRAGMENT_COUNT_LIMIT);
        } while (numFragments < expectedFragmentsBecauseOfHeader);
        final ArgumentCaptor<DirectBuffer> bufferArg = ArgumentCaptor.forClass(DirectBuffer.class);
        final ArgumentCaptor<Header> headerArg = ArgumentCaptor.forClass(Header.class);
        verify(mockFragmentHandler, times(1)).onFragment(bufferArg.capture(), eq(offset), eq(srcBuffer.capacity()), headerArg.capture());
        final DirectBuffer capturedBuffer = bufferArg.getValue();
        for (int i = 0; i < srcBuffer.capacity(); i++) {
            assertThat("same at i=" + i, capturedBuffer.getByte(i), is(srcBuffer.getByte(i)));
        }
        assertThat(headerArg.getValue().flags(), is(END_FRAG_FLAG));
    } finally {
        ctx.deleteAeronDirectory();
    }
}
Also used : DataPoint(org.junit.experimental.theories.DataPoint) DirectBuffer(org.agrona.DirectBuffer) MediaDriver(io.aeron.driver.MediaDriver) Header(io.aeron.logbuffer.Header) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Aggregations

Theory (org.junit.experimental.theories.Theory)107 DataPoint (org.junit.experimental.theories.DataPoint)23 Test (org.junit.Test)22 Header (io.aeron.logbuffer.Header)15 DirectBuffer (org.agrona.DirectBuffer)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)11 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)11 UdpChannel (io.aeron.driver.media.UdpChannel)11 MediaDriver (io.aeron.driver.MediaDriver)8 Lock (java.util.concurrent.locks.Lock)7 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 LongAdder (java.util.concurrent.atomic.LongAdder)6 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)6 PrimitiveCollection (org.neo4j.collection.primitive.PrimitiveCollection)6 InOrder (org.mockito.InOrder)5 InputStream (java.io.InputStream)4 BaseStream (java.util.stream.BaseStream)4 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)4 Metric (org.springframework.boot.actuate.metrics.Metric)4