chia7712 commented on code in PR #20751:
URL: https://github.com/apache/kafka/pull/20751#discussion_r2462667903


##########
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeadersTest.java:
##########
@@ -265,4 +273,44 @@ static void assertHeader(String key, String value, Header 
actual) {
         assertArrayEquals(value.getBytes(), actual.value());
     }
 
+    @RepeatedTest(100)
+    public void testRecordHeaderIsReadThreadSafe() throws Exception {
+        int threads = 8;
+        RecordHeader header = new RecordHeader(
+            ByteBuffer.wrap("key".getBytes(StandardCharsets.UTF_8)),
+            ByteBuffer.wrap("value".getBytes(StandardCharsets.UTF_8))
+        );
+
+        ExecutorService pool = Executors.newFixedThreadPool(threads);

Review Comment:
   one more thing: could you please add similar unit test for `null value`?



##########
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeadersTest.java:
##########
@@ -265,4 +273,44 @@ static void assertHeader(String key, String value, Header 
actual) {
         assertArrayEquals(value.getBytes(), actual.value());
     }
 
+    @RepeatedTest(100)
+    public void testRecordHeaderIsReadThreadSafe() throws Exception {
+        int threads = 8;
+        RecordHeader header = new RecordHeader(
+            ByteBuffer.wrap("key".getBytes(StandardCharsets.UTF_8)),
+            ByteBuffer.wrap("value".getBytes(StandardCharsets.UTF_8))
+        );
+
+        ExecutorService pool = Executors.newFixedThreadPool(threads);

Review Comment:
   Or we could leverage `CompletableFuture`
   
   ```java
           CountDownLatch startLatch = new CountDownLatch(1);
           var fs = IntStream.range(0, threads).mapToObj(__ -> 
CompletableFuture.supplyAsync(() -> {
               try {
                   startLatch.await();
                   header.key();
                   header.value();
                   return null;
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           })).collect(Collectors.toUnmodifiableList());
           startLatch.countDown();
           fs.forEach(CompletableFuture::join);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to