StephanEwen commented on a change in pull request #13784: URL: https://github.com/apache/flink/pull/13784#discussion_r511859322
########## File path: flink-core/src/test/java/org/apache/flink/testutils/TestUtils.java ########## @@ -0,0 +1,65 @@ +/* + 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.flink.testutils; + +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.clock.Clock; +import org.apache.flink.util.clock.SystemClock; + +import java.util.concurrent.TimeoutException; +import java.util.function.Supplier; + +/** + * A util class that provides general helper methods for unit tests and IT cases. + * + * <p>Generally speaking a method should be put into this class if the following + * conditions are met: + * <ul> + * <li>The method is commonly used in different modules.</li> + * <li>The method does not introduce cyclic dependency to flink-core.</li> + * </ul> + */ +public class TestUtils { + private static final Clock clock = SystemClock.getInstance(); + + private TestUtils() {} + + /** + * Wait util the given condition is met or timeout. + * + * @param condition the condition to wait for. + * @param timeoutMs the maximum time in milliseconds to wait for the condition to become true. + * @param errorMsg the error message to include in the <code>TimeoutException</code> + * if the condition was not met before timeout. + * @throws TimeoutException if the condition is not met before timeout. + * @throws InterruptedException if the thread is interrupted. + */ + @SuppressWarnings("BusyWait") + public static void waitUtil(Supplier<Boolean> condition, long timeoutMs, String errorMsg) Review comment: Most non-performance critical parts of the code started using `Duration` to make time units explicit. Could we use this here as well? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
