|
1 | 1 | package dev.zarr.zarrjava; |
2 | 2 |
|
3 | | -import com.adobe.testing.s3mock.testcontainers.S3MockContainer; |
4 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 4 | import dev.zarr.zarrjava.core.*; |
6 | 5 | import dev.zarr.zarrjava.store.*; |
|
10 | 9 | import org.junit.jupiter.params.ParameterizedTest; |
11 | 10 | import org.junit.jupiter.params.provider.CsvSource; |
12 | 11 | import org.junit.jupiter.params.provider.MethodSource; |
13 | | -import org.testcontainers.junit.jupiter.Container; |
14 | | -import org.testcontainers.junit.jupiter.Testcontainers; |
15 | 12 | import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider; |
16 | 13 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
17 | 14 | import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
18 | | -import software.amazon.awssdk.http.SdkHttpClient; |
19 | | -import software.amazon.awssdk.http.apache.ApacheHttpClient; |
20 | 15 | import software.amazon.awssdk.regions.Region; |
21 | 16 | import software.amazon.awssdk.services.s3.S3Client; |
22 | 17 | import software.amazon.awssdk.services.s3.S3Configuration; |
23 | | -import software.amazon.awssdk.utils.AttributeMap; |
24 | 18 |
|
25 | 19 | import java.io.IOException; |
26 | 20 | import java.io.InputStream; |
|
39 | 33 | import static dev.zarr.zarrjava.Utils.unzipFile; |
40 | 34 | import static dev.zarr.zarrjava.Utils.zipFile; |
41 | 35 | import static dev.zarr.zarrjava.v3.Node.makeObjectMapper; |
42 | | -import static software.amazon.awssdk.http.SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES; |
43 | 36 |
|
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") |
47 | 49 | class S3StoreTest { |
48 | | - private final String TEST_BUCKET = "test-bucket"; |
49 | | - @Container |
50 | | - private S3MockContainer s3Mock; |
51 | | - private S3Client s3Client; |
52 | 50 |
|
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; |
61 | 54 |
|
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(); |
72 | 69 | } |
73 | 70 |
|
74 | 71 | @Test |
75 | 72 | void testReadWriteS3Store() { |
76 | | - S3Store s3Store = new S3Store(s3Client, TEST_BUCKET, ""); |
| 73 | + S3Store s3Store = new S3Store(s3Client, bucket, ""); |
77 | 74 |
|
78 | 75 | StoreHandle storeHandle = s3Store.resolve("testfile"); |
79 | 76 | byte[] testData = new byte[100]; |
|
0 commit comments