diff --git a/it/common/src/main/java/org/apache/beam/it/common/utils/ResourceManagerUtils.java b/it/common/src/main/java/org/apache/beam/it/common/utils/ResourceManagerUtils.java index 7bcb1aa85dc4..a90c4f77dc0d 100644 --- a/it/common/src/main/java/org/apache/beam/it/common/utils/ResourceManagerUtils.java +++ b/it/common/src/main/java/org/apache/beam/it/common/utils/ResourceManagerUtils.java @@ -137,6 +137,17 @@ public static void checkValidProjectId(String idToCheck) { * @param managers Varargs of the managers to clean */ public static void cleanResources(ResourceManager... managers) { + cleanResources(false, managers); + } + + /** + * Cleanup Resources from the given ResourceManagers. It will guarantee that all the cleanups are + * invoked, but still throws / bubbles the first exception at the end if something went wrong. + * + * @param failOnCleanup Throw exception if cleanup fails. + * @param managers Varargs of the managers to clean + */ + public static void cleanResources(boolean failOnCleanup, ResourceManager... managers) { if (managers == null || managers.length == 0) { return; @@ -159,8 +170,12 @@ public static void cleanResources(ResourceManager... managers) { } } - if (bubbleException != null) { + if (bubbleException != null && failOnCleanup) { throw new RuntimeException("Error cleaning up resources", bubbleException); + } else if (bubbleException != null) { + LOG.warn( + "Error cleaning up resources. This is not configured to fail the test: {}", + bubbleException.getMessage()); } }