dimitarndimitrov commented on code in PR #13856:
URL: https://github.com/apache/kafka/pull/13856#discussion_r1233937877


##########
server-common/src/test/java/org/apache/kafka/server/util/InterBrokerSendThreadTest.java:
##########
@@ -0,0 +1,327 @@
+/*
+ * 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.server.util;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Queue;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import org.apache.kafka.clients.ClientRequest;
+import org.apache.kafka.clients.ClientResponse;
+import org.apache.kafka.clients.KafkaClient;
+import org.apache.kafka.clients.RequestCompletionHandler;
+import org.apache.kafka.common.Node;
+import org.apache.kafka.common.errors.AuthenticationException;
+import org.apache.kafka.common.errors.DisconnectException;
+import org.apache.kafka.common.internals.FatalExitError;
+import org.apache.kafka.common.protocol.ApiKeys;
+import org.apache.kafka.common.requests.AbstractRequest;
+import org.apache.kafka.common.utils.Time;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
+
+public class InterBrokerSendThreadTest {
+
+    private final Time time = new MockTime();
+    private final KafkaClient networkClient = mock(KafkaClient.class);
+    private final StubCompletionHandler completionHandler = new 
StubCompletionHandler();
+    private final int requestTimeoutMs = 1000;
+
+    class TestInterBrokerSendThread extends InterBrokerSendThread {
+
+        private final Consumer<Throwable> exceptionCallback;
+        private final Queue<RequestAndCompletionHandler> queue = new 
ArrayDeque<>();
+
+        TestInterBrokerSendThread() {
+            this(
+                InterBrokerSendThreadTest.this.networkClient,
+                t -> {
+                    throw (t instanceof RuntimeException)
+                        ? ((RuntimeException) t)
+                        : new RuntimeException(t);
+                });
+        }
+
+        TestInterBrokerSendThread(KafkaClient networkClient, 
Consumer<Throwable> exceptionCallback) {
+            super("name", networkClient, requestTimeoutMs, time);
+            this.exceptionCallback = exceptionCallback;
+        }
+
+        void enqueue(RequestAndCompletionHandler request) {
+            queue.offer(request);
+        }
+
+        @Override
+        public Collection<RequestAndCompletionHandler> generateRequests() {
+            return queue.isEmpty() ? Collections.emptyList() : 
Collections.singletonList(queue.poll());
+        }
+
+        @Override
+        protected void pollOnce(long maxTimeoutMs) {
+            try {
+                super.pollOnce(maxTimeoutMs);
+            } catch (Throwable t) {
+                exceptionCallback.accept(t);
+            }
+        }
+    }
+
+    @Test
+    public void shutdownThreadShouldNotCauseException() throws 
InterruptedException, IOException {

Review Comment:
   Done.
   - For some reason the original Scala test didn't name the test methods with 
a `test` prefix and I didn't even notice...



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