jsancio commented on a change in pull request #10786:
URL: https://github.com/apache/kafka/pull/10786#discussion_r651387182



##########
File path: raft/src/test/java/org/apache/kafka/raft/MockLogTest.java
##########
@@ -437,14 +437,89 @@ public void testCreateSnapshot() throws IOException {
         appendBatch(numberOfRecords, epoch);
         log.updateHighWatermark(new LogOffsetMetadata(numberOfRecords));
 
-        try (RawSnapshotWriter snapshot = log.createSnapshot(snapshotId)) {
+        try (RawSnapshotWriter snapshot = log.createSnapshot(snapshotId, 
true).get()) {
             snapshot.freeze();
         }
 
         RawSnapshotReader snapshot = log.readSnapshot(snapshotId).get();
         assertEquals(0, snapshot.sizeInBytes());
     }
 
+    @Test
+    public void testCreateSnapshotValidation() {
+        int numberOfRecords = 10;
+        int firstEpoch = 1;
+        int secondEpoch = 3;
+
+        appendBatch(numberOfRecords, firstEpoch);
+        appendBatch(numberOfRecords, secondEpoch);
+        log.updateHighWatermark(new LogOffsetMetadata(2 * numberOfRecords));
+
+        // Test snapshot id for the first epoch
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(numberOfRecords, firstEpoch), true).get()) { }
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(numberOfRecords - 1, firstEpoch), true).get()) { }
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(1, firstEpoch), true).get()) { }
+
+        // Test snapshot id for the second epoch
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(2 * numberOfRecords, secondEpoch), true).get()) { }
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(2 * numberOfRecords - 1, secondEpoch), true).get()) { }
+        try (RawSnapshotWriter snapshot = log.createSnapshot(new 
OffsetAndEpoch(numberOfRecords + 1, secondEpoch), true).get()) { }
+    }
+
+    @Test
+    public void testCreateSnapshotLaterThanHighWatermark() {
+        int numberOfRecords = 10;
+        int epoch = 1;
+
+        appendBatch(numberOfRecords, epoch);
+        log.updateHighWatermark(new LogOffsetMetadata(numberOfRecords));
+
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> log.createSnapshot(new OffsetAndEpoch(numberOfRecords + 1, 
epoch), true)
+        );
+    }
+
+    @Test
+    public void testCreateSnapshotBeforeLogStartOffset() {

Review comment:
       Added few more tests one for much larger epoch, one for much smaller 
epoch and one for missing epoch.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to