use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTests method startPublisherThread.
public static Thread startPublisherThread(final TestCluster testCluster, final MutableInteger messageCounter, final long backoffIntervalNs) {
final Thread thread = new Thread(() -> {
final IdleStrategy idleStrategy = YieldingIdleStrategy.INSTANCE;
final AeronCluster client = testCluster.client();
final ExpandableArrayBuffer msgBuffer = testCluster.msgBuffer();
msgBuffer.putStringWithoutLengthAscii(0, HELLO_WORLD_MSG);
while (!Thread.interrupted()) {
final long result = client.offer(msgBuffer, 0, HELLO_WORLD_MSG.length());
if (result > 0) {
messageCounter.increment();
} else {
if (Publication.CLOSED == result) {
break;
}
LockSupport.parkNanos(backoffIntervalNs);
}
idleStrategy.idle(client.pollEgress());
}
});
thread.setDaemon(true);
thread.setName("message-thread");
thread.start();
return thread;
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTest method shouldRejectTakeSnapshotRequestWithAnAuthorisationError.
@Test
@InterruptAfter(10)
void shouldRejectTakeSnapshotRequestWithAnAuthorisationError() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final List<TestNode> followers = cluster.followers();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.UNAUTHORISED_ACCESS, "Execution of the " + AdminRequestType.SNAPSHOT + " request was not authorised");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
long time = System.nanoTime();
final long deadline = time + TimeUnit.SECONDS.toNanos(2);
do {
assertEquals(0, cluster.getSnapshotCount(leader));
for (final TestNode follower : followers) {
assertEquals(0, cluster.getSnapshotCount(follower));
}
Tests.sleep(10);
time = System.nanoTime();
} while (time < deadline);
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterNetworkTopologyTest method connectAndSendMessages.
private void connectAndSendMessages(final String ingressChannel, final String ingressEndpoints, final Selector selector, final double messageCount) {
final String message = "Hello World!";
final MutableDirectBuffer messageBuffer = new UnsafeBuffer(ByteBuffer.allocate(128));
final int length = messageBuffer.putStringAscii(0, message);
final MutableReference<String> egressResponse = new MutableReference<>();
final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length1, header) -> {
final String stringAscii = buffer.getStringAscii(offset);
egressResponse.set(stringAscii);
};
try (MediaDriver mediaDriver = MediaDriver.launchEmbedded(new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirDeleteOnStart(true).dirDeleteOnShutdown(true));
AeronCluster.AsyncConnect asyncConnect = AeronCluster.asyncConnect(new AeronCluster.Context().messageTimeoutNs(TimeUnit.SECONDS.toNanos(CLUSTER_START_ELECTION_TIMEOUT_S * 2)).egressListener(egressListener).egressChannel("aeron:udp?endpoint=10.42.0.1:0").aeronDirectoryName(mediaDriver.aeronDirectoryName()).ingressChannel(ingressChannel).ingressEndpoints(ingressEndpoints));
AeronCluster aeronCluster = pollUntilConnected(asyncConnect, selector)) {
for (int i = 0; i < messageCount; i++) {
Tests.await(() -> {
final long position = aeronCluster.offer(messageBuffer, 0, length);
pollSelector(selector);
return 0 < position;
}, SECONDS.toNanos(5));
Tests.await(() -> {
aeronCluster.pollEgress();
pollSelector(selector);
return message.equals(egressResponse.get());
}, SECONDS.toNanos(5));
}
}
}
Aggregations