use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testTruncateFullyToLatestSnapshot.
@Test
public void testTruncateFullyToLatestSnapshot() throws IOException {
int numberOfRecords = 10;
int epoch = 0;
OffsetAndEpoch sameEpochSnapshotId = new OffsetAndEpoch(2 * numberOfRecords, epoch);
appendBatch(numberOfRecords, epoch);
try (RawSnapshotWriter snapshot = log.storeSnapshot(sameEpochSnapshotId).get()) {
snapshot.freeze();
}
assertTrue(log.truncateToLatestSnapshot());
assertEquals(sameEpochSnapshotId.offset, log.startOffset());
assertEquals(sameEpochSnapshotId.epoch, log.lastFetchedEpoch());
assertEquals(sameEpochSnapshotId.offset, log.endOffset().offset);
assertEquals(sameEpochSnapshotId.offset, log.highWatermark().offset);
OffsetAndEpoch greaterEpochSnapshotId = new OffsetAndEpoch(3 * numberOfRecords, epoch + 1);
appendBatch(numberOfRecords, epoch);
try (RawSnapshotWriter snapshot = log.storeSnapshot(greaterEpochSnapshotId).get()) {
snapshot.freeze();
}
assertTrue(log.truncateToLatestSnapshot());
assertEquals(greaterEpochSnapshotId.offset, log.startOffset());
assertEquals(greaterEpochSnapshotId.epoch, log.lastFetchedEpoch());
assertEquals(greaterEpochSnapshotId.offset, log.endOffset().offset);
assertEquals(greaterEpochSnapshotId.offset, log.highWatermark().offset);
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testCreateSnapshotBeforeLogStartOffset.
@Test
public void testCreateSnapshotBeforeLogStartOffset() {
int numberOfRecords = 10;
int epoch = 1;
OffsetAndEpoch snapshotId = new OffsetAndEpoch(numberOfRecords, epoch);
appendBatch(numberOfRecords, epoch);
log.updateHighWatermark(new LogOffsetMetadata(numberOfRecords));
try (RawSnapshotWriter snapshot = log.createNewSnapshot(snapshotId).get()) {
snapshot.freeze();
}
assertTrue(log.deleteBeforeSnapshot(snapshotId));
assertEquals(snapshotId.offset, log.startOffset());
assertEquals(Optional.empty(), log.createNewSnapshot(new OffsetAndEpoch(numberOfRecords - 1, epoch)));
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testValidateOffsetEqualToOldestSnapshotOffset.
@Test
public void testValidateOffsetEqualToOldestSnapshotOffset() throws IOException {
int offset = 2;
int epoch = 1;
OffsetAndEpoch olderEpochSnapshotId = new OffsetAndEpoch(offset, epoch);
try (RawSnapshotWriter snapshot = log.storeSnapshot(olderEpochSnapshotId).get()) {
snapshot.freeze();
}
log.truncateToLatestSnapshot();
ValidOffsetAndEpoch resultOffsetAndEpoch = log.validateOffsetAndEpoch(offset, epoch);
assertEquals(ValidOffsetAndEpoch.Kind.VALID, resultOffsetAndEpoch.kind());
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testReadOutOfRangeOffset.
@Test
public void testReadOutOfRangeOffset() throws IOException {
final long initialOffset = 5L;
final int epoch = 3;
SimpleRecord recordFoo = new SimpleRecord("foo".getBytes());
try (RawSnapshotWriter snapshot = log.storeSnapshot(new OffsetAndEpoch(initialOffset, 0)).get()) {
snapshot.freeze();
}
log.truncateToLatestSnapshot();
log.appendAsFollower(MemoryRecords.withRecords(initialOffset, CompressionType.NONE, epoch, recordFoo));
assertThrows(OffsetOutOfRangeException.class, () -> log.read(log.startOffset() - 1, Isolation.UNCOMMITTED));
assertThrows(OffsetOutOfRangeException.class, () -> log.read(log.endOffset().offset + 1, Isolation.UNCOMMITTED));
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testCreateSnapshot.
@Test
public void testCreateSnapshot() throws IOException {
int numberOfRecords = 10;
int epoch = 0;
OffsetAndEpoch snapshotId = new OffsetAndEpoch(numberOfRecords, epoch);
appendBatch(numberOfRecords, epoch);
log.updateHighWatermark(new LogOffsetMetadata(numberOfRecords));
try (RawSnapshotWriter snapshot = log.createNewSnapshot(snapshotId).get()) {
snapshot.freeze();
}
RawSnapshotReader snapshot = log.readSnapshot(snapshotId).get();
assertEquals(0, snapshot.sizeInBytes());
}
Aggregations