chia7712 commented on code in PR #20751:
URL: https://github.com/apache/kafka/pull/20751#discussion_r2461184891
##########
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeadersTest.java:
##########
@@ -265,4 +273,36 @@ 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);
+ CountDownLatch startLatch = new CountDownLatch(1);
+ AtomicBoolean raceDetected = new AtomicBoolean(false);
+
+ Runnable task = () -> {
+ try {
+ startLatch.await();
+ header.key();
+ header.value();
+ } catch (NullPointerException e) {
+ raceDetected.set(true);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ };
+
+ for (int i = 0; i < threads; i++) pool.submit(task);
+
+ startLatch.countDown();
+ pool.shutdown();
Review Comment:
Could you use `try-finally` to ensure the release?
--
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]