Search in sources :

Example 6 with MutableBoolean

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

the class ClusterTest method shouldRejectTakeSnapshotRequestWithAnAuthorisationError.

@Test
@InterruptAfter(10)
void shouldRejectTakeSnapshotRequestWithAnAuthorisationError() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final List<TestNode> followers = cluster.followers();
    final long requestCorrelationId = System.nanoTime();
    final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.UNAUTHORISED_ACCESS, "Execution of the " + AdminRequestType.SNAPSHOT + " request was not authorised");
    final AeronCluster client = cluster.connectClient();
    while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
        Tests.yield();
    }
    while (!responseReceived.get()) {
        client.pollEgress();
        Tests.yield();
    }
    long time = System.nanoTime();
    final long deadline = time + TimeUnit.SECONDS.toNanos(2);
    do {
        assertEquals(0, cluster.getSnapshotCount(leader));
        for (final TestNode follower : followers) {
            assertEquals(0, cluster.getSnapshotCount(follower));
        }
        Tests.sleep(10);
        time = System.nanoTime();
    } while (time < deadline);
}
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 7 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)

Example 8 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 9 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 10 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)

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