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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations