Search in sources :

Example 1 with EgressAdapter

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

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

Aggregations

Aeron (io.aeron.Aeron)2 Publication (io.aeron.Publication)2 EgressAdapter (io.aeron.cluster.client.EgressAdapter)2 SessionDecorator (io.aeron.cluster.client.SessionDecorator)2 Header (io.aeron.logbuffer.Header)2 DirectBuffer (org.agrona.DirectBuffer)2 ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)2 MutableInteger (org.agrona.collections.MutableInteger)2 Test (org.junit.Test)2