use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTest method shouldRejectAnInvalidAdminRequest.
@Test
@InterruptAfter(10)
void shouldRejectAnInvalidAdminRequest() {
final AdminRequestType invalidRequestType = AdminRequestType.NULL_VAL;
final AtomicBoolean authorisationServiceCalled = new AtomicBoolean();
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
authorisationServiceCalled.set(true);
assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
assertEquals(invalidRequestType, type);
return true;
}).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, invalidRequestType, AdminResponseCode.ERROR, "Unknown request type: " + invalidRequestType);
final AeronCluster client = cluster.connectClient();
final AdminRequestEncoder adminRequestEncoder = new AdminRequestEncoder().wrapAndApplyHeader(cluster.msgBuffer(), 0, new MessageHeaderEncoder()).leadershipTermId(client.leadershipTermId()).clusterSessionId(client.clusterSessionId()).correlationId(requestCorrelationId).requestType(invalidRequestType);
final Publication ingressPublication = client.ingressPublication();
while (ingressPublication.offer(adminRequestEncoder.buffer(), 0, MessageHeaderEncoder.ENCODED_LENGTH + adminRequestEncoder.encodedLength()) < 0) {
Tests.yield();
}
Tests.await(authorisationServiceCalled::get);
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll.
@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll() {
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
assertEquals(AdminRequestType.SNAPSHOT, type);
return true;
}).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminRequestControlledEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.controlledPollEgress();
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 shouldRejectAnAdminRequestIfLeadershipTermIsInvalid.
@Test
@InterruptAfter(10)
void shouldRejectAnAdminRequestIfLeadershipTermIsInvalid() {
cluster = aCluster().withStaticNodes(3).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
AeronCluster client = cluster.connectClient();
final long requestCorrelationId = System.nanoTime();
final long expectedLeadershipTermId = client.leadershipTermId();
final long invalidLeadershipTermId = expectedLeadershipTermId - 1000;
final AdminRequestType requestType = AdminRequestType.NULL_VAL;
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, requestType, AdminResponseCode.ERROR, "Invalid leadership term: expected " + expectedLeadershipTermId + ", got " + invalidLeadershipTermId);
client = cluster.connectClient();
final AdminRequestEncoder adminRequestEncoder = new AdminRequestEncoder().wrapAndApplyHeader(cluster.msgBuffer(), 0, new MessageHeaderEncoder()).leadershipTermId(invalidLeadershipTermId).clusterSessionId(client.clusterSessionId()).correlationId(requestCorrelationId).requestType(requestType);
final Publication ingressPublication = client.ingressPublication();
while (ingressPublication.offer(adminRequestEncoder.buffer(), 0, MessageHeaderEncoder.ENCODED_LENGTH + adminRequestEncoder.encodedLength()) < 0) {
Tests.yield();
}
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
}
use of io.aeron.cluster.client.AeronCluster in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test
@InterruptAfter(10)
public void shouldScheduleEventInService() {
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) -> {
final String expected = msg + "-scheduled";
assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchTimedService();
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 shouldSendResponseAfterServiceMessage.
@Test
@InterruptAfter(10)
public void shouldSendResponseAfterServiceMessage() {
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 = launchServiceMessageIngressService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
Aggregations