use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class EgressAdapterTest method onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionEvent.
@Test
void onFragmentIsANoOpIfSessionIdDoesNotMatchOnSessionEvent() {
final int offset = 8;
final long clusterSessionId = 42;
final long correlationId = 777;
final long leadershipTermId = 6;
final int leaderMemberId = 3;
final EventCode eventCode = EventCode.REDIRECT;
final int version = 18;
final String eventDetail = "Event details";
sessionEventEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).clusterSessionId(clusterSessionId).correlationId(correlationId).leadershipTermId(leadershipTermId).leaderMemberId(leaderMemberId).code(eventCode).version(version).detail(eventDetail);
final EgressListener egressListener = mock(EgressListener.class);
final Header header = new Header(0, 0);
final EgressAdapter adapter = new EgressAdapter(egressListener, clusterSessionId + 1, mock(Subscription.class), 3);
adapter.onFragment(buffer, offset, sessionEventEncoder.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);
}
use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class ClusterNodeRestartTest method launchReschedulingService.
private void launchReschedulingService(final AtomicLong triggeredTimersCounter) {
final ClusteredService service = new StubClusteredService() {
public void onSessionMessage(final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
scheduleNext(serviceCorrelationId(7), timestamp + 200);
}
public void onTimerEvent(final long correlationId, final long timestamp) {
triggeredTimersCounter.getAndIncrement();
scheduleNext(correlationId, timestamp + 200);
}
public void onStart(final Cluster cluster, final Image snapshotImage) {
super.onStart(cluster, snapshotImage);
if (null != snapshotImage) {
final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> triggeredTimersCounter.set(buffer.getLong(offset));
while (true) {
final int fragments = snapshotImage.poll(fragmentHandler, 1);
if (fragments == 1 || snapshotImage.isEndOfStream()) {
break;
}
idleStrategy.idle();
}
}
}
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
buffer.putLong(0, triggeredTimersCounter.get());
while (snapshotPublication.offer(buffer, 0, SIZE_OF_INT) < 0) {
idleStrategy.idle();
}
}
private void scheduleNext(final long correlationId, final long deadline) {
idleStrategy.reset();
while (!cluster.scheduleTimer(correlationId, deadline)) {
idleStrategy.idle();
}
}
};
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 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.logbuffer.Header 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();
}
Aggregations