From 38cf08fe0d68935d0d88062a7f01eb48c53bc4b8 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Tue, 16 Apr 2024 15:21:34 +0200 Subject: [PATCH 1/2] Upgrade org.testcontainers to version compatible with podman and version that dependency version explicitly (fixes #326) --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 6a05f60..65a85e2 100644 --- a/pom.xml +++ b/pom.xml @@ -171,6 +171,12 @@ 2.17.0 test + + org.testcontainers + testcontainers + 1.19.7 + test + From 6c4b934411352d2cfc95603f3b3f4863e210ac50 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Tue, 16 Apr 2024 16:26:49 +0200 Subject: [PATCH 2/2] Update tests to always run at least one of the variants against genuine or mock service. Rename the alternative test to MockS3.. to GenuineS3.. Update readme file accordingly. --- README.md | 3 +++ .../aws/AbstractS3_PINGDiscoveryTestCase.java | 4 ++++ ...ase.java => GenuineS3_PINGDiscoveryTestCase.java} | 7 +++---- .../protocols/aws/MockS3_PINGDiscoveryTestCase.java | 12 ++++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) rename src/test/java/org/jgroups/protocols/aws/{RealS3_PINGDiscoveryTestCase.java => GenuineS3_PINGDiscoveryTestCase.java} (69%) diff --git a/README.md b/README.md index 1714ca6..2b52d05 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ mvn verify If any of the required properties are not specified tests will be skipped (uses `org.junit.Assume`). +In case credentials are not provided and running on Linux, tests will be run against mock containerized S3 instance. +These require a functioning podman or Docker environment. + # Reporting Issues Project JGroups AWS uses GitHub issues: diff --git a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java index 9e1d034..eb90128 100644 --- a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java @@ -40,6 +40,10 @@ public abstract class AbstractS3_PINGDiscoveryTestCase { // credentials (e.g. running JDK8 and JDK9 on the CI). public static final String RANDOM_CLUSTER_NAME = UUID.randomUUID().toString(); + static boolean isGenuineCredentialsAvailable() { + return System.getenv("AWS_ACCESS_KEY_ID") != null && System.getenv("AWS_SECRET_ACCESS_KEY") != null && System.getenv("S3_PING_BUCKET_NAME") != null; + } + @Test public void testDiscovery() throws Exception { discover(RANDOM_CLUSTER_NAME, S3_PING.class.getSimpleName()); diff --git a/src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java similarity index 69% rename from src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java rename to src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java index aebf532..88c22ae 100644 --- a/src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java @@ -20,15 +20,14 @@ import org.junit.BeforeClass; /** - * Tests against real S3 endpoint requiring credentials. + * Tests against genuine S3 endpoint requiring credentials. * * @author Radoslav Husar */ -public class RealS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCase { +public class GenuineS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCase { @BeforeClass public static void assumeCredentials() { - Assume.assumeTrue("Credentials are not available, test is ignored!", System.getenv("AWS_ACCESS_KEY_ID") != null && System.getenv("AWS_SECRET_ACCESS_KEY") != null && System.getenv("S3_PING_BUCKET_NAME") != null); + Assume.assumeTrue("Credentials are not available, test will be ignored!", isGenuineCredentialsAvailable()); } - } diff --git a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java index fa6cdc6..4baec42 100644 --- a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java @@ -17,13 +17,16 @@ package org.jgroups.protocols.aws; import com.adobe.testing.s3mock.testcontainers.S3MockContainer; +import org.jgroups.util.Util; import org.junit.AfterClass; import org.junit.Assume; import org.junit.BeforeClass; import org.testcontainers.DockerClientFactory; +import static org.junit.Assert.fail; + /** - * Tests against a mock S3 service. + * Tests against a containerized mock S3 service. * * @author Radoslav Husar */ @@ -33,7 +36,12 @@ public class MockS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCa @BeforeClass public static void setUp() { - Assume.assumeTrue("Docker environment is not available - skipping tests against S3 mock service.", isDockerAvailable()); + // If credentials are available, we can conditionally skip Mock tests + if (isGenuineCredentialsAvailable() || (!isDockerAvailable() && !Util.checkForLinux())) { + Assume.assumeTrue("Podman/Docker environment is not available - skipping tests against S3 mock service.", isDockerAvailable()); + } else if (!isDockerAvailable()) { + fail("Credentials are not provided, thus Podman/Docker on Linux is required to run tests against a mock service!"); + } // TODO Since 3.3.0 the obscure cluster name tests start to fail. Manage the version manually and keep on '3.2.0' for now. s3Mock = new S3MockContainer("3.2.0");