Skip to content

Commit 551bd72

Browse files
authored
[0eSjZq6Q] Fix S3 failing flaky tests (neo4j/apoc#294) (#3448)
1 parent c3e2a29 commit 551bd72

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

core/src/test/java/apoc/util/s3/S3TestUtil.java

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package apoc.util.s3;
22

3+
import com.amazonaws.AmazonClientException;
34
import com.amazonaws.services.s3.AmazonS3;
45
import com.amazonaws.services.s3.model.S3Object;
56
import com.amazonaws.services.s3.model.S3ObjectInputStream;
67
import com.amazonaws.util.IOUtils;
8+
import org.neo4j.test.assertion.Assert;
79

810
import java.io.IOException;
911
import java.net.MalformedURLException;
1012
import java.net.URL;
13+
import java.util.concurrent.TimeUnit;
1114

1215
import static org.junit.Assert.assertEquals;
1316

@@ -21,7 +24,7 @@ public class S3TestUtil {
2124
* @param s3Url String containing url to S3 bucket.
2225
* @return the s3 string object
2326
*/
24-
public static String readS3FileToString(String s3Url) {
27+
public static String readS3FileToString(String s3Url) throws AmazonClientException {
2528
try {
2629
S3Object s3object = getS3Object(s3Url);
2730
S3ObjectInputStream inputStream = s3object.getObjectContent();
@@ -31,17 +34,27 @@ public static String readS3FileToString(String s3Url) {
3134
}
3235
}
3336

34-
public static S3Object getS3Object(String s3Url) throws MalformedURLException {
37+
public static S3Object getS3Object(String s3Url) throws MalformedURLException, AmazonClientException {
3538
S3Params s3Params = S3ParamsExtractor.extract(new URL(s3Url));
3639
S3Aws s3Aws = new S3Aws(s3Params, s3Params.getRegion());
3740
AmazonS3 s3Client = s3Aws.getClient();
38-
39-
S3Object s3object = s3Client.getObject(s3Params.getBucket(), s3Params.getKey());
40-
return s3object;
41+
42+
return s3Client.getObject(s3Params.getBucket(), s3Params.getKey());
4143
}
4244

4345
public static void assertStringFileEquals(String expected, String s3Url) {
44-
final String actual = readS3FileToString(s3Url);
45-
assertEquals(expected, actual);
46+
Assert.assertEventually(() -> {
47+
final String actual;
48+
try {
49+
actual = readS3FileToString(s3Url);
50+
} catch (AmazonClientException e) {
51+
if (e.getMessage().contains("The specified key does not exist")) {
52+
return false;
53+
}
54+
throw e;
55+
}
56+
assertEquals(expected, actual);
57+
return true;
58+
}, v -> v, 30L, TimeUnit.SECONDS);
4659
}
4760
}

0 commit comments

Comments
 (0)