use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class FragmentAssemblerTest method shouldAssembleFourPartMessage.
@Test
public void shouldAssembleFourPartMessage() {
when(header.flags()).thenReturn(FrameDescriptor.BEGIN_FRAG_FLAG).thenReturn((byte) 0).thenReturn((byte) 0).thenReturn(FrameDescriptor.END_FRAG_FLAG);
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
final int offset = 0;
final int length = srcBuffer.capacity() / 4;
for (int i = 0; i < 4; i++) {
srcBuffer.setMemory(i * length, length, (byte) (65 + i));
}
adapter.onFragment(srcBuffer, offset, length, header);
adapter.onFragment(srcBuffer, offset + length, length, header);
adapter.onFragment(srcBuffer, offset + (length * 2), length, header);
adapter.onFragment(srcBuffer, offset + (length * 3), 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 * 4), 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 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 EgressAdapterTest method onFragmentShouldInvokeOnNewLeaderCallbackIfSessionIdMatches.
@Test
void onFragmentShouldInvokeOnNewLeaderCallbackIfSessionIdMatches() {
final int offset = 0;
final long clusterSessionId = 0;
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, clusterSessionId, mock(Subscription.class), 10);
adapter.onFragment(buffer, offset, newLeaderEventEncoder.encodedLength(), header);
verify(egressListener).onNewLeader(clusterSessionId, leadershipTermId, leaderMemberId, ingressEndpoints);
verifyNoMoreInteractions(egressListener);
}
use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class EgressAdapterTest method onFragmentIsANoOpIfSessionIdDoesNotMatchOnAdminResponse.
@Test
void onFragmentIsANoOpIfSessionIdDoesNotMatchOnAdminResponse() {
final int offset = 24;
final long clusterSessionId = 18;
final long correlationId = 3274239749237498239L;
final AdminRequestType type = AdminRequestType.SNAPSHOT;
final AdminResponseCode responseCode = AdminResponseCode.OK;
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);
verifyNoInteractions(egressListener);
}
use of io.aeron.logbuffer.Header in project Aeron by real-logic.
the class EgressAdapterTest method onFragmentShouldInvokeOnSessionEventCallbackIfSessionIdMatches.
@Test
void onFragmentShouldInvokeOnSessionEventCallbackIfSessionIdMatches() {
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(1, 3);
final EgressAdapter adapter = new EgressAdapter(egressListener, clusterSessionId, mock(Subscription.class), 10);
adapter.onFragment(buffer, offset, sessionEventEncoder.encodedLength(), header);
verify(egressListener).onSessionEvent(correlationId, clusterSessionId, leadershipTermId, leaderMemberId, eventCode, eventDetail);
verifyNoMoreInteractions(egressListener);
}
Aggregations