Package org.apache.flink.core.testutils
Class CommonTestUtils
java.lang.Object
org.apache.flink.core.testutils.CommonTestUtils
This class contains reusable utility methods for unit tests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertThrows(String msg, Class<? extends Exception> expected, Callable<?> code) Checks whether an exception with a message occurs when running a piece of code.static voidPermanently blocks the current thread.static booleancontainsCause(Throwable throwable, Class<? extends Throwable> cause) Checks whether the given throwable contains the given cause as a cause.static <T extends Serializable>
TcreateCopySerializable(T original) Creates a copy of an object via Java Serialization.static StringcreateTempFile(String contents) Creates a temporary file that contains the given string.static voidstatic voidstatic voidwaitUntilIgnoringExceptions(Supplier<Boolean> condition, Duration timeout, Duration pause, String errorMsg) Wait until the given condition is met or timeout, ignoring any exceptions thrown by the condition.static voidWait util the given condition is met or timeout.static voidWait util the given condition is met or timeout.
-
Constructor Details
-
CommonTestUtils
public CommonTestUtils()
-
-
Method Details
-
createCopySerializable
Creates a copy of an object via Java Serialization.- Parameters:
original- The original object.- Returns:
- The copied object.
- Throws:
IOException
-
createTempFile
Creates a temporary file that contains the given string. The file is written with the platform's default encoding.The temp file is automatically deleted on JVM exit.
- Parameters:
contents- The contents to be written to the file.- Returns:
- The temp file URI.
- Throws:
IOException
-
blockForeverNonInterruptibly
public static void blockForeverNonInterruptibly()Permanently blocks the current thread. The thread cannot be woken up viaThread.interrupt(). -
setEnv
-
setEnv
-
containsCause
Checks whether the given throwable contains the given cause as a cause. The cause is not checked on equality but on type equality.- Parameters:
throwable- Throwable to check for the causecause- Cause to look for- Returns:
- True if the given Throwable contains the given cause (type equality); otherwise false
-
assertThrows
Checks whether an exception with a message occurs when running a piece of code. -
waitUtil
public static void waitUtil(Supplier<Boolean> condition, Duration timeout, Duration pause, String errorMsg) throws TimeoutException, InterruptedException Wait util the given condition is met or timeout.- Parameters:
condition- the condition to wait for.timeout- the maximum time to wait for the condition to become true.pause- delay between condition checks.errorMsg- the error message to include in theTimeoutExceptionif the condition was not met before timeout.- Throws:
TimeoutException- if the condition is not met before timeout.InterruptedException- if the thread is interrupted.
-
waitUntilIgnoringExceptions
public static void waitUntilIgnoringExceptions(Supplier<Boolean> condition, Duration timeout, Duration pause, String errorMsg) throws TimeoutException, InterruptedException Wait until the given condition is met or timeout, ignoring any exceptions thrown by the condition.- Parameters:
condition- the condition to wait for.timeout- the maximum time to wait for the condition to become true.pause- delay between condition checks.errorMsg- the error message to include in theTimeoutExceptionif the condition was not met before timeout.- Throws:
TimeoutException- if the condition is not met before timeout.InterruptedException- if the thread is interrupted.
-
waitUtil
public static void waitUtil(Supplier<Boolean> condition, Duration timeout, String errorMsg) throws TimeoutException, InterruptedException Wait util the given condition is met or timeout.- Parameters:
condition- the condition to wait for.timeout- the maximum time to wait for the condition to become true.errorMsg- the error message to include in theTimeoutExceptionif the condition was not met before timeout.- Throws:
TimeoutException- if the condition is not met before timeout.InterruptedException- if the thread is interrupted.
-