Search in sources :

Example 6 with SessionDecorator

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

the class ClusterTest method shouldEchoMessagesViaService.

@Test(timeout = 10_000)
public void shouldEchoMessagesViaService() throws InterruptedException {
    final Aeron aeron = client.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(client.clusterSessionId());
    final Publication publication = client.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    msgBuffer.putStringWithoutLengthAscii(0, MSG);
    final EchoConsumer consumer = new EchoConsumer(client.egressSubscription());
    final Thread thread = new Thread(consumer);
    thread.setName("consumer");
    thread.setDaemon(true);
    thread.start();
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, MSG.length()) < 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
    latch.await();
    for (final EchoService service : echoServices) {
        assertThat(service.messageCount(), is(MESSAGE_COUNT));
    }
}
Also used : Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

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