use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ReplaySessionTest method before.
@BeforeEach
public void before() throws IOException {
context = new Archive.Context().segmentFileLength(SEGMENT_LENGTH).archiveDir(archiveDir).epochClock(epochClock).countedErrorHandler(countedErrorHandler);
when(recordingPositionCounter.get()).then((invocation) -> recordingPosition);
when(mockControlSession.archiveConductor()).thenReturn(mockArchiveConductor);
when(mockArchiveConductor.catalog()).thenReturn(mockCatalog);
when(mockArchiveConductor.context()).thenReturn(context);
when(mockReplayPub.termBufferLength()).thenReturn(TERM_BUFFER_LENGTH);
when(mockReplayPub.positionBitsToShift()).thenReturn(LogBufferDescriptor.positionBitsToShift(TERM_BUFFER_LENGTH));
when(mockReplayPub.initialTermId()).thenReturn(INITIAL_TERM_ID);
when(mockReplayPub.availableWindow()).thenReturn((long) TERM_BUFFER_LENGTH / 2);
when(mockImage.termBufferLength()).thenReturn(TERM_BUFFER_LENGTH);
when(mockImage.joinPosition()).thenReturn(JOIN_POSITION);
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, SEGMENT_LENGTH, mockImage, context);
writer.init();
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, INITIAL_TERM_OFFSET, FRAME_LENGTH, 0, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, INITIAL_TERM_OFFSET + FRAME_LENGTH, FRAME_LENGTH, 1, BEGIN_FRAG_FLAG, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, INITIAL_TERM_OFFSET + FRAME_LENGTH * 2, FRAME_LENGTH, 2, END_FRAG_FLAG, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, INITIAL_TERM_OFFSET + FRAME_LENGTH * 3, FRAME_LENGTH, 3, UNFRAGMENTED, HDR_TYPE_PAD, SESSION_ID);
writer.close();
recordingSummary.stopPosition = START_POSITION + 4 * FRAME_LENGTH;
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ReplaySessionTest method shouldDoCrcForEachDataFrame.
@Test
public void shouldDoCrcForEachDataFrame() throws IOException {
context.recordChecksum(crc32());
context.recordChecksumBuffer(new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_BUFFER_LENGTH)));
final RecordingWriter writer = new RecordingWriter(RECORDING_ID, START_POSITION, SEGMENT_LENGTH, mockImage, context);
writer.init();
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, FRAME_LENGTH, 10, UNFRAGMENTED, HDR_TYPE_DATA, checksum(FRAME_LENGTH, 10));
recordFragment(writer, buffer, headerFwt, header, FRAME_LENGTH, FRAME_LENGTH, 20, BEGIN_FRAG_FLAG, HDR_TYPE_DATA, checksum(FRAME_LENGTH, 20));
recordFragment(writer, buffer, headerFwt, header, FRAME_LENGTH * 2, FRAME_LENGTH, 30, END_FRAG_FLAG, HDR_TYPE_DATA, checksum(FRAME_LENGTH, 30));
recordFragment(writer, buffer, headerFwt, header, FRAME_LENGTH * 3, FRAME_LENGTH, 40, UNFRAGMENTED, HDR_TYPE_PAD, SESSION_ID);
writer.close();
final long length = 4 * FRAME_LENGTH;
final long correlationId = 1L;
final int sessionId = Integer.MIN_VALUE;
final int streamId = Integer.MAX_VALUE;
try (ReplaySession replaySession = replaySession(RECORDING_POSITION, length, correlationId, mockReplayPub, mockControlSession, null, context.recordChecksum())) {
when(mockReplayPub.isClosed()).thenReturn(false);
when(mockReplayPub.isConnected()).thenReturn(false);
when(mockReplayPub.sessionId()).thenReturn(sessionId);
when(mockReplayPub.streamId()).thenReturn(streamId);
replaySession.doWork();
assertEquals(replaySession.state(), ReplaySession.State.INIT);
when(mockReplayPub.isConnected()).thenReturn(true);
final UnsafeBuffer termBuffer = new UnsafeBuffer(allocateDirectAligned(4096, 64));
mockPublication(mockReplayPub, termBuffer);
assertNotEquals(0, replaySession.doWork());
assertThat(messageCounter, is(2));
validateFrame(termBuffer, 0, FRAME_LENGTH, 10, UNFRAGMENTED, sessionId, streamId);
validateFrame(termBuffer, FRAME_LENGTH, FRAME_LENGTH, 20, BEGIN_FRAG_FLAG, sessionId, streamId);
validateFrame(termBuffer, 2 * FRAME_LENGTH, FRAME_LENGTH, 30, END_FRAG_FLAG, sessionId, streamId);
verify(mockReplayPub).appendPadding(FRAME_LENGTH - HEADER_LENGTH);
assertTrue(replaySession.isDone());
}
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ReplaySessionTest method shouldCalculateBlockSizeBasedOnFullFragments.
@Test
public void shouldCalculateBlockSizeBasedOnFullFragments() throws IOException {
context.recordChecksumBuffer(new UnsafeBuffer(ByteBuffer.allocateDirect(TERM_BUFFER_LENGTH)));
final RecordingWriter writer = new RecordingWriter(RECORDING_ID, START_POSITION, SEGMENT_LENGTH, mockImage, context);
writer.init();
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, 100, 11, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, 128, 200, 22, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, 352, 300, 33, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, 672, 400, 44, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, 1088, 500, 55, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
recordFragment(writer, buffer, headerFwt, header, 1600, 6000, 66, UNFRAGMENTED, HDR_TYPE_DATA, SESSION_ID);
writer.close();
final int sessionId = 555;
final int streamId = 777;
try (ReplaySession replaySession = replaySession(RECORDING_POSITION, 1_000_000, -1, mockReplayPub, mockControlSession, null, null)) {
when(mockReplayPub.isClosed()).thenReturn(false);
when(mockReplayPub.isConnected()).thenReturn(false);
when(mockReplayPub.sessionId()).thenReturn(sessionId);
when(mockReplayPub.streamId()).thenReturn(streamId);
replaySession.doWork();
assertEquals(replaySession.state(), ReplaySession.State.INIT);
when(mockReplayPub.isConnected()).thenReturn(true);
final UnsafeBuffer termBuffer = new UnsafeBuffer(allocateDirectAligned(4096, 64));
mockPublication(mockReplayPub, termBuffer);
assertEquals(2, replaySession.doWork());
assertThat(messageCounter, is(1));
validateFrame(termBuffer, 0, 100, 11, UNFRAGMENTED, sessionId, streamId);
validateFrame(termBuffer, 128, 200, 22, UNFRAGMENTED, sessionId, streamId);
validateFrame(termBuffer, 352, 300, 33, UNFRAGMENTED, sessionId, streamId);
validateFrame(termBuffer, 672, 400, 44, UNFRAGMENTED, sessionId, streamId);
validateFrame(termBuffer, 1088, 500, 55, UNFRAGMENTED, sessionId, streamId);
verify(mockReplayPub, never()).appendPadding(anyInt());
}
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ClusterNodeTest method shouldScheduleEventInService.
@Test
@InterruptAfter(10)
public void shouldScheduleEventInService() {
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) -> {
final String expected = msg + "-scheduled";
assertEquals(expected, buffer.getStringWithoutLengthAscii(offset, length));
messageCount.value += 1;
};
container = launchTimedService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
use of io.aeron.logbuffer.Header in project aeron by real-logic.
the class ClusterNodeTest method shouldSendResponseAfterServiceMessage.
@Test
@InterruptAfter(10)
public void shouldSendResponseAfterServiceMessage() {
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 = launchServiceMessageIngressService();
aeronCluster = connectToCluster(listener);
offerMessage(msgBuffer, msg);
awaitResponse(messageCount);
ClusterTests.failOnClusterError();
}
Aggregations