You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Scanteianu (via GitHub)" <gi...@apache.org> on 2023/04/23 11:23:38 UTC

[GitHub] [kafka] Scanteianu commented on a diff in pull request #10933: Fix NPE on concurrent RecordHeader.key() access

Scanteianu commented on code in PR #10933:
URL: https://github.com/apache/kafka/pull/10933#discussion_r1174561351


##########
clients/src/test/java/org/apache/kafka/common/header/internals/RecordHeaderConcurrentTest.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.common.header.internals;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class RecordHeaderConcurrentTest {
+
+    private static final int ITERATIONS = 100_000;
+
+    private final byte[] keyBytes = "key".getBytes(StandardCharsets.UTF_8);
+    private final byte[] valueBytes = "value".getBytes(StandardCharsets.UTF_8);
+    private final ByteBuffer keyBuffer = ByteBuffer.wrap(keyBytes);
+    private final ByteBuffer valueBuffer = ByteBuffer.wrap(valueBytes);
+
+    private static final ExecutorService executorService = Executors.newSingleThreadExecutor();

Review Comment:
   in order to get a higher probability of concurrent access, would it maybe make sense to use `Executors.newFixedThreadPool(NUM_THREADS);`  with `NUM_THREADS` around 10? (and also modify the structure of the test to submit a whole bunch of requests, collect the futures, and then get them back and run the assertions)?



-- 
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-unsubscribe@kafka.apache.org

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