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