diff --git a/presto-main/src/test/java/io/prestosql/tests/LogTestDurationListener.java b/presto-main/src/test/java/io/prestosql/tests/LogTestDurationListener.java index ea5ed4d8ef37..49cf8a8e21f0 100644 --- a/presto-main/src/test/java/io/prestosql/tests/LogTestDurationListener.java +++ b/presto-main/src/test/java/io/prestosql/tests/LogTestDurationListener.java @@ -48,6 +48,10 @@ public class LogTestDurationListener { private static final Logger LOG = Logger.get(LogTestDurationListener.class); + // LogTestDurationListener does not support concurrent invocations of same test method + // (@Test(threadPoolSize=n)), so we need kill switch for local development purposes. + private static final boolean enabled = Boolean.getBoolean("LogTestDurationListener.enabled"); + private static final Duration SINGLE_TEST_LOGGING_THRESHOLD = Duration.valueOf("30s"); private static final Duration CLASS_LOGGING_THRESHOLD = Duration.valueOf("1m"); // Must be below Travis "no output" timeout (10m). E.g. TestElasticsearchIntegrationSmokeTest is known to take ~5-6m. @@ -70,6 +74,10 @@ public LogTestDurationListener() @Override public synchronized void onExecutionStart() { + if (!enabled) { + return; + } + resetHangMonitor(); finished.set(false); if (monitorHangTask == null) { @@ -80,6 +88,10 @@ public synchronized void onExecutionStart() @Override public synchronized void onExecutionFinish() { + if (!enabled) { + return; + } + resetHangMonitor(); finished.set(true); // do not stop hang task so notification of hung test JVM will fire @@ -133,12 +145,20 @@ private void resetHangMonitor() @Override public void onBeforeClass(ITestClass testClass) { + if (!enabled) { + return; + } + beginTest(getName(testClass)); } @Override public void onAfterClass(ITestClass testClass) { + if (!enabled) { + return; + } + String name = getName(testClass); Duration duration = endTest(name); if (duration.compareTo(CLASS_LOGGING_THRESHOLD) > 0) { @@ -149,12 +169,20 @@ public void onAfterClass(ITestClass testClass) @Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { + if (!enabled) { + return; + } + beginTest(getName(method)); } @Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { + if (!enabled) { + return; + } + String name = getName(method); Duration duration = endTest(name); if (duration.compareTo(SINGLE_TEST_LOGGING_THRESHOLD) > 0) { diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/EnvironmentUp.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/EnvironmentUp.java index 20451a2bd98a..7199088e8456 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/EnvironmentUp.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/EnvironmentUp.java @@ -21,12 +21,12 @@ import io.airlift.log.Logger; import io.prestosql.tests.product.launcher.Extensions; import io.prestosql.tests.product.launcher.LauncherModule; +import io.prestosql.tests.product.launcher.docker.ContainerUtil; import io.prestosql.tests.product.launcher.env.Environment; import io.prestosql.tests.product.launcher.env.EnvironmentFactory; import io.prestosql.tests.product.launcher.env.EnvironmentModule; import io.prestosql.tests.product.launcher.env.EnvironmentOptions; import io.prestosql.tests.product.launcher.env.Environments; -import io.prestosql.tests.product.launcher.testcontainers.TestcontainersUtil; import org.testcontainers.DockerClientFactory; import javax.inject.Inject; @@ -132,7 +132,7 @@ private void killContainersReaperContainer() { try (DockerClient dockerClient = DockerClientFactory.lazyClient()) { log.info("Killing the testcontainers reaper container (Ryuk) so that environment can stay alive"); - TestcontainersUtil.killContainersReaperContainer(dockerClient); + ContainerUtil.killContainersReaperContainer(dockerClient); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/TestRun.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/TestRun.java index a185b1fcf1bc..f810d955be26 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/TestRun.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/cli/TestRun.java @@ -43,8 +43,8 @@ import static com.google.common.base.Preconditions.checkState; import static io.prestosql.tests.product.launcher.cli.Commands.runCommand; +import static io.prestosql.tests.product.launcher.docker.ContainerUtil.exposePort; import static io.prestosql.tests.product.launcher.env.common.Standard.CONTAINER_TEMPTO_PROFILE_CONFIG; -import static io.prestosql.tests.product.launcher.testcontainers.TestcontainersUtil.exposePort; import static java.util.Objects.requireNonNull; import static org.testcontainers.containers.BindMode.READ_ONLY; diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/ContainerUtil.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/ContainerUtil.java new file mode 100644 index 000000000000..b61a2f18cd1f --- /dev/null +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/ContainerUtil.java @@ -0,0 +1,138 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.prestosql.tests.product.launcher.docker; + +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.CreateContainerCmd; +import com.github.dockerjava.api.command.ListContainersCmd; +import com.github.dockerjava.api.command.ListNetworksCmd; +import com.github.dockerjava.api.exception.ConflictException; +import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.api.model.AccessMode; +import com.github.dockerjava.api.model.Bind; +import com.github.dockerjava.api.model.Container; +import com.github.dockerjava.api.model.Network; +import io.prestosql.tests.product.launcher.env.DockerContainer; +import org.testcontainers.DockerClientFactory; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + +import static com.google.common.base.MoreObjects.firstNonNull; +import static com.google.common.base.Preconditions.checkState; +import static io.prestosql.tests.product.launcher.docker.DockerFiles.createTemporaryDirectoryForDocker; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.Files.isRegularFile; +import static java.nio.file.Files.readAllLines; +import static java.nio.file.Files.write; +import static java.util.Objects.requireNonNull; + +public final class ContainerUtil +{ + private ContainerUtil() {} + + public static void killContainers(DockerClient dockerClient, Function filter) + { + while (true) { + ListContainersCmd listContainersCmd = filter.apply(dockerClient.listContainersCmd() + .withShowAll(true)); + + List containers = listContainersCmd.exec(); + if (containers.isEmpty()) { + break; + } + for (Container container : containers) { + try { + dockerClient.removeContainerCmd(container.getId()) + .withForce(true) + .exec(); + } + catch (ConflictException | NotFoundException ignored) { + } + } + } + } + + public static void removeNetworks(DockerClient dockerClient, Function filter) + { + ListNetworksCmd listNetworksCmd = filter.apply(dockerClient.listNetworksCmd()); + List networks = listNetworksCmd.exec(); + for (Network network : networks) { + dockerClient.removeNetworkCmd(network.getId()) + .exec(); + } + } + + public static void killContainersReaperContainer(DockerClient dockerClient) + { + @SuppressWarnings("resource") + Void ignore = dockerClient.removeContainerCmd("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID) + .withForce(true) + .exec(); + } + + public static void exposePort(DockerContainer container, int port) + { + container.addExposedPort(port); + container.withFixedExposedPort(port, port); + } + + public static void enableJavaDebugger(DockerContainer container, String jvmConfigPath, int debugPort) + { + requireNonNull(jvmConfigPath, "jvmConfigPath is null"); + container.withCreateContainerCmdModifier(createContainerCmd -> enableDebuggerInJvmConfig(createContainerCmd, jvmConfigPath, debugPort)); + exposePort(container, debugPort); + } + + private static void enableDebuggerInJvmConfig(CreateContainerCmd createContainerCmd, String jvmConfigPath, int debugPort) + { + try { + Bind[] binds = firstNonNull(createContainerCmd.getBinds(), new Bind[0]); + boolean found = false; + + // Last bind wins, so we can find the last one only + for (int bindIndex = binds.length - 1; bindIndex >= 0; bindIndex--) { + Bind bind = binds[bindIndex]; + if (!bind.getVolume().getPath().equals(jvmConfigPath)) { + continue; + } + + Path hostJvmConfig = Paths.get(bind.getPath()); + checkState(isRegularFile(hostJvmConfig), "Bind for %s is not a file", jvmConfigPath); + + Path temporaryDirectory = createTemporaryDirectoryForDocker(); + Path newJvmConfig = temporaryDirectory.resolve("jvm.config"); + + List jvmOptions = new ArrayList<>(readAllLines(hostJvmConfig, UTF_8)); + jvmOptions.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:" + debugPort); + write(newJvmConfig, jvmOptions, UTF_8); + + binds[bindIndex] = new Bind(newJvmConfig.toString(), bind.getVolume(), AccessMode.ro, bind.getSecMode(), bind.getNoCopy(), bind.getPropagationMode()); + found = true; + break; + } + + checkState(found, "Could not find %s bind", jvmConfigPath); + createContainerCmd.withBinds(binds); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/DockerUtil.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/DockerUtil.java deleted file mode 100644 index 5823e01faca0..000000000000 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/docker/DockerUtil.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.prestosql.tests.product.launcher.docker; - -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.ListContainersCmd; -import com.github.dockerjava.api.command.ListNetworksCmd; -import com.github.dockerjava.api.exception.ConflictException; -import com.github.dockerjava.api.exception.NotFoundException; -import com.github.dockerjava.api.model.Container; -import com.github.dockerjava.api.model.Network; - -import java.util.List; -import java.util.function.Function; - -public final class DockerUtil -{ - private DockerUtil() {} - - public static void killContainers(DockerClient dockerClient, Function filter) - { - while (true) { - ListContainersCmd listContainersCmd = filter.apply(dockerClient.listContainersCmd() - .withShowAll(true)); - - List containers = listContainersCmd.exec(); - if (containers.isEmpty()) { - break; - } - for (Container container : containers) { - try { - dockerClient.removeContainerCmd(container.getId()) - .withForce(true) - .exec(); - } - catch (ConflictException | NotFoundException ignored) { - } - } - } - } - - public static void removeNetworks(DockerClient dockerClient, Function filter) - { - ListNetworksCmd listNetworksCmd = filter.apply(dockerClient.listNetworksCmd()); - List networks = listNetworksCmd.exec(); - for (Network network : networks) { - dockerClient.removeNetworkCmd(network.getId()) - .exec(); - } - } -} diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/Environments.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/Environments.java index 6d8589122b0d..9a7ce82a7e2f 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/Environments.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/Environments.java @@ -17,7 +17,6 @@ import com.google.common.base.CaseFormat; import com.google.common.reflect.ClassPath; import io.airlift.log.Logger; -import io.prestosql.tests.product.launcher.docker.DockerUtil; import io.prestosql.tests.product.launcher.env.common.TestsEnvironment; import org.testcontainers.DockerClientFactory; import org.testcontainers.shaded.com.google.common.collect.ImmutableMap; @@ -27,6 +26,8 @@ import java.util.List; import static com.google.common.collect.ImmutableList.toImmutableList; +import static io.prestosql.tests.product.launcher.docker.ContainerUtil.killContainers; +import static io.prestosql.tests.product.launcher.docker.ContainerUtil.removeNetworks; import static io.prestosql.tests.product.launcher.env.Environment.PRODUCT_TEST_LAUNCHER_NETWORK; import static io.prestosql.tests.product.launcher.env.Environment.PRODUCT_TEST_LAUNCHER_STARTED_LABEL_NAME; import static io.prestosql.tests.product.launcher.env.Environment.PRODUCT_TEST_LAUNCHER_STARTED_LABEL_VALUE; @@ -41,10 +42,10 @@ public static void pruneEnvironment() { log.info("Shutting down previous containers"); try (DockerClient dockerClient = DockerClientFactory.lazyClient()) { - DockerUtil.killContainers( + killContainers( dockerClient, listContainersCmd -> listContainersCmd.withLabelFilter(ImmutableMap.of(PRODUCT_TEST_LAUNCHER_STARTED_LABEL_NAME, PRODUCT_TEST_LAUNCHER_STARTED_LABEL_VALUE))); - DockerUtil.removeNetworks( + removeNetworks( dockerClient, listNetworksCmd -> listNetworksCmd.withNameFilter(PRODUCT_TEST_LAUNCHER_NETWORK)); } diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/common/Standard.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/common/Standard.java index 3525db9d4cc9..765c31695a4a 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/common/Standard.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/common/Standard.java @@ -13,9 +13,6 @@ */ package io.prestosql.tests.product.launcher.env.common; -import com.github.dockerjava.api.command.CreateContainerCmd; -import com.github.dockerjava.api.model.AccessMode; -import com.github.dockerjava.api.model.Bind; import io.prestosql.tests.product.launcher.PathResolver; import io.prestosql.tests.product.launcher.docker.DockerFiles; import io.prestosql.tests.product.launcher.env.DockerContainer; @@ -29,23 +26,10 @@ import javax.inject.Inject; import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Duration; -import java.util.ArrayList; -import java.util.List; -import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; -import static io.prestosql.tests.product.launcher.docker.DockerFiles.createTemporaryDirectoryForDocker; -import static io.prestosql.tests.product.launcher.testcontainers.TestcontainersUtil.exposePort; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.nio.file.Files.isRegularFile; -import static java.nio.file.Files.readAllLines; -import static java.nio.file.Files.write; +import static io.prestosql.tests.product.launcher.docker.ContainerUtil.enableJavaDebugger; import static java.util.Objects.requireNonNull; import static org.testcontainers.containers.BindMode.READ_ONLY; @@ -76,10 +60,10 @@ public Standard( this.dockerFiles = requireNonNull(dockerFiles, "dockerFiles is null"); this.portBinder = requireNonNull(portBinder, "portBinder is null"); requireNonNull(environmentOptions, "environmentOptions is null"); - imagesVersion = requireNonNull(environmentOptions.imagesVersion, "environmentOptions.imagesVersion is null"); - serverPackage = requireNonNull(environmentOptions.serverPackage, "environmentOptions.serverPackage is null"); + this.imagesVersion = requireNonNull(environmentOptions.imagesVersion, "environmentOptions.imagesVersion is null"); + this.serverPackage = requireNonNull(environmentOptions.serverPackage, "environmentOptions.serverPackage is null"); checkArgument(serverPackage.getName().endsWith(".tar.gz"), "Currently only server .tar.gz package is supported"); - debug = environmentOptions.debug; + this.debug = environmentOptions.debug; } @Override @@ -99,8 +83,7 @@ private DockerContainer createPrestoMaster() portBinder.exposePort(container, 8080); // Presto default port if (debug) { - container.withCreateContainerCmdModifier(this::enableDebuggerInJvmConfig); - exposePort(container, 5005); // debug port + enableJavaDebugger(container, CONTAINER_PRESTO_JVM_CONFIG, 5005); // debug port } return container; @@ -130,40 +113,4 @@ public static DockerContainer createPrestoContainer(DockerFiles dockerFiles, Pat .waitingFor(Wait.forLogMessage(".*======== SERVER STARTED ========.*", 1)) .withStartupTimeout(Duration.ofMinutes(5)); } - - private void enableDebuggerInJvmConfig(CreateContainerCmd createContainerCmd) - { - try { - Bind[] binds = firstNonNull(createContainerCmd.getBinds(), new Bind[0]); - boolean found = false; - - // Last bind wins, so we can find the last one only - for (int bindIndex = binds.length - 1; bindIndex >= 0; bindIndex--) { - Bind bind = binds[bindIndex]; - if (!bind.getVolume().getPath().equals(CONTAINER_PRESTO_JVM_CONFIG)) { - continue; - } - - Path hostJvmConfig = Paths.get(bind.getPath()); - checkState(isRegularFile(hostJvmConfig), "Bind for %s is not a file", CONTAINER_PRESTO_JVM_CONFIG); - - Path temporaryDirectory = createTemporaryDirectoryForDocker(); - Path newJvmConfig = temporaryDirectory.resolve("jvm.config"); - - List jvmOptions = new ArrayList<>(readAllLines(hostJvmConfig, UTF_8)); - jvmOptions.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005"); - write(newJvmConfig, jvmOptions, UTF_8); - - binds[bindIndex] = new Bind(newJvmConfig.toString(), bind.getVolume(), AccessMode.ro, bind.getSecMode(), bind.getNoCopy(), bind.getPropagationMode()); - found = true; - break; - } - - checkState(found, "Could not find %s bind", CONTAINER_PRESTO_JVM_CONFIG); - createContainerCmd.withBinds(binds); - } - catch (IOException e) { - throw new UncheckedIOException(e); - } - } } diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/environment/Multinode.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/environment/Multinode.java index 6177d58a74d1..98d8ccd36f80 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/environment/Multinode.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/env/environment/Multinode.java @@ -28,6 +28,7 @@ import java.io.File; +import static io.prestosql.tests.product.launcher.docker.ContainerUtil.enableJavaDebugger; import static io.prestosql.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_HIVE_PROPERTIES; import static io.prestosql.tests.product.launcher.env.common.Hadoop.CONTAINER_PRESTO_ICEBERG_PROPERTIES; import static io.prestosql.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_CONFIG_PROPERTIES; @@ -45,6 +46,7 @@ public final class Multinode private final String imagesVersion; private final File serverPackage; + private final boolean debug; @Inject public Multinode( @@ -57,8 +59,9 @@ public Multinode( super(ImmutableList.of(standard, hadoop)); this.pathResolver = requireNonNull(pathResolver, "pathResolver is null"); this.dockerFiles = requireNonNull(dockerFiles, "dockerFiles is null"); - imagesVersion = requireNonNull(environmentOptions.imagesVersion, "environmentOptions.imagesVersion is null"); - serverPackage = requireNonNull(environmentOptions.serverPackage, "environmentOptions.serverPackage is null"); + this.imagesVersion = requireNonNull(environmentOptions.imagesVersion, "environmentOptions.imagesVersion is null"); + this.serverPackage = requireNonNull(environmentOptions.serverPackage, "environmentOptions.serverPackage is null"); + this.debug = environmentOptions.debug; } @Override @@ -82,6 +85,10 @@ private DockerContainer createPrestoWorker() .withFileSystemBind(dockerFiles.getDockerFilesHostPath("common/hadoop/hive.properties"), CONTAINER_PRESTO_HIVE_PROPERTIES, READ_ONLY) .withFileSystemBind(dockerFiles.getDockerFilesHostPath("common/hadoop/iceberg.properties"), CONTAINER_PRESTO_ICEBERG_PROPERTIES, READ_ONLY); + if (debug) { + enableJavaDebugger(container, CONTAINER_PRESTO_JVM_CONFIG, 5008); // debug port + } + return container; } } diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/PortBinder.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/PortBinder.java index 078a57c9447a..929c811fe9e3 100644 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/PortBinder.java +++ b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/PortBinder.java @@ -13,6 +13,7 @@ */ package io.prestosql.tests.product.launcher.testcontainers; +import io.prestosql.tests.product.launcher.docker.ContainerUtil; import io.prestosql.tests.product.launcher.env.DockerContainer; import io.prestosql.tests.product.launcher.env.EnvironmentOptions; @@ -33,7 +34,7 @@ public PortBinder(EnvironmentOptions environmentOptions) public void exposePort(DockerContainer container, int port) { if (bindPorts) { - TestcontainersUtil.exposePort(container, port); + ContainerUtil.exposePort(container, port); } else { // Still export port, at a random free number, as certain startup checks require this. diff --git a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/TestcontainersUtil.java b/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/TestcontainersUtil.java deleted file mode 100644 index 3aa74666e37b..000000000000 --- a/presto-product-tests-launcher/src/main/java/io/prestosql/tests/product/launcher/testcontainers/TestcontainersUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.prestosql.tests.product.launcher.testcontainers; - -import com.github.dockerjava.api.DockerClient; -import io.prestosql.tests.product.launcher.env.DockerContainer; -import org.testcontainers.DockerClientFactory; - -public final class TestcontainersUtil -{ - private TestcontainersUtil() {} - - public static void killContainersReaperContainer(DockerClient dockerClient) - { - @SuppressWarnings("resource") - Void ignore = dockerClient.removeContainerCmd("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID) - .withForce(true) - .exec(); - } - - public static void exposePort(DockerContainer container, int port) - { - container.addExposedPort(port); - container.withFixedExposedPort(port, port); - } -}