Search in sources :

Example 11 with MutableBoolean

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

the class BufferClaimMessageTest method shouldTransferReservedValue.

@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldTransferReservedValue(final String channel) {
    final BufferClaim bufferClaim = new BufferClaim();
    try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
        Publication publication = aeron.addPublication(channel, STREAM_ID)) {
        while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
            Tests.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) -> {
                assertEquals(MESSAGE_LENGTH, length);
                assertEquals(reservedValue, header.reservedValue());
                done.value = true;
            }, FRAGMENT_COUNT_LIMIT);
            if (0 == fragments) {
                Tests.yield();
            }
        }
    }
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) BufferClaim(io.aeron.logbuffer.BufferClaim) InterruptAfter(io.aeron.test.InterruptAfter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with MutableBoolean

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

the class ArchiveTest method verifyDescriptorListOngoingArchive.

private void verifyDescriptorListOngoingArchive(final ArchiveProxy archiveProxy, final int publicationTermBufferLength) {
    final long requestCorrelationId = client.nextCorrelationId();
    archiveProxy.listRecording(recordingId, requestCorrelationId, controlSessionId);
    final MutableBoolean isDone = new MutableBoolean();
    final ControlResponseAdapter controlResponseAdapter = new ControlResponseAdapter(new FailControlResponseListener() {

        public void onRecordingDescriptor(final long controlSessionId, final long correlationId, final long recordingId, final long startTimestamp, final long stopTimestamp, final long startPosition, final long stopPosition, final int initialTermId, final int segmentFileLength, final int termBufferLength, final int mtuLength, final int sessionId, final int streamId, final String strippedChannel, final String originalChannel, final String sourceIdentity) {
            assertEquals(requestCorrelationId, correlationId);
            assertEquals(ArchiveTest.this.recordingId, recordingId);
            assertEquals(publicationTermBufferLength, termBufferLength);
            assertEquals(PUBLISH_STREAM_ID, streamId);
            assertEquals(publishUri, originalChannel);
            isDone.set(true);
        }
    }, controlResponse, 1);
    while (!isDone.get()) {
        if (controlResponseAdapter.poll() == 0) {
            if (!controlResponse.isConnected()) {
                throw new IllegalStateException("control response not connected");
            }
            Tests.yield();
        }
    }
}
Also used : ControlResponseAdapter(io.aeron.archive.client.ControlResponseAdapter) MutableBoolean(org.agrona.collections.MutableBoolean)

Example 13 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 isRecordingStarted = new MutableBoolean();
    final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(new FailRecordingEventsListener() {

        public void onStart(final long recordingId, final long startPosition0, final int sessionId0, final int streamId, final String channel, final String sourceIdentity) {
            ArchiveTest.this.recordingId = recordingId;
            assertEquals(PUBLISH_STREAM_ID, streamId);
            assertEquals(sessionId, sessionId0);
            assertEquals(startPosition, startPosition0);
            isRecordingStarted.set(true);
        }
    }, recordingEvents, 1);
    while (!isRecordingStarted.get()) {
        if (recordingEventsAdapter.poll() == 0) {
            if (!recordingEvents.isConnected()) {
                throw new IllegalStateException("recording events not connected");
            }
            Tests.yield();
        }
    }
    verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) RecordingEventsAdapter(io.aeron.archive.client.RecordingEventsAdapter)

Example 14 with MutableBoolean

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

the class ClusterTest method shouldRejectAnInvalidAdminRequest.

@Test
@InterruptAfter(10)
void shouldRejectAnInvalidAdminRequest() {
    final AdminRequestType invalidRequestType = AdminRequestType.NULL_VAL;
    final AtomicBoolean authorisationServiceCalled = new AtomicBoolean();
    cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
        authorisationServiceCalled.set(true);
        assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
        assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
        assertEquals(invalidRequestType, type);
        return true;
    }).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, invalidRequestType, AdminResponseCode.ERROR, "Unknown request type: " + invalidRequestType);
    final AeronCluster client = cluster.connectClient();
    final AdminRequestEncoder adminRequestEncoder = new AdminRequestEncoder().wrapAndApplyHeader(cluster.msgBuffer(), 0, new MessageHeaderEncoder()).leadershipTermId(client.leadershipTermId()).clusterSessionId(client.clusterSessionId()).correlationId(requestCorrelationId).requestType(invalidRequestType);
    final Publication ingressPublication = client.ingressPublication();
    while (ingressPublication.offer(adminRequestEncoder.buffer(), 0, MessageHeaderEncoder.ENCODED_LENGTH + adminRequestEncoder.encodedLength()) < 0) {
        Tests.yield();
    }
    Tests.await(authorisationServiceCalled::get);
    while (!responseReceived.get()) {
        client.pollEgress();
        Tests.yield();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutableBoolean(org.agrona.collections.MutableBoolean) AeronCluster(io.aeron.cluster.client.AeronCluster) Publication(io.aeron.Publication) Test(org.junit.jupiter.api.Test)

Example 15 with MutableBoolean

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

the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll.

@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll() {
    cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
        assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
        assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
        assertEquals(AdminRequestType.SNAPSHOT, type);
        return true;
    }).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminRequestControlledEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
    final AeronCluster client = cluster.connectClient();
    while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.controlledPollEgress();
        Tests.yield();
    }
    cluster.awaitSnapshotCount(1);
    cluster.awaitNeutralControlToggle(leader);
}
Also used : MutableBoolean(org.agrona.collections.MutableBoolean) AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Aggregations

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