use of io.aeron.protocol.DataHeaderFlyweight in project aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailurePageStraddle.
@Test
public void shouldFixTimestampAndPositionAfterFailurePageStraddle() throws Exception {
final long newRecordingId = newRecording();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 0));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = ByteBuffer.allocateDirect(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(PAGE_SIZE - 32);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, PAGE_SIZE - 32);
bb.clear();
flyweight.frameLength(0);
log.write(bb, PAGE_SIZE - 32 + 128);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
catalog.forEntry((he, hd, e, decoder) -> {
assertThat(decoder.stopTimestamp(), is(NULL_TIMESTAMP));
assertThat(decoder.stopPosition(), is(NULL_POSITION));
}, newRecordingId);
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, MAX_ENTRIES, clock)) {
assertTrue(catalog.forEntry((he, hd, e, decoder) -> {
assertThat(decoder.stopTimestamp(), is(42L));
assertThat(decoder.stopPosition(), is((long) PAGE_SIZE - 32));
}, newRecordingId));
}
}
use of io.aeron.protocol.DataHeaderFlyweight in project aeron by real-logic.
the class RecordingSessionTest method before.
@Before
public void before() throws Exception {
when(mockPosition.getWeak()).then((invocation) -> positionLong);
when(mockPosition.get()).then((invocation) -> positionLong);
doAnswer((invocation) -> {
positionLong = invocation.getArgument(0);
return null;
}).when(mockPosition).setOrdered(anyLong());
termFile = File.createTempFile("test.rec", "sourceIdentity");
mockLogBufferChannel = FileChannel.open(termFile.toPath(), CREATE, READ, WRITE);
mockLogBufferMapped = new UnsafeBuffer(mockLogBufferChannel.map(FileChannel.MapMode.READ_WRITE, 0, TERM_BUFFER_LENGTH));
final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight();
headerFlyweight.wrap(mockLogBufferMapped, TERM_OFFSET, DataHeaderFlyweight.HEADER_LENGTH);
headerFlyweight.termOffset(TERM_OFFSET).sessionId(SESSION_ID).streamId(STREAM_ID).headerType(DataHeaderFlyweight.HDR_TYPE_DATA).frameLength(RECORDED_BLOCK_LENGTH);
context = new Archive.Context().segmentFileLength(SEGMENT_FILE_SIZE).archiveDir(archiveDir).catalog(mockCatalog).epochClock(epochClock);
}
use of io.aeron.protocol.DataHeaderFlyweight in project aeron by real-logic.
the class ReplaySessionTest method shouldReplayFromActiveRecording.
@Test
public void shouldReplayFromActiveRecording() {
final UnsafeBuffer termBuffer = new UnsafeBuffer(allocateDirectAligned(4096, 64));
final int recordingId = RECORDING_ID + 1;
recordingSummary.recordingId = recordingId;
recordingSummary.stopPosition = NULL_POSITION;
when(mockCatalog.stopPosition(recordingId)).thenReturn(START_POSITION + FRAME_LENGTH * 4);
position.setOrdered(START_POSITION);
final RecordingWriter writer = new RecordingWriter(recordingId, START_POSITION, JOIN_POSITION, TERM_BUFFER_LENGTH, context, ARCHIVE_DIR_CHANNEL, position);
when(epochClock.time()).thenReturn(TIME);
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);
final long length = 5 * FRAME_LENGTH;
final long correlationId = 1L;
final ReplaySession replaySession = replaySession(RECORDING_POSITION, length, correlationId, mockReplayPub, mockControlSession);
when(mockReplayPub.isClosed()).thenReturn(false);
when(mockReplayPub.isConnected()).thenReturn(false);
replaySession.doWork();
assertEquals(replaySession.state(), ReplaySession.State.INIT);
when(mockReplayPub.isConnected()).thenReturn(true);
replaySession.doWork();
assertEquals(replaySession.state(), ReplaySession.State.REPLAY);
verify(mockControlSession).sendOkResponse(eq(correlationId), anyLong(), eq(proxy));
mockPublication(mockReplayPub, termBuffer);
assertNotEquals(0, replaySession.doWork());
assertThat(messageCounter, is(2));
validateFrame(termBuffer, 0, FrameDescriptor.UNFRAGMENTED);
validateFrame(termBuffer, 1, FrameDescriptor.BEGIN_FRAG_FLAG);
assertEquals(0, replaySession.doWork());
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();
when(position.isClosed()).thenReturn(true);
when(mockCatalog.stopPosition(recordingId)).thenReturn(START_POSITION + FRAME_LENGTH * 4);
assertNotEquals(0, replaySession.doWork());
validateFrame(termBuffer, 2, FrameDescriptor.END_FRAG_FLAG);
verify(mockReplayPub).appendPadding(FRAME_LENGTH - HEADER_LENGTH);
assertTrue(replaySession.isDone());
replaySession.close();
}
use of io.aeron.protocol.DataHeaderFlyweight in project Aeron by real-logic.
the class ArchiveToolTests method writeToSegmentFile.
private void writeToSegmentFile(final File file, final int fileLength, final SegmentWriter segmentWriter) throws IOException {
final ByteBuffer byteBuffer = allocate(MTU_LENGTH);
final DataHeaderFlyweight dataHeaderFlyweight = new DataHeaderFlyweight(byteBuffer);
try (FileChannel channel = FileChannel.open(file.toPath(), READ, WRITE)) {
segmentWriter.write(byteBuffer, dataHeaderFlyweight, channel);
final long size = channel.size();
if (fileLength != size) {
channel.truncate(fileLength);
if (size < fileLength) {
byteBuffer.put(0, (byte) 0).limit(1).position(0);
channel.write(byteBuffer, fileLength - 1);
}
}
}
}
use of io.aeron.protocol.DataHeaderFlyweight in project Aeron by real-logic.
the class RecordingSessionTest method before.
@BeforeEach
public void before() throws Exception {
when(mockPosition.getWeak()).then((invocation) -> positionLong);
when(mockPosition.get()).then((invocation) -> positionLong);
doAnswer((invocation) -> {
positionLong = invocation.getArgument(0);
return null;
}).when(mockPosition).setOrdered(anyLong());
termFile = File.createTempFile("test.rec", "sourceIdentity");
mockLogBufferChannel = FileChannel.open(termFile.toPath(), CREATE, READ, WRITE);
mockLogBufferMapped = new UnsafeBuffer(mockLogBufferChannel.map(FileChannel.MapMode.READ_WRITE, 0, TERM_BUFFER_LENGTH));
final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight();
headerFlyweight.wrap(mockLogBufferMapped, TERM_OFFSET, DataHeaderFlyweight.HEADER_LENGTH);
headerFlyweight.termOffset(TERM_OFFSET).sessionId(SESSION_ID).streamId(STREAM_ID).headerType(DataHeaderFlyweight.HDR_TYPE_DATA).frameLength(RECORDED_BLOCK_LENGTH);
context = new Archive.Context().segmentFileLength(SEGMENT_LENGTH).archiveDir(archiveDir).epochClock(epochClock);
}
Aggregations