Java Code Examples for org.agrona.collections.MutableInteger#get()
The following examples show how to use
org.agrona.collections.MutableInteger#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchiveTool.java From aeron with Apache License 2.0 | 6 votes |
static boolean verify( final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Checksum checksum, final EpochClock epochClock, final ActionConfirmation<File> truncateFileOnPageStraddle) { try (Catalog catalog = openCatalog(archiveDir, epochClock)) { final MutableInteger errorCount = new MutableInteger(); catalog.forEach(createVerifyEntryProcessor( out, archiveDir, options, checksum, epochClock, errorCount, truncateFileOnPageStraddle)); return errorCount.get() == 0; } }
Example 2
Source File: ArchiveTool.java From aeron with Apache License 2.0 | 6 votes |
static boolean verifyRecording( final PrintStream out, final File archiveDir, final long recordingId, final Set<VerifyOption> options, final Checksum checksum, final EpochClock epochClock, final ActionConfirmation<File> truncateFileOnPageStraddle) { try (Catalog catalog = openCatalog(archiveDir, epochClock)) { final MutableInteger errorCount = new MutableInteger(); if (!catalog.forEntry(recordingId, createVerifyEntryProcessor( out, archiveDir, options, checksum, epochClock, errorCount, truncateFileOnPageStraddle))) { throw new AeronException("no recording found with recordingId: " + recordingId); } return errorCount.get() == 0; } }
Example 3
Source File: OneToOneRingBufferConcurrentTest.java From agrona with Apache License 2.0 | 6 votes |
@Test public void shouldExchangeMessages() { new Producer().start(); final MutableInteger count = new MutableInteger(); final MessageHandler handler = (msgTypeId, buffer, index, length) -> { final int iteration = buffer.getInt(index); assertEquals(count.get(), iteration); count.increment(); }; while (count.get() < REPETITIONS) { final int readCount = ringBuffer.read(handler); if (0 == readCount) { Thread.yield(); } } }
Example 4
Source File: OneToOneRingBufferConcurrentTest.java From agrona with Apache License 2.0 | 6 votes |
@Test public void shouldExchangeMessagesViaTryClaimAbort() { new ClaimAbort().start(); final MutableInteger count = new MutableInteger(); final MessageHandler handler = (msgTypeId, buffer, index, length) -> { final int iteration = buffer.getInt(index); assertEquals(count.get(), iteration); assertEquals(MSG_TYPE_ID, buffer.getInt(typeOffset(index - HEADER_LENGTH))); count.increment(); }; while (count.get() < REPETITIONS) { final int readCount = ringBuffer.read(handler); if (0 == readCount) { Thread.yield(); } } }
Example 5
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 5 votes |
private void awaitResponse(final MutableInteger messageCount) { while (messageCount.get() == 0) { if (aeronCluster.pollEgress() <= 0) { Tests.yield(); } } }
Example 6
Source File: OneToOneRingBufferConcurrentTest.java From agrona with Apache License 2.0 | 5 votes |
@Test public void shouldExchangeMessagesViaTryClaimCommit() { new ClaimCommit().start(); final MutableInteger count = new MutableInteger(); final MessageHandler handler = (msgTypeId, buffer, index, length) -> { final int iteration = buffer.getInt(index); final long longVal = buffer.getLong(index + SIZE_OF_INT); assertEquals(count.get(), iteration); assertEquals(count.get() * 20L, longVal); count.increment(); }; while (count.get() < REPETITIONS) { final int readCount = ringBuffer.read(handler); if (0 == readCount) { Thread.yield(); } } }
Example 7
Source File: StopStartSecondSubscriberTest.java From aeron with Apache License 2.0 | 4 votes |
private void shouldReceiveMessagesAfterStopStart( final String channelOne, final int streamOne, final String channelTwo, final int streamTwo) { final ExecutorService executor = Executors.newFixedThreadPool(2); final int numMessages = 1; final MutableInteger subscriber2AfterRestartCount = new MutableInteger(); final AtomicBoolean running = new AtomicBoolean(true); final FragmentHandler fragmentHandler2b = (buffer, offset, length, header) -> subscriber2AfterRestartCount.value++; launch(channelOne, streamOne, channelTwo, streamTwo); buffer.putInt(0, 1); executor.execute(() -> doPublisherWork(publicationOne, running)); executor.execute(() -> doPublisherWork(publicationTwo, running)); final MutableInteger fragmentsReadOne = new MutableInteger(); final MutableInteger fragmentsReadTwo = new MutableInteger(); final BooleanSupplier fragmentsReadCondition = () -> fragmentsReadOne.get() >= numMessages && fragmentsReadTwo.get() >= numMessages; Tests.executeUntil( fragmentsReadCondition, (i) -> { fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1); fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandlerTwo, 1); Thread.yield(); }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900)); assertTrue(subOneCount.get() >= numMessages); assertTrue(subTwoCount.get() >= numMessages); subscriptionTwo.close(); fragmentsReadOne.set(0); fragmentsReadTwo.set(0); subscriptionTwo = subscriberTwo.addSubscription(channelTwo, streamTwo); Tests.executeUntil( fragmentsReadCondition, (i) -> { fragmentsReadOne.value += subscriptionOne.poll(fragmentHandlerOne, 1); fragmentsReadTwo.value += subscriptionTwo.poll(fragmentHandler2b, 1); Thread.yield(); }, Integer.MAX_VALUE, TimeUnit.MILLISECONDS.toNanos(4900)); running.set(false); assertTrue(subOneCount.get() >= numMessages * 2, "Expecting subscriberOne to receive messages the entire time"); assertTrue(subTwoCount.get() >= numMessages, "Expecting subscriberTwo to receive messages before being stopped and started"); assertTrue(subscriber2AfterRestartCount.get() >= numMessages, "Expecting subscriberTwo to receive messages after being stopped and started"); executor.shutdown(); try { while (!executor.awaitTermination(1, TimeUnit.SECONDS)) { System.err.println("awaiting termination"); } } catch (final InterruptedException ex) { LangUtil.rethrowUnchecked(ex); } }
Example 8
Source File: SelectorAndTransportTest.java From aeron with Apache License 2.0 | 4 votes |
@Test @Timeout(10) public void shouldSendEmptyDataFrameUnicastFromSourceToReceiver() { 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); byteBuffer.position(0).limit(FRAME_LENGTH); processLoop(dataTransportPoller, 5); sendChannelEndpoint.send(byteBuffer); while (dataHeadersReceived.get() < 1) { processLoop(dataTransportPoller, 1); } assertEquals(1, dataHeadersReceived.get()); }
Example 9
Source File: SelectorAndTransportTest.java From aeron with Apache License 2.0 | 4 votes |
@Test @Timeout(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()); }
Example 10
Source File: SelectorAndTransportTest.java From aeron with Apache License 2.0 | 4 votes |
@Test @Timeout(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(); }