use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class StopStartSecondSubscriberTest method shouldReceivePublishedMessage.
@Test
@InterruptAfter(10)
void shouldReceivePublishedMessage() {
launch(CHANNEL1, STREAM_ID1, CHANNEL2, STREAM_ID2);
buffer.putInt(0, 1);
final int messagesPerPublication = 1;
while (publicationOne.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
while (publicationTwo.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
final MutableInteger fragmentsRead1 = new MutableInteger();
final MutableInteger fragmentsRead2 = new MutableInteger();
Tests.executeUntil(() -> fragmentsRead1.get() >= messagesPerPublication && fragmentsRead2.get() >= messagesPerPublication, (i) -> {
fragmentsRead1.value += subscriptionOne.poll(fragmentHandlerOne, 10);
fragmentsRead2.value += subscriptionTwo.poll(fragmentHandlerTwo, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(9900));
assertEquals(messagesPerPublication, subOneCount.get());
assertEquals(messagesPerPublication, subTwoCount.get());
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class PongTest method playPingPongWithRestart.
@SlowTest
@Test
void playPingPongWithRestart() {
buffer.putInt(0, 1);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
final MutableInteger fragmentsRead = new MutableInteger();
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pongSubscription.poll(pongHandler, 1);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
// close Pong side
pongPublication.close();
pingSubscription.close();
// wait for disconnect to ensure we stay in lock step
while (pingPublication.isConnected()) {
Tests.sleep(10);
}
// restart Pong side
pingSubscription = pingClient.addSubscription(PING_URI, PING_STREAM_ID);
pongPublication = pongClient.addPublication(PONG_URI, PONG_STREAM_ID);
fragmentsRead.set(0);
while (pingPublication.offer(buffer, 0, BitUtil.SIZE_OF_INT) < 0L) {
Tests.yield();
}
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pingSubscription.poll(this::echoPingHandler, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
fragmentsRead.set(0);
Tests.executeUntil(() -> fragmentsRead.get() > 0, (i) -> {
fragmentsRead.value += pongSubscription.poll(pongHandler, 10);
Thread.yield();
}, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(5900));
verify(pongHandler, times(2)).onFragment(any(DirectBuffer.class), eq(DataHeaderFlyweight.HEADER_LENGTH), eq(BitUtil.SIZE_OF_INT), any(Header.class));
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class SelectorAndTransportTest method shouldHandleSmFrameFromReceiverToSender.
@Test
@InterruptAfter(10)
public void shouldHandleSmFrameFromReceiverToSender() {
final MutableInteger controlMessagesReceived = new MutableInteger(0);
doAnswer((invocation) -> {
controlMessagesReceived.value++;
return null;
}).when(mockPublication).onStatusMessage(any(), any());
receiveChannelEndpoint = new ReceiveChannelEndpoint(RCV_DST, mockDispatcher, mockReceiveStatusIndicator, context);
sendChannelEndpoint = new SendChannelEndpoint(SRC_DST, mockSendStatusIndicator, context);
sendChannelEndpoint.registerForSend(mockPublication);
receiveChannelEndpoint.openDatagramChannel(mockReceiveStatusIndicator);
receiveChannelEndpoint.registerForRead(dataTransportPoller);
sendChannelEndpoint.openDatagramChannel(mockSendStatusIndicator);
sendChannelEndpoint.registerForRead(controlTransportPoller);
statusMessage.wrap(buffer);
statusMessage.streamId(STREAM_ID).sessionId(SESSION_ID).consumptionTermId(TERM_ID).receiverWindowLength(1000).consumptionTermOffset(0).version(HeaderFlyweight.CURRENT_VERSION).flags((short) 0).headerType(HeaderFlyweight.HDR_TYPE_SM).frameLength(StatusMessageFlyweight.HEADER_LENGTH);
byteBuffer.position(0).limit(statusMessage.frameLength());
processLoop(dataTransportPoller, 5);
receiveChannelEndpoint.sendTo(byteBuffer, rcvRemoteAddress);
while (controlMessagesReceived.get() < 1) {
processLoop(controlTransportPoller, 1);
}
verify(mockStatusMessagesReceivedCounter, times(1)).incrementOrdered();
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class SelectorAndTransportTest method shouldSendMultipleDataFramesPerDatagramUnicastFromSourceToReceiver.
@Test
@InterruptAfter(10)
public void shouldSendMultipleDataFramesPerDatagramUnicastFromSourceToReceiver() {
final MutableInteger dataHeadersReceived = new MutableInteger(0);
doAnswer((invocation) -> {
dataHeadersReceived.value++;
return null;
}).when(mockDispatcher).onDataPacket(any(ReceiveChannelEndpoint.class), any(DataHeaderFlyweight.class), any(UnsafeBuffer.class), anyInt(), any(InetSocketAddress.class), anyInt());
receiveChannelEndpoint = new ReceiveChannelEndpoint(RCV_DST, mockDispatcher, mockReceiveStatusIndicator, context);
sendChannelEndpoint = new SendChannelEndpoint(SRC_DST, mockSendStatusIndicator, context);
receiveChannelEndpoint.openDatagramChannel(mockReceiveStatusIndicator);
receiveChannelEndpoint.registerForRead(dataTransportPoller);
sendChannelEndpoint.openDatagramChannel(mockSendStatusIndicator);
sendChannelEndpoint.registerForRead(controlTransportPoller);
encodeDataHeader.wrap(buffer);
encodeDataHeader.version(HeaderFlyweight.CURRENT_VERSION).flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS).headerType(HeaderFlyweight.HDR_TYPE_DATA).frameLength(FRAME_LENGTH);
encodeDataHeader.sessionId(SESSION_ID).streamId(STREAM_ID).termId(TERM_ID);
final int alignedFrameLength = BitUtil.align(FRAME_LENGTH, FrameDescriptor.FRAME_ALIGNMENT);
encodeDataHeader.wrap(buffer, alignedFrameLength, buffer.capacity() - alignedFrameLength);
encodeDataHeader.version(HeaderFlyweight.CURRENT_VERSION).flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS).headerType(HeaderFlyweight.HDR_TYPE_DATA).frameLength(24);
encodeDataHeader.sessionId(SESSION_ID).streamId(STREAM_ID).termId(TERM_ID);
byteBuffer.position(0).limit(2 * alignedFrameLength);
processLoop(dataTransportPoller, 5);
sendChannelEndpoint.send(byteBuffer);
while (dataHeadersReceived.get() < 1) {
processLoop(dataTransportPoller, 1);
}
assertEquals(1, dataHeadersReceived.get());
}
use of org.agrona.collections.MutableInteger in project aeron by real-logic.
the class ArchiveTool method verify.
static boolean verify(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Checksum checksum, final EpochClock epochClock, final ActionConfirmation<File> truncateOnPageStraddle) {
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
final MutableInteger errorCount = new MutableInteger();
catalog.forEach(createVerifyEntryProcessor(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle));
return errorCount.get() == 0;
}
}
Aggregations