Skip to content

Commit c64ea1c

Browse files
committed
run S3 Mock with docker
1 parent 8d5d583 commit c64ea1c

3 files changed

Lines changed: 59 additions & 66 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v5
2323

24+
- name: Start S3Mock
25+
if: runner.os != 'macOS'
26+
run: |
27+
docker run -d -p 9090:9090 -p 9191:9191 \
28+
--name s3mock \
29+
-e "initialBuckets=zarr-test-bucket" \
30+
adobe/s3mock:3.11.0
31+
32+
# TODO: move this waiting logic right in front of the tests that need it
33+
- name: Wait for S3Mock
34+
if: runner.os != 'macOS'
35+
run: |
36+
echo "Waiting for S3Mock to start..."
37+
for i in {1..30}; do
38+
if curl -s http://localhost:9090/favicon.ico > /dev/null; then
39+
echo "S3Mock is up!"
40+
exit 0
41+
fi
42+
sleep 2
43+
done
44+
echo "S3Mock failed to start"
45+
exit 1
2446
- name: Set up JDK
2547
uses: actions/setup-java@v4
2648
with:
@@ -49,8 +71,13 @@ jobs:
4971
- name: Test
5072
env:
5173
MAVEN_OPTS: "-Xmx6g"
52-
run: mvn --no-transfer-progress test -DargLine="-Xmx6g"
53-
74+
SKIP_S3_TESTS: ${{ matrix.os == 'macos-latest' }}
75+
run: |
76+
if [ "$SKIP_S3_TESTS" = "true" ]; then
77+
mvn --no-transfer-progress test -DargLine="-Xmx6g" -Dgroups="!s3"
78+
else
79+
mvn --no-transfer-progress test -DargLine="-Xmx6g"
80+
fi
5481
- name: Assemble JAR
5582
run: mvn package -DskipTests
5683

pom.xml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,37 +126,6 @@
126126
<artifactId>commons-compress</artifactId>
127127
<version>1.28.0</version>
128128
</dependency>
129-
<dependency>
130-
<groupId>com.adobe.testing</groupId>
131-
<artifactId>s3mock</artifactId>
132-
<version>2.17.0</version>
133-
<scope>test</scope>
134-
</dependency>
135-
<dependency>
136-
<groupId>com.adobe.testing</groupId>
137-
<artifactId>s3mock-testcontainers</artifactId>
138-
<version>2.17.0</version>
139-
<scope>test</scope>
140-
</dependency>
141-
<dependency>
142-
<groupId>org.testcontainers</groupId>
143-
<artifactId>junit-jupiter</artifactId>
144-
<version>1.20.4</version>
145-
<scope>test</scope>
146-
</dependency>
147-
<dependency>
148-
<groupId>org.testcontainers</groupId>
149-
<artifactId>testcontainers</artifactId>
150-
<version>1.20.4</version>
151-
<scope>test</scope>
152-
</dependency>
153-
<!-- Add/Update Logback to a version compatible with SLF4J 2.0 (Java 11+) -->
154-
<dependency>
155-
<groupId>ch.qos.logback</groupId>
156-
<artifactId>logback-classic</artifactId>
157-
<version>1.4.14</version>
158-
<scope>test</scope>
159-
</dependency>
160129
</dependencies>
161130

162131
<repositories>

src/test/java/dev/zarr/zarrjava/ZarrStoreTest.java

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.zarr.zarrjava;
22

3-
import com.adobe.testing.s3mock.testcontainers.S3MockContainer;
43
import com.fasterxml.jackson.databind.ObjectMapper;
54
import dev.zarr.zarrjava.core.*;
65
import dev.zarr.zarrjava.store.*;
@@ -10,17 +9,12 @@
109
import org.junit.jupiter.params.ParameterizedTest;
1110
import org.junit.jupiter.params.provider.CsvSource;
1211
import org.junit.jupiter.params.provider.MethodSource;
13-
import org.testcontainers.junit.jupiter.Container;
14-
import org.testcontainers.junit.jupiter.Testcontainers;
1512
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
1613
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
1714
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
18-
import software.amazon.awssdk.http.SdkHttpClient;
19-
import software.amazon.awssdk.http.apache.ApacheHttpClient;
2015
import software.amazon.awssdk.regions.Region;
2116
import software.amazon.awssdk.services.s3.S3Client;
2217
import software.amazon.awssdk.services.s3.S3Configuration;
23-
import software.amazon.awssdk.utils.AttributeMap;
2418

2519
import java.io.IOException;
2620
import java.io.InputStream;
@@ -39,41 +33,44 @@
3933
import static dev.zarr.zarrjava.Utils.unzipFile;
4034
import static dev.zarr.zarrjava.Utils.zipFile;
4135
import static dev.zarr.zarrjava.v3.Node.makeObjectMapper;
42-
import static software.amazon.awssdk.http.SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES;
4336

44-
45-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
46-
@Testcontainers
37+
/**
38+
* Tests for S3Store
39+
* <p>
40+
* Requires a local S3 mock server running at http://localhost:9090
41+
* with a bucket named "zarr-test-bucket"
42+
* <p>
43+
* Execute the following command to start a local S3 mock server:
44+
* <pre>
45+
* docker run -p 9090:9090 -p 9191:9191 -e "initialBuckets=zarr-test-bucket" adobe/s3mock:3.11.0
46+
* </pre>
47+
*/
48+
@Tag("s3")
4749
class S3StoreTest {
48-
private final String TEST_BUCKET = "test-bucket";
49-
@Container
50-
private S3MockContainer s3Mock;
51-
private S3Client s3Client;
5250

53-
@BeforeAll
54-
void setUp() {
55-
s3Mock = new S3MockContainer("latest").withInitialBuckets(TEST_BUCKET);
56-
s3Mock.start();
57-
SdkHttpClient httpClient = ApacheHttpClient.builder().buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, Boolean.TRUE).build());
58-
s3Client = S3Client.builder().endpointOverride(URI.create(s3Mock.getHttpsEndpoint())).serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build()).credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_EAST_1) // required, but ignored
59-
.httpClient(httpClient).build();
60-
}
51+
static String s3Endpoint = "http://localhost:9090";
52+
static String bucket = "zarr-test-bucket";
53+
static S3Client s3Client;
6154

62-
@AfterAll
63-
void tearDown() {
64-
if (s3Mock.isRunning()) {
65-
s3Mock.stop();
66-
}
67-
}
68-
69-
@Test
70-
void testS3Mock() {
71-
Assertions.assertTrue(s3Mock.isRunning());
55+
@BeforeAll
56+
static void setUp() {
57+
s3Client = S3Client.builder()
58+
.endpointOverride(URI.create(s3Endpoint))
59+
.region(Region.US_EAST_1) // required, but ignored
60+
.serviceConfiguration(
61+
S3Configuration.builder()
62+
.pathStyleAccessEnabled(true) // required
63+
.build()
64+
)
65+
.credentialsProvider(StaticCredentialsProvider.create(
66+
AwsBasicCredentials.create("accessKey", "secretKey")
67+
))
68+
.build();
7269
}
7370

7471
@Test
7572
void testReadWriteS3Store() {
76-
S3Store s3Store = new S3Store(s3Client, TEST_BUCKET, "");
73+
S3Store s3Store = new S3Store(s3Client, bucket, "");
7774

7875
StoreHandle storeHandle = s3Store.resolve("testfile");
7976
byte[] testData = new byte[100];

0 commit comments

Comments
 (0)