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 onFragmentIsANoOpIfSessionIdDoesNotMatchOnNewLeader.
@Test
void onFragmentIsANoOpIfSessionIdDoesNotMatchOnNewLeader() {
final int offset = 0;
final long clusterSessionId = -100;
final long leadershipTermId = 6;
final int leaderMemberId = 9999;
final String ingressEndpoints = "ingress endpoints ...";
newLeaderEventEncoder.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder).leadershipTermId(leadershipTermId).clusterSessionId(clusterSessionId).leaderMemberId(leaderMemberId).ingressEndpoints(ingressEndpoints);
final EgressListener egressListener = mock(EgressListener.class);
final Header header = new Header(1, 3);
final EgressAdapter adapter = new EgressAdapter(egressListener, 0, mock(Subscription.class), 10);
adapter.onFragment(buffer, offset, newLeaderEventEncoder.encodedLength(), header);
verifyNoInteractions(egressListener);
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class SubscriptionTest method shouldReadData.
@Test
public void shouldReadData() {
subscription.addImage(imageOneMock);
when(imageOneMock.poll(any(FragmentHandler.class), anyInt())).then((invocation) -> {
final FragmentHandler handler = (FragmentHandler) invocation.getArguments()[0];
handler.onFragment(atomicReadBuffer, HEADER_LENGTH, READ_BUFFER_CAPACITY - HEADER_LENGTH, header);
return 1;
});
assertEquals(1, subscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT));
verify(fragmentHandler).onFragment(eq(atomicReadBuffer), eq(HEADER_LENGTH), eq(READ_BUFFER_CAPACITY - HEADER_LENGTH), any(Header.class));
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class FragmentAssemblerTest method shouldAssembleTwoPartMessage.
@Test
public void shouldAssembleTwoPartMessage() {
when(header.flags()).thenReturn(FrameDescriptor.BEGIN_FRAG_FLAG).thenReturn(FrameDescriptor.END_FRAG_FLAG);
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
final int offset = 0;
final int length = srcBuffer.capacity() / 2;
srcBuffer.setMemory(0, length, (byte) 65);
srcBuffer.setMemory(length, length, (byte) 66);
adapter.onFragment(srcBuffer, offset, length, header);
adapter.onFragment(srcBuffer, length, length, header);
final ArgumentCaptor<UnsafeBuffer> bufferArg = ArgumentCaptor.forClass(UnsafeBuffer.class);
final ArgumentCaptor<Header> headerArg = ArgumentCaptor.forClass(Header.class);
verify(delegateFragmentHandler, times(1)).onFragment(bufferArg.capture(), eq(offset), eq(length * 2), headerArg.capture());
final UnsafeBuffer capturedBuffer = bufferArg.getValue();
for (int i = 0; i < srcBuffer.capacity(); i++) {
assertEquals(srcBuffer.getByte(i), capturedBuffer.getByte(i), "same at i=" + i);
}
final Header capturedHeader = headerArg.getValue();
assertEquals(SESSION_ID, capturedHeader.sessionId());
assertEquals(FrameDescriptor.END_FRAG_FLAG, capturedHeader.flags());
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ClusterTest method injectAdminRequestControlledEgressListener.
private MutableBoolean injectAdminRequestControlledEgressListener(final long expectedCorrelationId, final AdminRequestType expectedRequestType, final AdminResponseCode expectedResponseCode, final String expectedMessage) {
final MutableBoolean responseReceived = new MutableBoolean();
cluster.controlledEgressListener(new ControlledEgressListener() {
public ControlledFragmentHandler.Action onMessage(final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
return ControlledFragmentHandler.Action.ABORT;
}
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;
}
Aggregations