From c46f5442ea3f8276c80627b071338cb4761ef3bb Mon Sep 17 00:00:00 2001 From: Jakub Scholz Date: Sat, 31 Aug 2024 21:53:21 +0200 Subject: [PATCH] Minor clean-up of the test module Signed-off-by: Jakub Scholz --- .../operator/assembly/KafkaConnectApiIT.java | 8 +- .../systemtest}/logs/CollectorElement.java | 2 +- .../strimzi/systemtest/logs/LogCollector.java | 1 - .../systemtest/logs/TestExecutionWatcher.java | 1 - .../parallel/TestSuiteNamespaceManager.java | 2 +- .../resources/NamespaceManager.java | 2 +- .../resources/jaeger/SetupJaeger.java | 2 +- .../operator/SetupClusterOperator.java | 6 +- .../strimzi/systemtest/metrics/MetricsST.java | 2 +- .../operators/LeaderElectionST.java | 3 +- .../systemtest/specific/SpecificST.java | 2 +- .../systemtest/watcher/AllNamespaceST.java | 2 +- .../watcher/MultipleNamespaceST.java | 2 +- test/pom.xml | 4 - .../io/strimzi/test/EmbeddedZooKeeper.java | 78 ------------------- .../main/java/io/strimzi/test/TestUtils.java | 75 ++++-------------- 16 files changed, 30 insertions(+), 162 deletions(-) rename {test/src/main/java/io/strimzi/test => systemtest/src/main/java/io/strimzi/systemtest}/logs/CollectorElement.java (98%) delete mode 100644 test/src/main/java/io/strimzi/test/EmbeddedZooKeeper.java diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiIT.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiIT.java index 14524b7891a..ebf897b7c77 100644 --- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiIT.java +++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiIT.java @@ -9,7 +9,6 @@ import io.strimzi.operator.common.Reconciliation; import io.strimzi.operator.common.model.OrderedProperties; import io.strimzi.test.TestUtils; -import io.strimzi.test.annotations.IsolatedTest; import io.strimzi.test.container.StrimziKafkaCluster; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -23,6 +22,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import java.io.IOException; @@ -84,7 +84,7 @@ public static void after() { vertx.close(); } - @IsolatedTest + @Test @SuppressWarnings({"unchecked", "checkstyle:MethodLength", "checkstyle:NPathComplexity"}) public void test(VertxTestContext context) throws InterruptedException { KafkaConnectApi client = new KafkaConnectApiImpl(vertx); @@ -235,7 +235,7 @@ public void handle(Long timerId) { })); } - @IsolatedTest + @Test public void testChangeLoggers(VertxTestContext context) { String desired = "log4j.rootLogger=TRACE, CONSOLE\n" + "log4j.logger.org.apache.zookeeper=WARN\n" + @@ -272,7 +272,7 @@ public void testChangeLoggers(VertxTestContext context) { })))); } - @IsolatedTest + @Test public void testHierarchy() { String rootLevel = "TRACE"; String desired = "log4j.rootLogger=" + rootLevel + ", CONSOLE\n" + diff --git a/test/src/main/java/io/strimzi/test/logs/CollectorElement.java b/systemtest/src/main/java/io/strimzi/systemtest/logs/CollectorElement.java similarity index 98% rename from test/src/main/java/io/strimzi/test/logs/CollectorElement.java rename to systemtest/src/main/java/io/strimzi/systemtest/logs/CollectorElement.java index 795e3e4ab00..2d810212a0e 100644 --- a/test/src/main/java/io/strimzi/test/logs/CollectorElement.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/logs/CollectorElement.java @@ -2,7 +2,7 @@ * Copyright Strimzi authors. * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). */ -package io.strimzi.test.logs; +package io.strimzi.systemtest.logs; import java.util.Objects; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/logs/LogCollector.java b/systemtest/src/main/java/io/strimzi/systemtest/logs/LogCollector.java index a24f60a7a33..f8289f2cc19 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/logs/LogCollector.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/logs/LogCollector.java @@ -15,7 +15,6 @@ import io.strimzi.systemtest.utils.StUtils; import io.strimzi.test.k8s.KubeClient; import io.strimzi.test.k8s.KubeClusterResource; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/logs/TestExecutionWatcher.java b/systemtest/src/main/java/io/strimzi/systemtest/logs/TestExecutionWatcher.java index 51adf9a0eb4..0d5378344ae 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/logs/TestExecutionWatcher.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/logs/TestExecutionWatcher.java @@ -6,7 +6,6 @@ import io.strimzi.systemtest.Environment; import io.strimzi.systemtest.exceptions.KubernetesClusterUnstableException; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.extension.ExtensionContext; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java b/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java index 18ab3acb067..bcb4d5b153a 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/parallel/TestSuiteNamespaceManager.java @@ -7,10 +7,10 @@ import io.strimzi.systemtest.Environment; import io.strimzi.systemtest.TestConstants; import io.strimzi.systemtest.listeners.ExecutionListener; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.ResourceManager; import io.strimzi.systemtest.utils.StUtils; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.extension.ExtensionContext; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/NamespaceManager.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/NamespaceManager.java index a8a7f70f44a..22d883baf0a 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/NamespaceManager.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/NamespaceManager.java @@ -9,12 +9,12 @@ import io.fabric8.kubernetes.api.model.NamespaceStatus; import io.strimzi.systemtest.Environment; import io.strimzi.systemtest.TestConstants; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.kubernetes.NetworkPolicyResource; import io.strimzi.systemtest.utils.StUtils; import io.strimzi.systemtest.utils.kafkaUtils.KafkaTopicUtils; import io.strimzi.test.TestUtils; import io.strimzi.test.k8s.KubeClusterResource; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/jaeger/SetupJaeger.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/jaeger/SetupJaeger.java index 0e863155363..31f222769cc 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/jaeger/SetupJaeger.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/jaeger/SetupJaeger.java @@ -7,13 +7,13 @@ import io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy; import io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyBuilder; import io.strimzi.systemtest.TestConstants; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.ResourceItem; import io.strimzi.systemtest.resources.ResourceManager; import io.strimzi.systemtest.resources.kubernetes.NetworkPolicyResource; import io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils; import io.strimzi.test.TestUtils; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java index 690113e51da..db9d8c1c9b7 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java @@ -25,6 +25,7 @@ import io.strimzi.systemtest.TestConstants; import io.strimzi.systemtest.enums.ClusterOperatorRBACType; import io.strimzi.systemtest.enums.OlmInstallationStrategy; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.ResourceItem; import io.strimzi.systemtest.resources.ResourceManager; @@ -42,7 +43,6 @@ import io.strimzi.test.executor.Exec; import io.strimzi.test.k8s.KubeClusterResource; import io.strimzi.test.k8s.cluster.OpenShift; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -617,7 +617,7 @@ public String changeLeaseNameInResourceIfNeeded(String yamlPath) { return yamlPath; } - TestUtils.writeFile(tmpFile.getAbsolutePath(), tmpFileContent); + TestUtils.writeFile(tmpFile.toPath(), tmpFileContent); return tmpFile.getAbsolutePath(); } catch (IOException e) { throw new RuntimeException(e); @@ -715,7 +715,7 @@ public File switchClusterRolesToRolesIfNeeded(File oldFile, boolean explicitConv fileNameArr[1] = "Role"; final String changeFileName = Arrays.stream(fileNameArr).map(item -> "-" + item).collect(Collectors.joining()).substring(1); File tmpFile = Files.createTempFile(changeFileName.replace(".yaml", ""), ".yaml").toFile(); - TestUtils.writeFile(tmpFile.getAbsolutePath(), TestUtils.readFile(oldFile).replace("ClusterRole", "Role")); + TestUtils.writeFile(tmpFile.toPath(), TestUtils.readFile(oldFile).replace("ClusterRole", "Role")); LOGGER.info("Replaced ClusterRole for Role in {}", oldFile.getAbsolutePath()); return tmpFile; diff --git a/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java b/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java index 0743ea28be2..3c222b1acab 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/metrics/MetricsST.java @@ -37,6 +37,7 @@ import io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder; import io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients; import io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.NodePoolsConverter; import io.strimzi.systemtest.resources.ResourceManager; @@ -61,7 +62,6 @@ import io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils; import io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils; import io.strimzi.systemtest.utils.specific.CruiseControlUtils; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeAll; diff --git a/systemtest/src/test/java/io/strimzi/systemtest/operators/LeaderElectionST.java b/systemtest/src/test/java/io/strimzi/systemtest/operators/LeaderElectionST.java index 65cb6a392df..91cdee59d75 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/operators/LeaderElectionST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/operators/LeaderElectionST.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.coordination.v1.Lease; import io.strimzi.systemtest.AbstractST; import io.strimzi.systemtest.Environment; +import io.strimzi.systemtest.annotations.IsolatedTest; import io.strimzi.systemtest.resources.ResourceManager; import io.strimzi.systemtest.resources.operator.BundleResource; import io.strimzi.systemtest.resources.operator.specific.HelmResource; import io.strimzi.systemtest.utils.StUtils; import io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils; -import io.strimzi.test.annotations.IsolatedTest; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeAll; @@ -47,7 +47,6 @@ * * the documentation */ - @Tag(REGRESSION) public class LeaderElectionST extends AbstractST { diff --git a/systemtest/src/test/java/io/strimzi/systemtest/specific/SpecificST.java b/systemtest/src/test/java/io/strimzi/systemtest/specific/SpecificST.java index 615e48d4118..f6282ebdade 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/specific/SpecificST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/specific/SpecificST.java @@ -13,6 +13,7 @@ import io.strimzi.systemtest.Environment; import io.strimzi.systemtest.TestConstants; import io.strimzi.systemtest.annotations.IsolatedTest; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.NodePoolsConverter; import io.strimzi.systemtest.resources.ResourceManager; @@ -24,7 +25,6 @@ import io.strimzi.systemtest.templates.kubernetes.ClusterRoleBindingTemplates; import io.strimzi.systemtest.utils.kafkaUtils.KafkaUtils; import io.strimzi.test.TestUtils; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hamcrest.CoreMatchers; diff --git a/systemtest/src/test/java/io/strimzi/systemtest/watcher/AllNamespaceST.java b/systemtest/src/test/java/io/strimzi/systemtest/watcher/AllNamespaceST.java index c42546784e5..04a49f5dacc 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/watcher/AllNamespaceST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/watcher/AllNamespaceST.java @@ -6,8 +6,8 @@ import io.strimzi.systemtest.Environment; import io.strimzi.systemtest.TestConstants; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeAll; diff --git a/systemtest/src/test/java/io/strimzi/systemtest/watcher/MultipleNamespaceST.java b/systemtest/src/test/java/io/strimzi/systemtest/watcher/MultipleNamespaceST.java index 18583a60468..690fe6be1cd 100644 --- a/systemtest/src/test/java/io/strimzi/systemtest/watcher/MultipleNamespaceST.java +++ b/systemtest/src/test/java/io/strimzi/systemtest/watcher/MultipleNamespaceST.java @@ -4,10 +4,10 @@ */ package io.strimzi.systemtest.watcher; +import io.strimzi.systemtest.logs.CollectorElement; import io.strimzi.systemtest.resources.NamespaceManager; import io.strimzi.systemtest.resources.ResourceManager; import io.strimzi.systemtest.resources.operator.SetupClusterOperator; -import io.strimzi.test.logs.CollectorElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeAll; diff --git a/test/pom.xml b/test/pom.xml index 7706445c280..901711e73a3 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -39,10 +39,6 @@ org.apache.logging.log4j log4j-api - - org.apache.zookeeper - zookeeper - com.jayway.jsonpath json-path diff --git a/test/src/main/java/io/strimzi/test/EmbeddedZooKeeper.java b/test/src/main/java/io/strimzi/test/EmbeddedZooKeeper.java deleted file mode 100644 index 3ed6644dcc4..00000000000 --- a/test/src/main/java/io/strimzi/test/EmbeddedZooKeeper.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Strimzi authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.strimzi.test; - -import org.apache.zookeeper.server.NIOServerCnxnFactory; -import org.apache.zookeeper.server.ZooKeeperServer; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.file.Files; - -public class EmbeddedZooKeeper { - - NIOServerCnxnFactory factory; - ZooKeeperServer zk; - File dir; - - public EmbeddedZooKeeper() throws IOException, InterruptedException { - dir = Files.createTempDirectory("strimzi").toFile(); - zk = new ZooKeeperServer(dir, dir, 1000); - start(new InetSocketAddress("localhost", TestUtils.getFreePort())); - } - - private void start(InetSocketAddress addr) throws IOException, InterruptedException { - factory = new NIOServerCnxnFactory(); - factory.configure(addr, 20); - factory.startup(zk); - } - - public void restart() throws IOException, InterruptedException { - if (zk != null) { - zk.shutdown(false); - } - // Reuse the existing port - InetSocketAddress addr = factory.getLocalAddress(); - factory.shutdown(); - zk = new ZooKeeperServer(dir, dir, 1000); - start(addr); - } - - public void close() { - if (zk != null) { - zk.shutdown(true); - } - if (factory != null) { - factory.shutdown(); - } - delete(dir); - } - - private static void delete(File file) { - File[] children = file.listFiles(); - if (children != null) { - for (File child : children) { - delete(child); - } - } - if (!file.delete()) { - noop(); - } - } - - private static void noop() { - // Here merely to please findbugs - } - - public int getZkPort() { - return factory.getLocalPort(); - } - - public String getZkConnectString() { - InetSocketAddress addr = factory.getLocalAddress(); - return addr.getAddress().getHostAddress() + ":" + addr.getPort(); - } -} diff --git a/test/src/main/java/io/strimzi/test/TestUtils.java b/test/src/main/java/io/strimzi/test/TestUtils.java index 0695c5258df..03aeb967559 100644 --- a/test/src/main/java/io/strimzi/test/TestUtils.java +++ b/test/src/main/java/io/strimzi/test/TestUtils.java @@ -57,6 +57,7 @@ import java.util.concurrent.TimeoutException; import java.util.function.BooleanSupplier; import java.util.function.Function; +import java.util.stream.Stream; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; @@ -72,7 +73,7 @@ public final class TestUtils { public static final String USER_PATH = System.getProperty("user.dir"); - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + public static final String LINE_SEPARATOR = System.lineSeparator(); public static final String CRD_TOPIC = USER_PATH + "/../packaging/install/cluster-operator/043-Crd-kafkatopic.yaml"; @@ -179,9 +180,7 @@ public static long waitFor(String description, long pollIntervalMs, long timeout } } onTimeout.run(); - WaitException waitException = new WaitException("Timeout after " + timeoutMs + " ms waiting for " + description); - waitException.printStackTrace(); - throw waitException; + throw new WaitException("Timeout after " + timeoutMs + " ms waiting for " + description); } long sleepTime = Math.min(pollIntervalMs, timeLeft); if (LOGGER.isTraceEnabled()) { @@ -249,7 +248,7 @@ public static String readResource(InputStream stream) { textBuilder.append((char) character); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.warn("Failed to read from InputStream", e); } return textBuilder.toString(); } @@ -341,25 +340,6 @@ public static ConfigMap configMapFromYaml(String yamlPath, String name) { } - public static T configFromMultiYamlFile(String yamlFile, String expectedKind, Class kindClass) { - return configFromMultiYamlFile(new File(yamlFile), expectedKind, kindClass); - } - - public static T configFromMultiYamlFile(File yamlFile, String expectedKind, Class kindClass) { - try { - YAMLFactory yamlFactory = new YAMLFactory(); - ObjectMapper mapper = new ObjectMapper(); - YAMLParser yamlParser = yamlFactory.createParser(yamlFile); - List> resources = mapper.readValues(yamlParser, new TypeReference>() { }).readAll(); - - return mapper.convertValue(resources.stream().filter(resource -> resource.get("kind").equals(expectedKind)).findFirst().get(), kindClass); - } catch (InvalidFormatException e) { - throw new IllegalArgumentException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - public static T configFromYaml(File yamlFile, Class c) { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try { @@ -391,18 +371,7 @@ public static void writeFile(Path filePath, String text) { try { Files.writeString(filePath, text, StandardCharsets.UTF_8); } catch (IOException e) { - LOGGER.info("Exception during writing text in file"); - e.printStackTrace(); - } - } - - /** Method to create and write file */ - public static void writeFile(String filePath, String text) { - try { - Files.writeString(Paths.get(filePath), text, StandardCharsets.UTF_8); - } catch (IOException e) { - LOGGER.info("Exception during writing text in file"); - e.printStackTrace(); + LOGGER.warn("Exception during writing text in file", e); } } @@ -520,32 +489,12 @@ public static T await(CompletionStage stage, long timeout, TimeUnit unit) * result. * * @param unused the result of a completion stage, unused by this method - * @param error an error thrown by the an earlier completion stage + * @param error an error thrown by an earlier completion stage */ public static void assertSuccessful(Object unused, Throwable error) { assertThat(error, is(nullValue())); } - /** - * Creates an empty file in the default temporary-file directory with an UUID as prefix and .tmp as suffix. - * - * @return The empty file just created. - */ - public static File tempFile() { - return tempFile(null); - } - - /** - * Creates an empty file in the default temporary-file directory with an UUID as prefix and given suffix. - * - * @param suffix The suffix of the empty file (default: .tmp). - * - * @return The empty file just created. - */ - public static File tempFile(String suffix) { - return tempFile(null, suffix); - } - /** * Creates an empty file in the default temporary-file directory, using the given prefix and suffix. * @@ -577,11 +526,15 @@ public static File tempFile(String prefix, String suffix) { public static String jsonFromResource(String resourcePath) { try { URI resourceURI = Objects.requireNonNull(TestUtils.class.getClassLoader().getResource(resourcePath)).toURI(); - Optional content = Files.lines(Paths.get(resourceURI), UTF_8).reduce((x, y) -> x + y); - if (content.isEmpty()) { - throw new IOException(format("File %s from resources was empty", resourcePath)); + try (Stream lines = Files.lines(Paths.get(resourceURI), UTF_8)) { + Optional content = lines.reduce((x, y) -> x + y); + + if (content.isEmpty()) { + throw new IOException(format("File %s from resources was empty", resourcePath)); + } + + return content.get(); } - return content.get(); } catch (Throwable t) { throw new RuntimeException(t); }