use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testValidateEpochLessThanFirstEpochInLog.
@Test
public void testValidateEpochLessThanFirstEpochInLog() throws IOException {
int numberOfRecords = 5;
int offset = 10;
OffsetAndEpoch olderEpochSnapshotId = new OffsetAndEpoch(offset, 1);
try (RawSnapshotWriter snapshot = log.storeSnapshot(olderEpochSnapshotId).get()) {
snapshot.freeze();
}
log.truncateToLatestSnapshot();
appendBatch(numberOfRecords, 3);
// offset is not equal to oldest snapshot's offset
ValidOffsetAndEpoch resultOffsetAndEpoch = log.validateOffsetAndEpoch(100, 2);
assertEquals(ValidOffsetAndEpoch.diverging(olderEpochSnapshotId), resultOffsetAndEpoch);
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testDoesntTruncateFully.
@Test
public void testDoesntTruncateFully() throws IOException {
int numberOfRecords = 10;
int epoch = 1;
appendBatch(numberOfRecords, epoch);
OffsetAndEpoch olderEpochSnapshotId = new OffsetAndEpoch(numberOfRecords, epoch - 1);
try (RawSnapshotWriter snapshot = log.storeSnapshot(olderEpochSnapshotId).get()) {
snapshot.freeze();
}
assertFalse(log.truncateToLatestSnapshot());
appendBatch(numberOfRecords, epoch);
OffsetAndEpoch olderOffsetSnapshotId = new OffsetAndEpoch(numberOfRecords, epoch);
try (RawSnapshotWriter snapshot = log.storeSnapshot(olderOffsetSnapshotId).get()) {
snapshot.freeze();
}
assertFalse(log.truncateToLatestSnapshot());
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testValidateUnknownEpochLessThanLastKnownGreaterThanOldestSnapshot.
@Test
public void testValidateUnknownEpochLessThanLastKnownGreaterThanOldestSnapshot() throws IOException {
int numberOfRecords = 5;
int offset = 10;
OffsetAndEpoch olderEpochSnapshotId = new OffsetAndEpoch(offset, 1);
try (RawSnapshotWriter snapshot = log.storeSnapshot(olderEpochSnapshotId).get()) {
snapshot.freeze();
}
log.truncateToLatestSnapshot();
appendBatch(numberOfRecords, 1);
appendBatch(numberOfRecords, 2);
appendBatch(numberOfRecords, 4);
// offset is not equal to oldest snapshot's offset
ValidOffsetAndEpoch resultOffsetAndEpoch = log.validateOffsetAndEpoch(100, 3);
assertEquals(ValidOffsetAndEpoch.diverging(new OffsetAndEpoch(20, 2)), resultOffsetAndEpoch);
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testValidateEpochLessThanOldestSnapshotEpoch.
@Test
public void testValidateEpochLessThanOldestSnapshotEpoch() throws IOException {
int offset = 1;
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 - 1);
assertEquals(ValidOffsetAndEpoch.snapshot(olderEpochSnapshotId), resultOffsetAndEpoch);
}
use of org.apache.kafka.snapshot.RawSnapshotWriter in project kafka by apache.
the class MockLogTest method testValidateOffsetLessThanOldestSnapshotOffset.
@Test
public void testValidateOffsetLessThanOldestSnapshotOffset() 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 - 1, epoch);
assertEquals(ValidOffsetAndEpoch.snapshot(olderEpochSnapshotId), resultOffsetAndEpoch);
}
Aggregations