use of io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureFullSegment.
@Test
void shouldFixTimestampAndPositionAfterFailureFullSegment() 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 = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(SEGMENT_LENGTH - 128);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, SEGMENT_LENGTH - 128);
log.truncate(SEGMENT_LENGTH);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(NULL_TIMESTAMP));
assertThat(descriptorDecoder.stopPosition(), is(NULL_POSITION));
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(42L));
assertThat(descriptorDecoder.stopPosition(), is((long) SEGMENT_LENGTH));
}));
}
}
use of io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH in project aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureSamePage.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void shouldFixTimestampAndPositionAfterFailureSamePage() throws Exception {
final long newRecordingId = newRecording();
new File(archiveDir, segmentFileName(newRecordingId, 0)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, SEGMENT_LENGTH)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, 2 * SEGMENT_LENGTH)).createNewFile();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 3 * SEGMENT_LENGTH));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(1024);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, 1024);
bb.clear();
flyweight.frameLength(0);
log.write(bb, 1024 + 128);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(NULL_TIMESTAMP, descriptorDecoder.stopTimestamp());
assertEquals(NULL_POSITION, descriptorDecoder.stopPosition());
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(42L, descriptorDecoder.stopTimestamp());
assertEquals(SEGMENT_LENGTH * 3 + 1024L + 128L, descriptorDecoder.stopPosition());
}));
}
}
use of io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH in project aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureFullSegment.
@Test
void shouldFixTimestampAndPositionAfterFailureFullSegment() 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 = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(SEGMENT_LENGTH - 128);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, SEGMENT_LENGTH - 128);
log.truncate(SEGMENT_LENGTH);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(NULL_TIMESTAMP));
assertThat(descriptorDecoder.stopPosition(), is(NULL_POSITION));
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertThat(descriptorDecoder.stopTimestamp(), is(42L));
assertThat(descriptorDecoder.stopPosition(), is((long) SEGMENT_LENGTH));
}));
}
}
use of io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH 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.HEADER_LENGTH in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureSamePage.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void shouldFixTimestampAndPositionAfterFailureSamePage() throws Exception {
final long newRecordingId = newRecording();
new File(archiveDir, segmentFileName(newRecordingId, 0)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, SEGMENT_LENGTH)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, 2 * SEGMENT_LENGTH)).createNewFile();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 3 * SEGMENT_LENGTH));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(1024);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, 1024);
bb.clear();
flyweight.frameLength(0);
log.write(bb, 1024 + 128);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(NULL_TIMESTAMP, descriptorDecoder.stopTimestamp());
assertEquals(NULL_POSITION, descriptorDecoder.stopPosition());
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(42L, descriptorDecoder.stopTimestamp());
assertEquals(SEGMENT_LENGTH * 3 + 1024L + 128L, descriptorDecoder.stopPosition());
}));
}
}
Aggregations