Search in sources :

Example 6 with AeronCluster

use of io.aeron.cluster.client.AeronCluster 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 AeronCluster

use of io.aeron.cluster.client.AeronCluster 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 AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class ClusterTest method shouldCloseClientOnTimeout.

@Test
@InterruptAfter(20)
public void shouldCloseClientOnTimeout() {
    cluster = aCluster().withStaticNodes(3).start();
    systemTestWatcher.cluster(cluster);
    final TestNode leader = cluster.awaitLeader();
    final AeronCluster client = cluster.connectClient();
    final ConsensusModule.Context context = leader.consensusModule().context();
    assertEquals(0, context.timedOutClientCounter().get());
    assertFalse(client.isClosed());
    Tests.sleep(NANOSECONDS.toMillis(context.sessionTimeoutNs()));
    cluster.shouldErrorOnClientClose(false);
    while (!client.isClosed()) {
        Tests.sleep(1);
        client.pollEgress();
    }
    assertEquals(1, context.timedOutClientCounter().get());
}
Also used : AeronCluster(io.aeron.cluster.client.AeronCluster) TestNode(io.aeron.test.cluster.TestNode) Test(org.junit.jupiter.api.Test)

Example 9 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class MultiClusteredServicesTest method shouldSupportMultipleServicesPerNode.

@Test
@InterruptAfter(20)
public void shouldSupportMultipleServicesPerNode() {
    final List<TestCluster.NodeContext> nodeContexts = new ArrayList<>();
    final List<TestCluster.ServiceContext> serviceContexts = new ArrayList<>();
    final List<ClusteredMediaDriver> clusteredMediaDrivers = new ArrayList<>();
    final List<ClusteredServiceContainer> clusteredServiceContainers = new ArrayList<>();
    nodeContexts.add(TestCluster.nodeContext(0, true));
    nodeContexts.add(TestCluster.nodeContext(1, true));
    nodeContexts.add(TestCluster.nodeContext(2, true));
    serviceContexts.add(TestCluster.serviceContext(0, 0, nodeContexts.get(0), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(0, 1, nodeContexts.get(0), ServiceB::new));
    serviceContexts.add(TestCluster.serviceContext(1, 0, nodeContexts.get(1), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(1, 1, nodeContexts.get(1), ServiceB::new));
    serviceContexts.add(TestCluster.serviceContext(2, 0, nodeContexts.get(2), ServiceA::new));
    serviceContexts.add(TestCluster.serviceContext(2, 1, nodeContexts.get(2), ServiceB::new));
    nodeContexts.forEach((context) -> {
        try {
            clusteredMediaDrivers.add(ClusteredMediaDriver.launch(context.mediaDriverCtx, context.archiveCtx, context.consensusModuleCtx));
        } finally {
            systemTestWatcher.dataCollector().add(context.mediaDriverCtx.aeronDirectory());
            systemTestWatcher.dataCollector().add(context.archiveCtx.archiveDir());
            systemTestWatcher.dataCollector().add(context.consensusModuleCtx.clusterDir());
        }
    });
    serviceContexts.forEach((context) -> {
        context.serviceContainerCtx.aeronDirectoryName(context.aeronCtx.aeronDirectoryName());
        try {
            clusteredServiceContainers.add(ClusteredServiceContainer.launch(context.serviceContainerCtx));
        } finally {
            systemTestWatcher.dataCollector().add(context.serviceContainerCtx.clusterDir());
        }
    });
    final String aeronDirName = CommonContext.getAeronDirectoryName();
    final MediaDriver clientMediaDriver = MediaDriver.launch(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).aeronDirectoryName(aeronDirName).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)));
    final AeronCluster client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName).ingressChannel(CommonContext.UDP_CHANNEL).ingressEndpoints(TestCluster.ingressEndpoints(0, 3)));
    try {
        final DirectBuffer buffer = new UnsafeBuffer(new byte[100]);
        while (client.offer(buffer, 0, 100) < 0) {
            Tests.yield();
        }
        Tests.awaitValue(serviceAMessageCount, 3);
        Tests.awaitValue(serviceBMessageCount, 3);
    } finally {
        CloseHelper.closeAll(client, clientMediaDriver);
        clusteredMediaDrivers.forEach((clusteredMediaDriver) -> clusteredMediaDriver.consensusModule().close());
        CloseHelper.closeAll(clusteredServiceContainers);
        CloseHelper.closeAll(clusteredMediaDrivers);
        clientMediaDriver.context().deleteDirectory();
    }
}
Also used : CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) ArrayList(java.util.ArrayList) DirectBuffer(org.agrona.DirectBuffer) MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) Test(org.junit.jupiter.api.Test)

Example 10 with AeronCluster

use of io.aeron.cluster.client.AeronCluster in project Aeron by real-logic.

the class MultiModuleSharedDriverTest method shouldSupportTwoMultiNodeClusters.

@Test
@InterruptAfter(30)
public void shouldSupportTwoMultiNodeClusters() {
    try (MultiClusterNode node0 = new MultiClusterNode(0, systemTestWatcher.dataCollector());
        MultiClusterNode node1 = new MultiClusterNode(1, systemTestWatcher.dataCollector())) {
        final MutableReference<String> egress = new MutableReference<>();
        final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
        try (AeronCluster client0 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node0.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(0, 2)).egressChannel("aeron:udp?endpoint=localhost:9020"));
            AeronCluster client1 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node1.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(1, 2)).egressChannel("aeron:udp?endpoint=localhost:9120"))) {
            echoMessage(client0, "Message 0", egress);
            echoMessage(client1, "Message 1", egress);
        }
    }
}
Also used : AeronCluster(io.aeron.cluster.client.AeronCluster) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) io.aeron.test(io.aeron.test) SystemUtil(org.agrona.SystemUtil) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) MutableReference(org.agrona.collections.MutableReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) CommonContext(io.aeron.CommonContext) File(java.io.File) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) TestCluster(io.aeron.test.cluster.TestCluster) DirectBuffer(org.agrona.DirectBuffer) CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) MutableReference(org.agrona.collections.MutableReference) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test)

Aggregations

AeronCluster (io.aeron.cluster.client.AeronCluster)38 Test (org.junit.jupiter.api.Test)30 MediaDriver (io.aeron.driver.MediaDriver)18 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)15 EgressListener (io.aeron.cluster.client.EgressListener)14 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)14 ThreadingMode (io.aeron.driver.ThreadingMode)14 DirectBuffer (org.agrona.DirectBuffer)14 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)14 Archive (io.aeron.archive.Archive)12 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)12 ClientSession (io.aeron.cluster.service.ClientSession)12 Header (io.aeron.logbuffer.Header)12 StubClusteredService (io.aeron.test.cluster.StubClusteredService)12 CloseHelper (org.agrona.CloseHelper)12 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)12 InterruptAfter (io.aeron.test.InterruptAfter)10 TestNode (io.aeron.test.cluster.TestNode)10 MutableBoolean (org.agrona.collections.MutableBoolean)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10