Search in sources :

Example 1 with SessionDecorator

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

the class AuthenticationTest method connectClient.

private void connectClient(final CredentialsSupplier credentialsSupplier) {
    aeronCluster = null;
    aeronCluster = connectToCluster(credentialsSupplier);
    sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    publication = aeronCluster.ingressPublication();
}
Also used : SessionDecorator(io.aeron.cluster.client.SessionDecorator)

Example 2 with SessionDecorator

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

the class ClusterNodeTest method shouldScheduleEventInService.

@Test(timeout = 10_000)
public void shouldScheduleEventInService() {
    container = launchTimedService();
    aeronCluster = connectToCluster();
    final Aeron aeron = aeronCluster.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    final Publication publication = aeronCluster.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
        TestUtil.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger messageCount = new MutableInteger();
    final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {

        public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertThat(correlationId, is(msgCorrelationId));
            assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg + "-scheduled"));
            messageCount.value += 1;
        }
    }, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
    while (messageCount.get() == 0) {
        if (adapter.poll() <= 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Example 3 with SessionDecorator

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

the class ClusterNodeTest method shouldEchoMessageViaService.

@Test(timeout = 10_000)
public void shouldEchoMessageViaService() {
    container = launchEchoService();
    aeronCluster = connectToCluster();
    final Aeron aeron = aeronCluster.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    final Publication publication = aeronCluster.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
        TestUtil.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger messageCount = new MutableInteger();
    final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {

        public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertThat(correlationId, is(msgCorrelationId));
            assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg));
            messageCount.value += 1;
        }
    }, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
    while (messageCount.get() == 0) {
        if (adapter.poll() <= 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Example 4 with SessionDecorator

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

the class ConsensusModuleHarness method makeRecordingLog.

public static long makeRecordingLog(final int numMessages, final int maxMessageLength, final Random random, final ConsensusModule.Context context) {
    try (ConsensusModuleHarness harness = new ConsensusModuleHarness(context, new StubClusteredService(), null, true, false)) {
        harness.awaitServiceOnStart();
        final AeronCluster aeronCluster = AeronCluster.connect(new AeronCluster.Context().lock(new NoOpLock()));
        final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
        final Publication publication = aeronCluster.ingressPublication();
        final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer(maxMessageLength);
        for (int i = 0; i < numMessages; i++) {
            final long messageCorrelationId = aeronCluster.context().aeron().nextCorrelationId();
            final int length = (null == random) ? maxMessageLength : random.nextInt(maxMessageLength);
            msgBuffer.putInt(0, i);
            while (true) {
                final long result = sessionDecorator.offer(publication, messageCorrelationId, msgBuffer, 0, length);
                if (result > 0) {
                    break;
                }
                checkOfferResult(result);
                TestUtil.checkInterruptedStatus();
                Thread.yield();
            }
        }
        harness.awaitServiceOnMessageCounter(numMessages);
        return publication.position();
    }
}
Also used : NoOpLock(org.agrona.concurrent.NoOpLock) AeronCluster(io.aeron.cluster.client.AeronCluster) SessionDecorator(io.aeron.cluster.client.SessionDecorator) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 5 with SessionDecorator

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

the class ClusterNodeRestartTest method connectClient.

private void connectClient() {
    aeronCluster = null;
    aeronCluster = connectToCluster();
    sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    publication = aeronCluster.ingressPublication();
}
Also used : SessionDecorator(io.aeron.cluster.client.SessionDecorator)

Aggregations

SessionDecorator (io.aeron.cluster.client.SessionDecorator)6 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)4 Aeron (io.aeron.Aeron)3 Publication (io.aeron.Publication)3 EgressAdapter (io.aeron.cluster.client.EgressAdapter)2 Header (io.aeron.logbuffer.Header)2 DirectBuffer (org.agrona.DirectBuffer)2 MutableInteger (org.agrona.collections.MutableInteger)2 Test (org.junit.Test)2 AeronCluster (io.aeron.cluster.client.AeronCluster)1 NoOpLock (org.agrona.concurrent.NoOpLock)1