use of io.aeron.logbuffer.BufferClaim in project Aeron by real-logic.
the class BufferClaimMessageTest method shouldReceivePublishedMessageWithInterleavedAbort.
@Theory
@Test(timeout = 10000)
public void shouldReceivePublishedMessageWithInterleavedAbort(final String channel) throws Exception {
final BufferClaim bufferClaim = new BufferClaim();
final UnsafeBuffer srcBuffer = new UnsafeBuffer(ByteBuffer.allocateDirect(MESSAGE_LENGTH));
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)) {
publishMessage(srcBuffer, publication);
while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
Thread.yield();
}
publishMessage(srcBuffer, publication);
bufferClaim.abort();
final int expectedNumberOfFragments = 2;
int numFragments = 0;
do {
numFragments += subscription.poll(mockFragmentHandler, FRAGMENT_COUNT_LIMIT);
} while (numFragments < expectedNumberOfFragments);
verify(mockFragmentHandler, times(expectedNumberOfFragments)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
} finally {
ctx.deleteAeronDirectory();
}
}
use of io.aeron.logbuffer.BufferClaim in project Aeron by real-logic.
the class PublicationTest method shouldEnsureThePublicationIsOpenBeforeClaim.
@Test
public void shouldEnsureThePublicationIsOpenBeforeClaim() {
publication.close();
final BufferClaim bufferClaim = new BufferClaim();
assertThat(publication.tryClaim(SEND_BUFFER_CAPACITY, bufferClaim), is(Publication.CLOSED));
}
use of io.aeron.logbuffer.BufferClaim in project Aeron by real-logic.
the class PublicationUnblockTest method shouldUnblockNonCommittedMessage.
@Theory
@Test(timeout = 10000)
public void shouldUnblockNonCommittedMessage(final String channel) throws Exception {
final FragmentHandler mockFragmentHandler = mock(FragmentHandler.class);
final MediaDriver.Context ctx = new MediaDriver.Context();
ctx.publicationUnblockTimeoutNs(TimeUnit.MILLISECONDS.toNanos(10));
try (MediaDriver ignore = MediaDriver.launch(ctx);
Aeron client = Aeron.connect(new Aeron.Context());
Publication publicationA = client.addPublication(channel, STREAM_ID);
Publication publicationB = client.addPublication(channel, STREAM_ID);
Subscription subscription = client.addSubscription(channel, STREAM_ID)) {
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[ctx.mtuLength()]);
final int length = 128;
final BufferClaim bufferClaim = new BufferClaim();
srcBuffer.setMemory(0, length, (byte) 66);
while (publicationA.tryClaim(length, bufferClaim) < 0L) {
Thread.yield();
}
bufferClaim.buffer().setMemory(bufferClaim.offset(), length, (byte) 65);
bufferClaim.commit();
while (publicationB.offer(srcBuffer, 0, length) < 0L) {
Thread.yield();
}
while (publicationA.tryClaim(length, bufferClaim) < 0L) {
Thread.yield();
}
while (publicationB.offer(srcBuffer, 0, length) < 0L) {
Thread.yield();
}
final int expectedFragments = 3;
int numFragments = 0;
do {
numFragments += subscription.poll(mockFragmentHandler, FRAGMENT_COUNT_LIMIT);
} while (numFragments < expectedFragments);
assertThat(numFragments, is(3));
} finally {
ctx.deleteAeronDirectory();
}
}
use of io.aeron.logbuffer.BufferClaim 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();
}
}
Aggregations