rhauch commented on a change in pull request #11797: URL: https://github.com/apache/kafka/pull/11797#discussion_r815174043
########## File path: connect/runtime/src/main/java/org/apache/kafka/connect/util/RetryUtil.java ########## @@ -0,0 +1,76 @@ +/* + * 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.connect.util; + +import org.apache.kafka.common.errors.RetriableException; +import org.apache.kafka.common.errors.WakeupException; +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.connect.errors.ConnectException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.Callable; + +public class RetryUtil { + private static final Logger log = LoggerFactory.getLogger(RetryUtil.class); + + /** + * The method executes the callable at least once, optionally retrying the callable if + * {@link org.apache.kafka.connect.errors.RetriableException} is being thrown. If all retries are exhausted, + * then the last exception is wrapped with a {@link org.apache.kafka.connect.errors.ConnectException} and thrown. + * + * <p>If <code>maxRetries</code> is set to 0, the task will be + * executed exactly once. If <code>maxRetries</code> is set to <code>n</code>, the callable will be executed at + * most <code>n + 1</code> times. + * + * <p>If <code>retryBackoffMs</code> is set to 0, no wait will happen in between the retries. + * + * @param callable the function to execute. + * @param maxRetries maximum number of retries; must be 0 or more + * @param retryBackoffMs the number of milliseconds to delay upon receiving a + * {@link org.apache.kafka.connect.errors.RetriableException} before retrying again; must be 0 or more + * Review comment: Nit on the spacing so the description of parameters is column-aligned. ```suggestion * @param callable the function to execute. * @param maxRetries maximum number of retries; must be 0 or more * @param retryBackoffMs the number of milliseconds to delay upon receiving a * {@link org.apache.kafka.connect.errors.RetriableException} before retrying again; * must be 0 or more ``` ########## File path: connect/runtime/src/test/java/org/apache/kafka/connect/util/RetryUtilTest.java ########## @@ -0,0 +1,127 @@ +/* + * 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.connect.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.apache.kafka.common.errors.TimeoutException; +import org.apache.kafka.connect.errors.ConnectException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.concurrent.Callable; + +@RunWith(PowerMockRunner.class) +public class RetryUtilTest { + + @Mock Review comment: Do we need this line? I think not since you're instantiating `mockCallable` in `setUp()`. The annotation is really only needed when the Mockito JUnit runner is used to initialize the mock fields. Also, IIRC we get rid of the `@RunWith(PowerMockRunner.class)` line as well, since this code is not really using anything from PowerMock. It'd be great if we could avoid using PowerMock in new code. -- 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