Search in sources :

Example 16 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 17 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 18 with MutableBoolean

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

the class DriverNameResolverTest method shouldFallbackToAnotherBootstrapNeighborIfOneBecomesUnavailable.

@SlowTest
@Test
@InterruptAfter(20)
public void shouldFallbackToAnotherBootstrapNeighborIfOneBecomesUnavailable() {
    assumeTrue(TestMediaDriver.shouldRunJavaMediaDriver());
    final NameResolver bootstrapResolver = DriverNameResolver.bootstrapNameResolver;
    try {
        final MutableBoolean resolveHostA = new MutableBoolean(true);
        DriverNameResolver.bootstrapNameResolver = (name, uriParamName, isReResolution) -> (resolveHostA.get() || !name.endsWith("A")) ? DefaultNameResolver.INSTANCE.resolve(name.substring(0, name.length() - 1), uriParamName, isReResolution) : null;
        addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context()).aeronDirectoryName(baseDir + "-A").resolverName("A").resolverInterface("0.0.0.0:8050"), testWatcher));
        addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context()).aeronDirectoryName(baseDir + "-B").resolverName("B").resolverInterface("0.0.0.0:8051").resolverBootstrapNeighbor("localhostA:8050,localhostB:8051"), testWatcher));
        addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context()).aeronDirectoryName(baseDir + "-C").resolverName("C").resolverInterface("0.0.0.0:8052").resolverBootstrapNeighbor("localhostA:8050,localhostB:8051"), testWatcher));
        startClients();
        final int aNeighborsCounterId = awaitNeighborsCounterId("A");
        final int bNeighborsCounterId = awaitNeighborsCounterId("B");
        final int cNeighborsCounterId = awaitNeighborsCounterId("C");
        awaitCounterValue("A", aNeighborsCounterId, 2);
        awaitCounterValue("B", bNeighborsCounterId, 2);
        awaitCounterValue("C", cNeighborsCounterId, 2);
        awaitCounterLabel("A", aNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8050");
        awaitCounterLabel("B", bNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8051 bootstrap 127.0.0.1:8050");
        awaitCounterLabel("C", cNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8052 bootstrap 127.0.0.1:8050");
        closeDriver("A");
        resolveHostA.set(false);
        awaitCounterValue("B", bNeighborsCounterId, 1);
        awaitCounterValue("C", cNeighborsCounterId, 1);
        awaitCounterLabel("B", bNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8051 bootstrap 127.0.0.1:8051");
        awaitCounterLabel("C", cNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8052 bootstrap 127.0.0.1:8051");
        addDriver(TestMediaDriver.launch(setDefaults(new MediaDriver.Context()).aeronDirectoryName(baseDir + "-D").resolverName("D").resolverInterface("0.0.0.0:8053").resolverBootstrapNeighbor("localhostA:8050,localhostB:8051"), testWatcher));
        startClients();
        final int dNeighborsCounterId = awaitNeighborsCounterId("D");
        awaitCounterValue("B", bNeighborsCounterId, 2);
        awaitCounterValue("C", cNeighborsCounterId, 2);
        awaitCounterValue("D", dNeighborsCounterId, 2);
        awaitCounterLabel("D", dNeighborsCounterId, "Resolver neighbors: bound 0.0.0.0:8053 bootstrap 127.0.0.1:8051");
    } finally {
        DriverNameResolver.bootstrapNameResolver = bootstrapResolver;
    }
}
Also used : TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MutableBoolean(org.agrona.collections.MutableBoolean) Test(org.junit.jupiter.api.Test)

Example 19 with MutableBoolean

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

the class ArchiveToolTests method assertRecording.

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

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

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