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();
}
}
}
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();
}
}
}
Aggregations