Search in sources :

Example 1 with MutableBoolean

use of org.agrona.collections.MutableBoolean in project aeron by real-logic.

the class BufferClaimMessageTest method shouldTransferReservedValue.

@Theory
@Test(timeout = 10_000)
public void shouldTransferReservedValue(final String channel) {
    final BufferClaim bufferClaim = new BufferClaim();
    try (Publication publication = aeron.addPublication(channel, STREAM_ID);
        Subscription subscription = aeron.addSubscription(channel, STREAM_ID)) {
        while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
        final long reservedValue = System.currentTimeMillis();
        bufferClaim.reservedValue(reservedValue);
        bufferClaim.commit();
        final MutableBoolean done = new MutableBoolean();
        while (!done.get()) {
            final int fragments = subscription.poll((buffer, offset, length, header) -> {
                assertThat(length, is(MESSAGE_LENGTH));
                assertThat(header.reservedValue(), is(reservedValue));
                done.value = true;
            }, FRAGMENT_COUNT_LIMIT);
            if (0 == fragments) {
                SystemTest.checkInterruptedStatus();
                Thread.yield();
            }
        }
    }
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) DataPoint(org.junit.experimental.theories.DataPoint) BufferClaim(io.aeron.logbuffer.BufferClaim) Theory(org.junit.experimental.theories.Theory) Test(org.junit.Test)

Example 2 with MutableBoolean

use of org.agrona.collections.MutableBoolean in project aeron by real-logic.

the class ArchiveTest method preSendChecks.

private void preSendChecks(final ArchiveProxy archiveProxy, final Subscription recordingEvents, final int sessionId, final int termBufferLength, final long startPosition) {
    final MutableBoolean recordingStarted = new MutableBoolean();
    final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(new FailRecordingEventsListener() {

        public void onStart(final long recordingId0, final long startPosition0, final int sessionId0, final int streamId0, final String channel, final String sourceIdentity) {
            recordingId = recordingId0;
            assertThat(streamId0, is(PUBLISH_STREAM_ID));
            assertThat(sessionId0, is(sessionId));
            assertThat(startPosition0, is(startPosition));
            recordingStarted.set(true);
        }
    }, recordingEvents, 1);
    while (!recordingStarted.get()) {
        if (recordingEventsAdapter.poll() == 0) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
    }
    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) RecordingEventsAdapter(io.aeron.archive.client.RecordingEventsAdapter)

Example 3 with MutableBoolean

use of org.agrona.collections.MutableBoolean in project Aeron by real-logic.

the class ArchiveToolTests method assertNoRecording.

private void assertNoRecording(final Catalog catalog, final long recordingId) {
    final MutableBoolean found = new MutableBoolean();
    catalog.forEach((recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
        if (recordingId == descriptorDecoder.recordingId()) {
            found.set(true);
        }
    });
    assertFalse(found.get(), () -> "recordingId=" + recordingId + " was found");
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean)

Example 4 with MutableBoolean

use of org.agrona.collections.MutableBoolean in project Aeron by real-logic.

the class ClusterTool method nextBackupQueryDeadlineMs.

/**
 * Set the deadline time (MS) for the next cluster backup query.
 *
 * @param markFile for the cluster component.
 * @param timeMs   to set for the next deadline.
 * @return true if successful, otherwise false.
 */
public static boolean nextBackupQueryDeadlineMs(final ClusterMarkFile markFile, final long timeMs) {
    final String aeronDirectoryName = markFile.decoder().aeronDirectory();
    final MutableBoolean result = new MutableBoolean(false);
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName))) {
        final CountersReader countersReader = aeron.countersReader();
        countersReader.forEach((counterId, typeId, keyBuffer, label) -> {
            if (ClusterBackup.QUERY_DEADLINE_TYPE_ID == typeId) {
                final AtomicCounter atomicCounter = new AtomicCounter(countersReader.valuesBuffer(), counterId, null);
                atomicCounter.setOrdered(timeMs);
                result.value = true;
            }
        });
    }
    return result.value;
}
Also used : CommonContext(io.aeron.CommonContext) MutableBoolean(org.agrona.collections.MutableBoolean) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) Aeron(io.aeron.Aeron) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 5 with MutableBoolean

use of org.agrona.collections.MutableBoolean in project Aeron by real-logic.

the class ArchiveTest method postPublicationValidations.

private void postPublicationValidations(final ArchiveProxy archiveProxy, final Subscription recordingEvents, final int termBufferLength, final int initialTermId, final int maxPayloadLength) {
    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
    assertNull(trackerError);
    final long requestCorrelationId = client.nextCorrelationId();
    if (!archiveProxy.stopRecording(publishUri, PUBLISH_STREAM_ID, requestCorrelationId, controlSessionId)) {
        throw new IllegalStateException("failed to send stop recording");
    }
    ArchiveTests.awaitOk(controlResponse, requestCorrelationId);
    final MutableBoolean isRecordingStopped = new MutableBoolean();
    final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(new FailRecordingEventsListener() {

        public void onStop(final long id, final long startPosition, final long stopPosition) {
            assertEquals(recordingId, id);
            isRecordingStopped.set(true);
        }
    }, recordingEvents, 1);
    while (!isRecordingStopped.get()) {
        if (recordingEventsAdapter.poll() == 0) {
            Tests.yield();
        }
    }
    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
    validateArchiveFile(recordingId);
    validateReplay(archiveProxy, initialTermId, maxPayloadLength, termBufferLength);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) RecordingEventsAdapter(io.aeron.archive.client.RecordingEventsAdapter)

Aggregations

MutableBoolean (org.agrona.collections.MutableBoolean)19 Test (org.junit.jupiter.api.Test)6 AeronCluster (io.aeron.cluster.client.AeronCluster)5 RecordingEventsAdapter (io.aeron.archive.client.RecordingEventsAdapter)4 TestNode (io.aeron.test.cluster.TestNode)3 Publication (io.aeron.Publication)2 ControlledEgressListener (io.aeron.cluster.client.ControlledEgressListener)2 BufferClaim (io.aeron.logbuffer.BufferClaim)2 Header (io.aeron.logbuffer.Header)2 DirectBuffer (org.agrona.DirectBuffer)2 Aeron (io.aeron.Aeron)1 CommonContext (io.aeron.CommonContext)1 ControlResponseAdapter (io.aeron.archive.client.ControlResponseAdapter)1 EgressListener (io.aeron.cluster.client.EgressListener)1 InterruptAfter (io.aeron.test.InterruptAfter)1 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)1 CountersReader (org.agrona.concurrent.status.CountersReader)1 Test (org.junit.Test)1