use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ReplaySessionTest method before.
@Before
public void before() {
when(position.getWeak()).then((invocation) -> positionLong);
when(position.get()).then((invocation) -> positionLong);
when(mockArchiveConductor.catalog()).thenReturn(mockCatalog);
doAnswer((invocation) -> {
positionLong = invocation.getArgument(0);
return null;
}).when(position).setOrdered(anyLong());
doAnswer((invocation) -> {
final long delta = invocation.getArgument(0);
positionLong += delta;
return null;
}).when(position).getAndAddOrdered(anyLong());
context = new Archive.Context().archiveDir(archiveDir).epochClock(epochClock);
recordingSummary.recordingId = RECORDING_ID;
recordingSummary.startPosition = START_POSITION;
recordingSummary.segmentFileLength = context.segmentFileLength();
recordingSummary.initialTermId = INITIAL_TERM_ID;
recordingSummary.termBufferLength = TERM_BUFFER_LENGTH;
recordingSummary.mtuLength = MTU_LENGTH;
recordingSummary.streamId = STREAM_ID;
recordingSummary.sessionId = SESSION_ID;
final RecordingWriter writer = new RecordingWriter(RECORDING_ID, START_POSITION, JOIN_POSITION, TERM_BUFFER_LENGTH, context, ARCHIVE_DIR_CHANNEL, position);
final UnsafeBuffer buffer = new UnsafeBuffer(allocateDirectAligned(TERM_BUFFER_LENGTH, 64));
final DataHeaderFlyweight headerFwt = new DataHeaderFlyweight();
final Header header = new Header(INITIAL_TERM_ID, Integer.numberOfLeadingZeros(TERM_BUFFER_LENGTH));
header.buffer(buffer);
recordFragment(writer, buffer, headerFwt, header, 0, FrameDescriptor.UNFRAGMENTED, HDR_TYPE_DATA);
recordFragment(writer, buffer, headerFwt, header, 1, FrameDescriptor.BEGIN_FRAG_FLAG, HDR_TYPE_DATA);
recordFragment(writer, buffer, headerFwt, header, 2, FrameDescriptor.END_FRAG_FLAG, HDR_TYPE_DATA);
recordFragment(writer, buffer, headerFwt, header, 3, FrameDescriptor.UNFRAGMENTED, HDR_TYPE_PAD);
writer.close();
recordingSummary.stopPosition = START_POSITION + 4 * FRAME_LENGTH;
}
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++) {
assertThat("same at i=" + i, capturedBuffer.getByte(i), is(srcBuffer.getByte(i)));
}
final Header capturedHeader = headerArg.getValue();
assertThat(capturedHeader.sessionId(), is(SESSION_ID));
assertThat(capturedHeader.flags(), is(FrameDescriptor.END_FRAG_FLAG));
}
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 timestampMs) {
sessionId.value = session.id();
encodedPrincipal.set(session.encodedPrincipal());
}
public void onSessionMessage(final long clusterSessionId, final long correlationId, final long timestampMs, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(buffer.getInt(offset), is(counterValue));
msgCounter.getAndIncrement();
counterValue++;
}
};
container = null;
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test(timeout = 10_000)
public void shouldScheduleEventInService() {
container = launchTimedService();
aeronCluster = connectToCluster();
final Aeron aeron = aeronCluster.context().aeron();
final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
final Publication publication = aeronCluster.ingressPublication();
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final long msgCorrelationId = aeron.nextCorrelationId();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger messageCount = new MutableInteger();
final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {
public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(correlationId, is(msgCorrelationId));
assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg + "-scheduled"));
messageCount.value += 1;
}
}, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
while (messageCount.get() == 0) {
if (adapter.poll() <= 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ClusterNodeTest method shouldEchoMessageViaService.
@Test(timeout = 10_000)
public void shouldEchoMessageViaService() {
container = launchEchoService();
aeronCluster = connectToCluster();
final Aeron aeron = aeronCluster.context().aeron();
final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
final Publication publication = aeronCluster.ingressPublication();
final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
final long msgCorrelationId = aeron.nextCorrelationId();
final String msg = "Hello World!";
msgBuffer.putStringWithoutLengthAscii(0, msg);
while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
final MutableInteger messageCount = new MutableInteger();
final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {
public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
assertThat(correlationId, is(msgCorrelationId));
assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg));
messageCount.value += 1;
}
}, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
while (messageCount.get() == 0) {
if (adapter.poll() <= 0) {
TestUtil.checkInterruptedStatus();
Thread.yield();
}
}
}
Aggregations