use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterNodeTest method shouldEchoMessageViaServiceUsingDirectOffer.
@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingDirectOffer() {
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
final MutableInteger messageCount = new MutableInteger();
final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchEchoService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterNodeTest method shouldEchoMessageViaServiceUsingTryClaim.
@Test
@InterruptAfter(10)
public void shouldEchoMessageViaServiceUsingTryClaim() {
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
final MutableInteger messageCount = new MutableInteger();
final EgressListener listener = (clusterSessionId, timestamp, buffer, offset, length, header) -> {
assertEquals(msg, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchEchoService();
aeronCluster = connectToCluster(listener);
final BufferClaim bufferClaim = new BufferClaim();
long publicationResult;
do {
publicationResult = aeronCluster.tryClaim(msg.length(), bufferClaim);
if (publicationResult > 0) {
final int offset = bufferClaim.offset() + AeronCluster.SESSION_HEADER_LENGTH;
bufferClaim.buffer().putBytes(offset, msgBuffer, 0, msg.length());
bufferClaim.commit();
} else {
Tests.yield();
}
} while (publicationResult < 0);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot.
@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshot() {
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> AuthorisationService.ALLOW_ALL).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
cluster.awaitSnapshotCount(1);
cluster.awaitNeutralControlToggle(leader);
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTest method shouldCloseClientOnTimeout.
@Test
@InterruptAfter(20)
public void shouldCloseClientOnTimeout() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final AeronCluster client = cluster.connectClient();
final ConsensusModule.Context context = leader.consensusModule().context();
assertEquals(0, context.timedOutClientCounter().get());
assertFalse(client.isClosed());
Tests.sleep(NANOSECONDS.toMillis(context.sessionTimeoutNs()));
cluster.shouldErrorOnClientClose(false);
while (!client.isClosed()) {
Tests.sleep(1);
client.pollEgress();
}
assertEquals(1, context.timedOutClientCounter().get());
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class MultiModuleSharedDriverTest method shouldSupportTwoMultiNodeClusters.
@Test
@InterruptAfter(30)
public void shouldSupportTwoMultiNodeClusters() {
try (MultiClusterNode node0 = new MultiClusterNode(0, systemTestWatcher.dataCollector());
MultiClusterNode node1 = new MultiClusterNode(1, systemTestWatcher.dataCollector())) {
final MutableReference<String> egress = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
try (AeronCluster client0 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node0.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(0, 2)).egressChannel("aeron:udp?endpoint=localhost:9020"));
AeronCluster client1 = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(node1.archivingMediaDriver.mediaDriver().aeronDirectoryName()).egressListener(egressListener).ingressChannel("aeron:udp?term-length=64k").ingressEndpoints(TestCluster.ingressEndpoints(1, 2)).egressChannel("aeron:udp?endpoint=localhost:9120"))) {
echoMessage(client0, "Message 0", egress);
echoMessage(client1, "Message 1", egress);
}
}
}
Aggregations