use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class ClusterTest method injectAdminResponseEgressListener.
private MutableBoolean injectAdminResponseEgressListener(final long expectedCorrelationId, final AdminRequestType expectedRequestType, final AdminResponseCode expectedResponseCode, final String expectedMessage) {
final MutableBoolean responseReceived = new MutableBoolean();
cluster.egressListener(new EgressListener() {
public void onMessage(final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
}
public void onAdminResponse(final long clusterSessionId, final long correlationId, final AdminRequestType requestType, final AdminResponseCode responseCode, final String message, final DirectBuffer payload, final int payloadOffset, final int payloadLength) {
responseReceived.set(true);
assertEquals(expectedCorrelationId, correlationId);
assertEquals(expectedRequestType, requestType);
assertEquals(expectedResponseCode, responseCode);
assertEquals(expectedMessage, message);
assertNotNull(payload);
final int minPayloadOffset = MessageHeaderEncoder.ENCODED_LENGTH + AdminResponseEncoder.BLOCK_LENGTH + AdminResponseEncoder.messageHeaderLength() + message.length() + AdminResponseEncoder.payloadHeaderLength();
assertTrue(payloadOffset > minPayloadOffset);
assertEquals(0, payloadLength);
}
});
return responseReceived;
}
use of io.aeron.logbuffer.Header 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);
}
}
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class AuthenticationTest method launchService.
private void launchService(final MutableLong sessionId, final MutableReference<byte[]> encodedPrincipal, final AtomicLong msgCounter) {
final ClusteredService service = new StubClusteredService() {
private int counterValue = 0;
public void onSessionOpen(final ClientSession session, final long timestamp) {
sessionId.value = session.id();
encodedPrincipal.set(session.encodedPrincipal());
}
public void onSessionMessage(final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertEquals(counterValue, buffer.getInt(offset));
msgCounter.getAndIncrement();
counterValue++;
}
};
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(ClusterTests.NOOP_TERMINATION_HOOK).errorHandler(ClusterTests.errorHandler(0)));
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class EgressAdapterTest method onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionMessage.
@Test
void onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionMessage() {
final int offset = 18;
final long sessionId = 21;
final long timestamp = 1000;
sessionMessageHeaderEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).clusterSessionId(sessionId).timestamp(timestamp);
final EgressListener egressListener = mock(EgressListener.class);
final Header header = new Header(0, 0);
final EgressAdapter adapter = new EgressAdapter(egressListener, -19, mock(Subscription.class), 3);
adapter.onFragment(buffer, offset, sessionMessageHeaderEncoder.encodedLength(), header);
verifyNoInteractions(egressListener);
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class EgressAdapterTest method onFragmentShouldInvokeOnAdminResponseCallbackIfSessionIdMatches.
@Test
void onFragmentShouldInvokeOnAdminResponseCallbackIfSessionIdMatches() {
final int offset = 24;
final long clusterSessionId = 18;
final long correlationId = 3274239749237498239L;
final AdminRequestType type = AdminRequestType.SNAPSHOT;
final AdminResponseCode responseCode = AdminResponseCode.UNAUTHORISED_ACCESS;
final String message = "Unauthorised access detected!";
final byte[] payload = new byte[] { 0x1, 0x2, 0x3 };
adminResponseEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).clusterSessionId(clusterSessionId).correlationId(correlationId).requestType(type).responseCode(responseCode).message(message);
adminResponseEncoder.putPayload(payload, 0, payload.length);
final EgressListener egressListener = mock(EgressListener.class);
final Header header = new Header(1, 3);
final EgressAdapter adapter = new EgressAdapter(egressListener, clusterSessionId, mock(Subscription.class), 10);
adapter.onFragment(buffer, offset, adminResponseEncoder.encodedLength(), header);
verify(egressListener).onAdminResponse(clusterSessionId, correlationId, type, responseCode, message, buffer, offset + MessageHeaderEncoder.ENCODED_LENGTH + adminResponseEncoder.encodedLength() - payload.length, payload.length);
verifyNoMoreInteractions(egressListener);
}
Aggregations