Search in sources :

Example 16 with AeronCluster

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

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

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

the class ClusterNodeTest method shouldScheduleEventInService.

@Test
@InterruptAfter(10)
public void shouldScheduleEventInService() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        final String expected = msg + "-scheduled";
        assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchTimedService();
    aeronCluster = connectToCluster(listener);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 20 with AeronCluster

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

the class ClusterNodeTest method shouldSendResponseAfterServiceMessage.

@Test
@InterruptAfter(10)
public void shouldSendResponseAfterServiceMessage() {
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    final MutableInteger messageCount = new MutableInteger();
    final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
        assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
        messageCount.value += 1;
    };
    container = launchServiceMessageIngressService();
    aeronCluster = connectToCluster(listener);
    offerMessage(msgBuffer, msg);
    awaitResponse(messageCount);
    ClusterTests.failOnClusterError();
}
Also used : ClusterTests(io.aeron.test.cluster.ClusterTests) AeronCluster(io.aeron.cluster.client.AeronCluster) Tests(io.aeron.test.Tests) BeforeEach(org.junit.jupiter.api.BeforeEach) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) CLUSTER_MEMBERS(io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS) ClusteredService(io.aeron.cluster.service.ClusteredService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BufferClaim(io.aeron.logbuffer.BufferClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) MutableInteger(org.agrona.collections.MutableInteger) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) INGRESS_ENDPOINTS(io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS) DirectBuffer(org.agrona.DirectBuffer) MutableInteger(org.agrona.collections.MutableInteger) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressListener(io.aeron.cluster.client.EgressListener) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

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