Search in sources :

Example 21 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 22 with MutableBoolean

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

the class ClusterTest method injectAdminRequestControlledEgressListener.

private MutableBoolean injectAdminRequestControlledEgressListener(final long expectedCorrelationId, final AdminRequestType expectedRequestType, final AdminResponseCode expectedResponseCode, final String expectedMessage) {
    final MutableBoolean responseReceived = new MutableBoolean();
    cluster.controlledEgressListener(new ControlledEgressListener() {

        public ControlledFragmentHandler.Action onMessage(final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            return ControlledFragmentHandler.Action.ABORT;
        }

        public void onAdminResponse(final long clusterSessionId, final long correlationId, final AdminRequestType requestType, final AdminResponseCode responseCode, final String message, final DirectBuffer payload, final int payloadOffset, final int payloadLength) {
            responseReceived.set(true);
            assertEquals(expectedCorrelationId, correlationId);
            assertEquals(expectedRequestType, requestType);
            assertEquals(expectedResponseCode, responseCode);
            assertEquals(expectedMessage, message);
            assertNotNull(payload);
            final int minPayloadOffset = MessageHeaderEncoder.ENCODED_LENGTH + AdminResponseEncoder.BLOCK_LENGTH + AdminResponseEncoder.messageHeaderLength() + message.length() + AdminResponseEncoder.payloadHeaderLength();
            assertTrue(payloadOffset > minPayloadOffset);
            assertEquals(0, payloadLength);
        }
    });
    return responseReceived;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableBoolean(org.agrona.collections.MutableBoolean) ControlledEgressListener(io.aeron.cluster.client.ControlledEgressListener)

Example 23 with MutableBoolean

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

the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot.

@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot() {
    cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> AuthorisationService.ALLOW_ALL).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
    final AeronCluster client = cluster.connectClient();
    while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.pollEgress();
        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)

Example 24 with MutableBoolean

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

the class ClusterTest method shouldRejectAnAdminRequestIfLeadershipTermIsInvalid.

@Test
@InterruptAfter(10)
void shouldRejectAnAdminRequestIfLeadershipTermIsInvalid() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    cluster.awaitLeader();
    AeronCluster client = cluster.connectClient();
    final long requestCorrelationId = System.nanoTime();
    final long expectedLeadershipTermId = client.leadershipTermId();
    final long invalidLeadershipTermId = expectedLeadershipTermId - 1000;
    final AdminRequestType requestType = AdminRequestType.NULL_VAL;
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, requestType, AdminResponseCode.ERROR, "Invalid leadership term: expected " + expectedLeadershipTermId + ", got " + invalidLeadershipTermId);
    client = cluster.connectClient();
    final AdminRequestEncoder adminRequestEncoder = new AdminRequestEncoder().wrapAndApplyHeader(cluster.msgBuffer(), 0, new MessageHeaderEncoder()).leadershipTermId(invalidLeadershipTermId).clusterSessionId(client.clusterSessionId()).correlationId(requestCorrelationId).requestType(requestType);
    final Publication ingressPublication = client.ingressPublication();
    while (ingressPublication.offer(adminRequestEncoder.buffer(), 0, MessageHeaderEncoder.ENCODED_LENGTH + adminRequestEncoder.encodedLength()) < 0) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.pollEgress();
        Tests.yield();
    }
}
Also used : AeronCluster(io.aeron.cluster.client.AeronCluster) MutableBoolean(org.agrona.collections.MutableBoolean) Publication(io.aeron.Publication) Test(org.junit.jupiter.api.Test)

Example 25 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)

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