niket-goel commented on a change in pull request #10899:
URL: https://github.com/apache/kafka/pull/10899#discussion_r658137972



##########
File path: 
raft/src/test/java/org/apache/kafka/snapshot/SnapshotWriterReaderTest.java
##########
@@ -37,6 +43,52 @@
     private final int localId = 0;
     private final Set<Integer> voters = Collections.singleton(localId);
 
+    @Test
+    public void testSnapshotDelimiters() throws Exception {
+        // TODO ngoel
+        // Is this the right way to setup the offset for
+        // an empty snapshot?
+        int recordsPerBatch = 1;
+        int batches = 0;
+        OffsetAndEpoch id = new OffsetAndEpoch(recordsPerBatch * batches, 3);
+
+        RaftClientTestContext.Builder contextBuilder = new 
RaftClientTestContext.Builder(localId, voters);
+        RaftClientTestContext context = contextBuilder.build();
+
+        context.pollUntil(() -> 
context.currentLeader().equals(OptionalInt.of(localId)));
+        context.advanceLocalLeaderHighWatermarkToLogEndOffset();
+
+        // Create an empty snapshot and freeze it immediately
+        try (SnapshotWriter<String> snapshot = 
context.client.createSnapshot(id.offset - 1, id.epoch).get()) {
+            assertEquals(id, snapshot.snapshotId());
+            snapshot.freeze();
+        }
+
+        // Verify that an empty snapshot has only the Header and Footer
+        try (SnapshotReader<String> reader = readSnapshot(context, id, 
Integer.MAX_VALUE)) {
+            RawSnapshotReader snapshot = context.log.readSnapshot(id).get();
+            // TODO ngoel
+            // Is there a way to make this a function of the actual
+            // Control Batch Record size.
+            assertEquals(150, snapshot.sizeInBytes());

Review comment:
       Yeah, I wanted to ask you about this. I think checking to decode it as  
a control batch makes sense. Will do that.
   

##########
File path: 
raft/src/test/java/org/apache/kafka/snapshot/SnapshotWriterReaderTest.java
##########
@@ -37,6 +43,52 @@
     private final int localId = 0;
     private final Set<Integer> voters = Collections.singleton(localId);
 
+    @Test
+    public void testSnapshotDelimiters() throws Exception {
+        // TODO ngoel
+        // Is this the right way to setup the offset for
+        // an empty snapshot?
+        int recordsPerBatch = 1;
+        int batches = 0;
+        OffsetAndEpoch id = new OffsetAndEpoch(recordsPerBatch * batches, 3);
+
+        RaftClientTestContext.Builder contextBuilder = new 
RaftClientTestContext.Builder(localId, voters);
+        RaftClientTestContext context = contextBuilder.build();
+
+        context.pollUntil(() -> 
context.currentLeader().equals(OptionalInt.of(localId)));
+        context.advanceLocalLeaderHighWatermarkToLogEndOffset();
+
+        // Create an empty snapshot and freeze it immediately
+        try (SnapshotWriter<String> snapshot = 
context.client.createSnapshot(id.offset - 1, id.epoch).get()) {
+            assertEquals(id, snapshot.snapshotId());
+            snapshot.freeze();
+        }
+
+        // Verify that an empty snapshot has only the Header and Footer
+        try (SnapshotReader<String> reader = readSnapshot(context, id, 
Integer.MAX_VALUE)) {
+            RawSnapshotReader snapshot = context.log.readSnapshot(id).get();
+            // TODO ngoel
+            // Is there a way to make this a function of the actual
+            // Control Batch Record size.
+            assertEquals(150, snapshot.sizeInBytes());
+            int countBatches = 0;
+            Iterator<RecordBatch> recordBatches = 
Utils.covariantCast(snapshot.records().batchIterator());
+            while (recordBatches.hasNext()) {
+                int countRecords = 0;
+                RecordBatch batch = recordBatches.next();

Review comment:
       Will do




-- 
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