Skip to content

Commit ad4a338

Browse files
authored
test: enable integration tests against real S3 (fixes #1899) (#1951)
* test: enable integration tests against real S3 (fixes #1899) * avoid overwriting task settins of root project. * refactored method checking MinIO availability. * added documentation about running integration tests against S3. * split method checking backend availability for readability. * fixed invalid endpoint URL in example cmdline.
1 parent e25e01a commit ad4a338

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

extensions/common/aws/aws-test/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# AWS Test
22

3+
## Local testing using MinIO
4+
35
To run AWS integration tests you will need a MinIO instance running:
46
```
57
docker run -d -p 9000:9000 -e MINIO_ROOT_USER=root -e MINIO_ROOT_PASSWORD=password bitnami/minio:latest
@@ -10,3 +12,23 @@ Then set the two environment variables:
1012
S3_ACCESS_KEY_ID=root
1113
S3_SECRET_ACCESS_KEY=password
1214
```
15+
16+
## Test using your AWS credential
17+
18+
`IT_AWS_ENDPOINT` can be used to override [endpoint](https://docs.aws.amazon.com/general/latest/gr/s3.html) URI
19+
for running integration tests against AWS S3 by environment variable:
20+
21+
```
22+
$ IT_AWS_ENDPOINT=https://s3.us-east-1.amazonaws.com/ \
23+
IT_AWS_REGION=us-east-1 \
24+
IT_AWS_PROFILE=myprofie \
25+
./gradlew clean test -DincludeTags="AwsS3IntegrationTest" --tests '*S3StatusCheckerIntegrationTest'
26+
```
27+
28+
`IT_AWS_REGION` must be set to your region code in order to avoid
29+
["A conflicting conditional operation is currently in progress against this resource." error](http://stackoverflow.com/questions/13898057/aws-error-message-a-conflicting-conditional-operation-is-currently-in-progress).
30+
31+
`IT_AWS_PROFILE` can be used to specify
32+
[named profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
33+
referring your own credential.
34+
You can also use access key and secret access key by `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY`.

extensions/common/aws/aws-test/src/testFixtures/java/org/eclipse/dataspaceconnector/aws/testfixtures/AbstractS3Test.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*
1010
* Contributors:
1111
* Microsoft Corporation - initial API and implementation
12+
* NTT DATA - added endpoint override
1213
*
1314
*/
1415

@@ -59,13 +60,14 @@
5960
*/
6061
public abstract class AbstractS3Test {
6162

62-
protected static final String REGION = System.getProperty("it.aws.region", Region.US_EAST_1.id());
63+
protected static final String REGION = propOrEnv("it.aws.region", Region.US_EAST_1.id());
6364
// Adding REGION to bucket prevents errors of
6465
// "A conflicting conditional operation is currently in progress against this resource."
6566
// when bucket is rapidly added/deleted and consistency propagation causes this error.
6667
// (Should not be necessary if REGION remains static, but added to prevent future frustration.)
6768
// [see http://stackoverflow.com/questions/13898057/aws-error-message-a-conflicting-conditional-operation-is-currently-in-progress]
68-
protected static final URI S3_ENDPOINT = URI.create("http://localhost:9000");
69+
protected static final String MINIO_ENDPOINT = "http://localhost:9000";
70+
protected static final URI S3_ENDPOINT = URI.create(propOrEnv("it.aws.endpoint", MINIO_ENDPOINT));
6971
protected final UUID processId = UUID.randomUUID();
7072
protected String bucketName = createBucketName();
7173
protected S3AsyncClient s3AsyncClient;
@@ -83,15 +85,27 @@ static void prepareAll() {
8385
.pollInterval(Duration.ofSeconds(2))
8486
.ignoreException(IOException.class) // thrown by pingMinio
8587
.ignoreException(ConnectException.class)
86-
.until(AbstractS3Test::pingMinio);
88+
.until(AbstractS3Test::isBackendAvailable);
89+
}
90+
91+
private static boolean isBackendAvailable() throws IOException {
92+
if (isMinio()) {
93+
return isMinioAvailable();
94+
} else {
95+
return true;
96+
}
97+
}
98+
99+
private static boolean isMinio() {
100+
return MINIO_ENDPOINT.equals(S3_ENDPOINT.toString());
87101
}
88102

89103
/**
90104
* pings <a href="https://docs.min.io/minio/baremetal/monitoring/healthcheck-probe.html">MinIO's health endpoint</a>
91105
*
92106
* @return true if HTTP status [200..300[
93107
*/
94-
private static boolean pingMinio() throws IOException {
108+
private static boolean isMinioAvailable() throws IOException {
95109
var httpClient = new OkHttpClient();
96110
var healthRq = new Request.Builder().url(S3_ENDPOINT + "/minio/health/live").get().build();
97111
try (var response = httpClient.newCall(healthRq).execute()) {
@@ -158,7 +172,7 @@ protected void putStringOnBucket(String bucketName, String key, String content)
158172
}
159173

160174
protected @NotNull AwsCredentials getCredentials() {
161-
String profile = propOrEnv("AWS_PROFILE", null);
175+
var profile = propOrEnv("it.aws.profile", null);
162176
if (profile != null) {
163177
return ProfileCredentialsProvider.create(profile).resolveCredentials();
164178
}

0 commit comments

Comments
 (0)