You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2023/05/05 10:17:43 UTC
[flink] 01/04: [hotfix][test] Adds utility methods to OneShotLatch
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 43688339721176c8b8070fb19ac1dcda990f9017
Author: Matthias Pohl <ma...@aiven.io>
AuthorDate: Tue Apr 18 14:36:22 2023 +0200
[hotfix][test] Adds utility methods to OneShotLatch
Signed-off-by: Matthias Pohl <ma...@aiven.io>
---
.../apache/flink/core/testutils/OneShotLatch.java | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/OneShotLatch.java b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/OneShotLatch.java
index 82c5afb787e..c0ed331fd05 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/OneShotLatch.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/OneShotLatch.java
@@ -66,6 +66,18 @@ public final class OneShotLatch {
}
}
+ /**
+ * Calls {@link #await()} and transforms any {@link InterruptedException} into a {@link
+ * RuntimeException}.
+ */
+ public void awaitQuietly() {
+ try {
+ await();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Waits until {@link OneShotLatch#trigger()} is called. Once {@code #trigger()} has been called
* this call will always return immediately.
@@ -109,6 +121,18 @@ public final class OneShotLatch {
}
}
+ /**
+ * Calls {@link #await(long, TimeUnit)} and transforms any {@link InterruptedException} or
+ * {@link TimeoutException} into a {@link RuntimeException}.
+ */
+ public void awaitQuietly(long timeout, TimeUnit timeUnit) {
+ try {
+ await(timeout, timeUnit);
+ } catch (InterruptedException | TimeoutException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Checks if the latch was triggered.
*