From 32fc73d64182b7e27e23aa5cb41a14a22ec8e8ab Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 26 Oct 2020 14:31:04 +1000 Subject: [PATCH] use try resource for container Signed-off-by: olivier lamy --- .../core/autobahn/AutobahnTests.java | 33 ++++++++----------- pom.xml | 5 +++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java index d46133cbef9..2f3e9d518a1 100644 --- a/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java +++ b/jetty-websocket/websocket-core-tests/src/test/java/org/eclipse/jetty/websocket/core/autobahn/AutobahnTests.java @@ -24,6 +24,7 @@ import java.nio.file.Paths; import java.time.Duration; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.IO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -47,6 +48,8 @@ public class AutobahnTests private Path fuzzingServer; private Path fuzzingClient; + Path baseDir; + @BeforeEach public void before() throws Exception { @@ -54,7 +57,7 @@ public class AutobahnTests workspace = System.getenv().get("WORKSPACE"); LOG.info("Workspace: {}", workspace); LOG.info("User Dir: {}", USER_DIR); - Path baseDir = (workspace != null) ? Paths.get(workspace) : USER_DIR; + baseDir = (workspace != null) ? Paths.get(workspace) : USER_DIR; LOG.info("Base Dir: {}", baseDir); fuzzingServer = baseDir.resolve("fuzzingserver.json"); @@ -72,22 +75,17 @@ public class AutobahnTests public void testClient() throws Exception { // We need to chown the generated test results so host has permissions to delete files generated by container. - GenericContainer container = new GenericContainer<>("crossbario/autobahn-testsuite:latest") + try (GenericContainer container = new GenericContainer<>("crossbario/autobahn-testsuite:latest") .withCommand("/bin/bash", "-c", "wstest -m fuzzingserver -s /config/fuzzingserver.json ; " + CHOWN_REPORTS_CMD) .withExposedPorts(9001) - .withLogConsumer(new Slf4jLogConsumer(LOG)); - container.addFileSystemBind(fuzzingServer.toString(), "/config/fuzzingserver.json", BindMode.READ_ONLY); - container.addFileSystemBind(reportDir.toString(), "/target/reports", BindMode.READ_WRITE); - - try + .withLogConsumer(new Slf4jLogConsumer(LOG))) { + container.addFileSystemBind(fuzzingServer.toString(), "/config/fuzzingserver.json", BindMode.READ_ONLY); + container.addFileSystemBind(reportDir.toString(), "/target/reports", BindMode.READ_WRITE); container.start(); Integer mappedPort = container.getMappedPort(9001); CoreAutobahnClient.main(new String[]{"localhost", mappedPort.toString()}); - } - finally - { - container.stop(); + IO.copy(reportDir.toFile(), baseDir.resolve("target/reports-client").toFile()); } LOG.info("Test Result Overview {}", reportDir.resolve("clients/index.html").toUri()); @@ -100,22 +98,19 @@ public class AutobahnTests final int port = 9001; org.testcontainers.Testcontainers.exposeHostPorts(port); Server server = CoreAutobahnServer.startAutobahnServer(port); - // We need to chown the generated test results so host has permissions to delete files generated by container. - GenericContainer container = new GenericContainer<>("crossbario/autobahn-testsuite:latest") + try (GenericContainer container = new GenericContainer<>("crossbario/autobahn-testsuite:latest") .withCommand("/bin/bash", "-c", "wstest -m fuzzingclient -s /config/fuzzingclient.json ; " + CHOWN_REPORTS_CMD) .withLogConsumer(new Slf4jLogConsumer(LOG)) - .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofHours(1))); - container.addFileSystemBind(fuzzingClient.toString(), "/config/fuzzingclient.json", BindMode.READ_ONLY); - container.addFileSystemBind(reportDir.toString(), "/target/reports", BindMode.READ_WRITE); - - try + .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofHours(1)))) { + container.addFileSystemBind(fuzzingClient.toString(), "/config/fuzzingclient.json", BindMode.READ_ONLY); + container.addFileSystemBind(reportDir.toString(), "/target/reports", BindMode.READ_WRITE); container.start(); + IO.copy(reportDir.toFile(), baseDir.resolve("target/reports-server").toFile()); } finally { - container.stop(); server.stop(); } diff --git a/pom.xml b/pom.xml index 94d9e94776e..1d7a3317df4 100644 --- a/pom.xml +++ b/pom.xml @@ -1145,6 +1145,11 @@ jnr-unixsocket 0.38.3 + + net.java.dev.jna + jna + 5.5.0 + org.apache.derby derby