Copilot commented on code in PR #18804:
URL: https://github.com/apache/kafka/pull/18804#discussion_r1941832078


##########
server/src/test/java/org/apache/kafka/server/share/fetch/ShareFetchTestUtils.java:
##########
@@ -74,4 +87,74 @@ public static void validateRotatedMapEquals(
             assertEquals(original.get(key), result.get(key));
         }
     }
+
+    /**
+     * Create a file records with the given offset values, the number of 
records from each given start
+     * offset.
+     *
+     * @param offsetValues The offset values to create the file records with.
+     * @return The file records.
+     * @throws IOException If the file records cannot be created.
+     */
+    public static FileRecords createFileRecords(Map<Long, Integer> 
offsetValues) throws IOException {
+        FileRecords fileRecords = FileRecords.open(tempFile());
+        for (Entry<Long, Integer> entry : offsetValues.entrySet()) {
+            try (MemoryRecordsBuilder records = 
memoryRecordsBuilder(entry.getValue(), entry.getKey())) {
+                fileRecords.append(records.build());
+            }
+        }
+        return fileRecords;

Review Comment:
   The temporary file created by tempFile() should be properly managed and 
deleted after use to avoid potential issues in different environments.
   ```suggestion
           try (FileRecords fileRecords = FileRecords.open(tempFile())) {
               for (Entry<Long, Integer> entry : offsetValues.entrySet()) {
                   try (MemoryRecordsBuilder records = 
memoryRecordsBuilder(entry.getValue(), entry.getKey())) {
                       fileRecords.append(records.build());
                   }
               }
               return fileRecords;
           }
   ```



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

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

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

Reply via email to