Search in sources :

Example 16 with Header

use of io.aeron.logbuffer.Header in project Aeron by real-logic.

the class ClusterTest method injectAdminResponseEgressListener.

private MutableBoolean injectAdminResponseEgressListener(final long expectedCorrelationId, final AdminRequestType expectedRequestType, final AdminResponseCode expectedResponseCode, final String expectedMessage) {
    final MutableBoolean responseReceived = new MutableBoolean();
    cluster.egressListener(new EgressListener() {

        public void onMessage(final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
        }

        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) EgressListener(io.aeron.cluster.client.EgressListener)

Example 17 with Header

use of io.aeron.logbuffer.Header 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)

Example 18 with Header

use of io.aeron.logbuffer.Header in project aeron by real-logic.

the class AuthenticationTest method launchService.

private void launchService(final MutableLong sessionId, final MutableReference<byte[]> encodedPrincipal, final AtomicLong msgCounter) {
    final ClusteredService service = new StubClusteredService() {

        private int counterValue = 0;

        public void onSessionOpen(final ClientSession session, final long timestamp) {
            sessionId.value = session.id();
            encodedPrincipal.set(session.encodedPrincipal());
        }

        public void onSessionMessage(final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertEquals(counterValue, buffer.getInt(offset));
            msgCounter.getAndIncrement();
            counterValue++;
        }
    };
    container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(ClusterTests.NOOP_TERMINATION_HOOK).errorHandler(ClusterTests.errorHandler(0)));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredService(io.aeron.cluster.service.ClusteredService) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 19 with Header

use of io.aeron.logbuffer.Header in project aeron by real-logic.

the class EgressAdapterTest method onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionMessage.

@Test
void onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionMessage() {
    final int offset = 18;
    final long sessionId = 21;
    final long timestamp = 1000;
    sessionMessageHeaderEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).clusterSessionId(sessionId).timestamp(timestamp);
    final EgressListener egressListener = mock(EgressListener.class);
    final Header header = new Header(0, 0);
    final EgressAdapter adapter = new EgressAdapter(egressListener, -19, mock(Subscription.class), 3);
    adapter.onFragment(buffer, offset, sessionMessageHeaderEncoder.encodedLength(), header);
    verifyNoInteractions(egressListener);
}
Also used : Header(io.aeron.logbuffer.Header) Subscription(io.aeron.Subscription) Test(org.junit.jupiter.api.Test)

Example 20 with Header

use of io.aeron.logbuffer.Header in project aeron by real-logic.

the class EgressAdapterTest method onFragmentShouldInvokeOnAdminResponseCallbackIfSessionIdMatches.

@Test
void onFragmentShouldInvokeOnAdminResponseCallbackIfSessionIdMatches() {
    final int offset = 24;
    final long clusterSessionId = 18;
    final long correlationId = 3274239749237498239L;
    final AdminRequestType type = AdminRequestType.SNAPSHOT;
    final AdminResponseCode responseCode = AdminResponseCode.UNAUTHORISED_ACCESS;
    final String message = "Unauthorised access detected!";
    final byte[] payload = new byte[] { 0x1, 0x2, 0x3 };
    adminResponseEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).clusterSessionId(clusterSessionId).correlationId(correlationId).requestType(type).responseCode(responseCode).message(message);
    adminResponseEncoder.putPayload(payload, 0, payload.length);
    final EgressListener egressListener = mock(EgressListener.class);
    final Header header = new Header(1, 3);
    final EgressAdapter adapter = new EgressAdapter(egressListener, clusterSessionId, mock(Subscription.class), 10);
    adapter.onFragment(buffer, offset, adminResponseEncoder.encodedLength(), header);
    verify(egressListener).onAdminResponse(clusterSessionId, correlationId, type, responseCode, message, buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH + adminResponseEncoder.encodedLength() - payload.length, payload.length);
    verifyNoMoreInteractions(egressListener);
}
Also used : Header(io.aeron.logbuffer.Header) Subscription(io.aeron.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

Header (io.aeron.logbuffer.Header)63 Test (org.junit.jupiter.api.Test)44 DirectBuffer (org.agrona.DirectBuffer)33 ClientSession (io.aeron.cluster.service.ClientSession)21 StubClusteredService (io.aeron.test.cluster.StubClusteredService)20 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)20 ClusteredService (io.aeron.cluster.service.ClusteredService)18 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)18 MediaDriver (io.aeron.driver.MediaDriver)18 CloseHelper (org.agrona.CloseHelper)17 Subscription (io.aeron.Subscription)16 Archive (io.aeron.archive.Archive)16 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)16 AeronCluster (io.aeron.cluster.client.AeronCluster)16 ThreadingMode (io.aeron.driver.ThreadingMode)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)15 EgressListener (io.aeron.cluster.client.EgressListener)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 CLUSTER_MEMBERS (io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS)12