You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "JiayaoS (via GitHub)" <gi...@apache.org> on 2026/05/06 01:36:37 UTC

[PR] MINOR: Move AdminClient timeout test to Java and remove internal factory hack [kafka]

JiayaoS opened a new pull request, #22220:
URL: https://github.com/apache/kafka/pull/22220

   Moves `testCallInFlightTimeouts` from the Scala core module to a new Java `AdminClientTimeoutIntegrationTest` in `clients-integration-tests`. 
   By placing the test in the `org.apache.kafka.clients.admin` package, it can directly access `KafkaAdminClient.createInternal()`. This allows us to:
   1. Delete the `KafkaAdminClientInternalFactory` backdoor, restoring proper encapsulation.
   2. Inline `FailureInjectingTimeoutProcessorFactory` into the test class, reducing test fixture clutter.
   


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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "soarez (via GitHub)" <gi...@apache.org>.
soarez commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3201076626


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private static final Logger log = LoggerFactory.getLogger(AdminClientTimeoutIntegrationTest.class);
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        var config = Map.of(
+                AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers(),
+                AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000",
+                AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000",

Review Comment:
   Are these two configurations necessary? I suspect we can remove them.



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3201546427


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private static final Logger log = LoggerFactory.getLogger(AdminClientTimeoutIntegrationTest.class);
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        var config = Map.of(
+                AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers(),
+                AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000",
+                AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000",

Review Comment:
   It appears this is used to prevent these calls from being handled by `handleTimeouts`. While the value seems a bit excessive, it should be fine as long as we add a comment explaining its purpose.



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "JiayaoS (via GitHub)" <gi...@apache.org>.
JiayaoS commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3197631216


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();

Review Comment:
   Thank you, I've fixed this and also changed similar issues to `var`.



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();
+        try (Admin client = KafkaAdminClient.createInternal(new AdminClientConfig(config), factory)) {
+
+            var future = client.createTopics(Stream.of("mytopic1", "mytopic2")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+
+            var e = assertThrows(ExecutionException.class, future::get);
+            assertInstanceOf(TimeoutException.class, e.getCause());
+
+            var future2 = client.createTopics(Stream.of("mytopic3", "mytopic4")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+            future2.get();
+            assertEquals(1, factory.failuresInjected());
+        }
+    }
+
+
+    static class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory {
+
+        private static final Logger log = LoggerFactory.getLogger(FailureInjectingTimeoutProcessorFactory.class);
+
+        private int numTries = 0;
+
+        private int failuresInjected = 0;
+
+        @Override
+        KafkaAdminClient.TimeoutProcessor create(long now) {
+            return new FailureInjectingTimeoutProcessor(now);
+        }
+
+        synchronized boolean shouldInjectFailure() {
+            numTries++;
+            if (numTries == 1) {
+                failuresInjected++;
+                return true;
+            }
+            return false;
+        }
+
+        synchronized int failuresInjected() {
+            return failuresInjected;
+        }
+
+        final class FailureInjectingTimeoutProcessor extends KafkaAdminClient.TimeoutProcessor {
+            FailureInjectingTimeoutProcessor(long now) {
+                super(now);
+            }
+
+            boolean callHasExpired(KafkaAdminClient.Call call) {

Review Comment:
   Yes, I fixed this



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "JiayaoS (via GitHub)" <gi...@apache.org>.
JiayaoS commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3204827783


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private static final Logger log = LoggerFactory.getLogger(AdminClientTimeoutIntegrationTest.class);
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        var config = Map.of(
+                AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers(),
+                AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000",
+                AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000",

Review Comment:
   Thanks @soarez @chia7712. I removed `REQUEST_TIMEOUT_MS_CONFIG` — the default is already [30s](https://github.com/apache/kafka/blob/baa064e4223005c0bf78cd03c4bcf4d65b50bfa1/clients/src/main/java/org/apache/kafka/clients/admin/AdminClientConfig.java#L206-L207), **so** setting it to 20s doesn't add value here. Kept `DEFAULT_API_TIMEOUT_MS_CONFIG` with a comment explaining its purpose.
   



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "soarez (via GitHub)" <gi...@apache.org>.
soarez commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3196841537


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();
+        try (Admin client = KafkaAdminClient.createInternal(new AdminClientConfig(config), factory)) {
+
+            var future = client.createTopics(Stream.of("mytopic1", "mytopic2")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+
+            var e = assertThrows(ExecutionException.class, future::get);
+            assertInstanceOf(TimeoutException.class, e.getCause());
+
+            var future2 = client.createTopics(Stream.of("mytopic3", "mytopic4")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+            future2.get();
+            assertEquals(1, factory.failuresInjected());
+        }
+    }
+
+
+    static class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory {
+
+        private static final Logger log = LoggerFactory.getLogger(FailureInjectingTimeoutProcessorFactory.class);
+
+        private int numTries = 0;
+
+        private int failuresInjected = 0;
+
+        @Override
+        KafkaAdminClient.TimeoutProcessor create(long now) {
+            return new FailureInjectingTimeoutProcessor(now);
+        }
+
+        synchronized boolean shouldInjectFailure() {
+            numTries++;
+            if (numTries == 1) {
+                failuresInjected++;
+                return true;
+            }
+            return false;
+        }
+
+        synchronized int failuresInjected() {
+            return failuresInjected;
+        }
+
+        final class FailureInjectingTimeoutProcessor extends KafkaAdminClient.TimeoutProcessor {
+            FailureInjectingTimeoutProcessor(long now) {
+                super(now);
+            }
+
+            boolean callHasExpired(KafkaAdminClient.Call call) {

Review Comment:
   Missing an `@Override` here?



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3196623195


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();
+        try (Admin client = KafkaAdminClient.createInternal(new AdminClientConfig(config), factory)) {
+
+            var future = client.createTopics(Stream.of("mytopic1", "mytopic2")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+
+            var e = assertThrows(ExecutionException.class, future::get);
+            assertInstanceOf(TimeoutException.class, e.getCause());
+
+            var future2 = client.createTopics(Stream.of("mytopic3", "mytopic4")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+            future2.get();
+            assertEquals(1, factory.failuresInjected());
+        }
+    }
+
+
+    static class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory {
+
+        private static final Logger log = LoggerFactory.getLogger(FailureInjectingTimeoutProcessorFactory.class);

Review Comment:
   Could you move `log` to `AdminClientTimeoutIntegrationTest` ?



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();

Review Comment:
   ```java
   Map<String, Object> config = Map.of(
       AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers(),
       AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000",
       AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000",
       AdminClientConfig.RETRIES_CONFIG, "0"
   );
   ```



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();

Review Comment:
   ```java
   var factory = new FailureInjectingTimeoutProcessorFactory();
   ```



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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #22220:
URL: https://github.com/apache/kafka/pull/22220


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


Re: [PR] MINOR: Move testCallInFlightTimeouts to Java and remove internal factory hack [kafka]

Posted by "JiayaoS (via GitHub)" <gi...@apache.org>.
JiayaoS commented on code in PR #22220:
URL: https://github.com/apache/kafka/pull/22220#discussion_r3197629670


##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();
+        config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterInstance.bootstrapServers());
+        config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "20000");
+        config.put(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "100000000");
+        config.put(AdminClientConfig.RETRIES_CONFIG, "0");
+
+        FailureInjectingTimeoutProcessorFactory factory = new FailureInjectingTimeoutProcessorFactory();
+        try (Admin client = KafkaAdminClient.createInternal(new AdminClientConfig(config), factory)) {
+
+            var future = client.createTopics(Stream.of("mytopic1", "mytopic2")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+
+            var e = assertThrows(ExecutionException.class, future::get);
+            assertInstanceOf(TimeoutException.class, e.getCause());
+
+            var future2 = client.createTopics(Stream.of("mytopic3", "mytopic4")
+                    .map(t -> new NewTopic(t, 1, (short) 1)).toList(),
+                    new CreateTopicsOptions().validateOnly(true)).all();
+            future2.get();
+            assertEquals(1, factory.failuresInjected());
+        }
+    }
+
+
+    static class FailureInjectingTimeoutProcessorFactory extends KafkaAdminClient.TimeoutProcessorFactory {
+
+        private static final Logger log = LoggerFactory.getLogger(FailureInjectingTimeoutProcessorFactory.class);

Review Comment:
   Done.



##########
clients/clients-integration-tests/src/test/java/org/apache/kafka/clients/admin/AdminClientTimeoutIntegrationTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.clients.admin;
+
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.test.ClusterInstance;
+import org.apache.kafka.common.test.api.ClusterTest;
+import org.apache.kafka.common.test.api.ClusterTestDefaults;
+import org.apache.kafka.common.test.api.Type;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+@ClusterTestDefaults(types = { Type.KRAFT })
+public class AdminClientTimeoutIntegrationTest {
+
+    private final ClusterInstance clusterInstance;
+
+    public AdminClientTimeoutIntegrationTest(ClusterInstance clusterInstance) {
+        this.clusterInstance = clusterInstance;
+    }
+
+    /**
+     * Test injecting timeouts for calls that are in flight.
+     */
+    @ClusterTest
+    public void testCallInFlightTimeouts() throws Exception {
+        Map<String, Object> config = new HashMap<>();

Review Comment:
   Thanks, I fixed this



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