Search in sources :

Example 11 with RawSnapshotWriter

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);
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) Test(org.junit.jupiter.api.Test)

Example 12 with RawSnapshotWriter

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());
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) Test(org.junit.jupiter.api.Test)

Example 13 with RawSnapshotWriter

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);
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) Test(org.junit.jupiter.api.Test)

Example 14 with RawSnapshotWriter

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);
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) Test(org.junit.jupiter.api.Test)

Example 15 with RawSnapshotWriter

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);
}
Also used : RawSnapshotWriter(org.apache.kafka.snapshot.RawSnapshotWriter) Test(org.junit.jupiter.api.Test)

Aggregations

RawSnapshotWriter (org.apache.kafka.snapshot.RawSnapshotWriter)19 Test (org.junit.jupiter.api.Test)17 MemoryRecords (org.apache.kafka.common.record.MemoryRecords)2 SimpleRecord (org.apache.kafka.common.record.SimpleRecord)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 OptionalInt (java.util.OptionalInt)1 FetchSnapshotResponseData (org.apache.kafka.common.message.FetchSnapshotResponseData)1 ApiMessage (org.apache.kafka.common.protocol.ApiMessage)1 Errors (org.apache.kafka.common.protocol.Errors)1 Record (org.apache.kafka.common.record.Record)1 Records (org.apache.kafka.common.record.Records)1 UnalignedMemoryRecords (org.apache.kafka.common.record.UnalignedMemoryRecords)1 RawSnapshotReader (org.apache.kafka.snapshot.RawSnapshotReader)1