1
1
package apoc .util .s3 ;
2
2
3
+ import com .amazonaws .AmazonClientException ;
3
4
import com .amazonaws .services .s3 .AmazonS3 ;
4
5
import com .amazonaws .services .s3 .model .S3Object ;
5
6
import com .amazonaws .services .s3 .model .S3ObjectInputStream ;
6
7
import com .amazonaws .util .IOUtils ;
8
+ import org .neo4j .test .assertion .Assert ;
7
9
8
10
import java .io .IOException ;
9
11
import java .net .MalformedURLException ;
10
12
import java .net .URL ;
13
+ import java .util .concurrent .TimeUnit ;
11
14
12
15
import static org .junit .Assert .assertEquals ;
13
16
@@ -21,7 +24,7 @@ public class S3TestUtil {
21
24
* @param s3Url String containing url to S3 bucket.
22
25
* @return the s3 string object
23
26
*/
24
- public static String readS3FileToString (String s3Url ) {
27
+ public static String readS3FileToString (String s3Url ) throws AmazonClientException {
25
28
try {
26
29
S3Object s3object = getS3Object (s3Url );
27
30
S3ObjectInputStream inputStream = s3object .getObjectContent ();
@@ -31,17 +34,27 @@ public static String readS3FileToString(String s3Url) {
31
34
}
32
35
}
33
36
34
- public static S3Object getS3Object (String s3Url ) throws MalformedURLException {
37
+ public static S3Object getS3Object (String s3Url ) throws MalformedURLException , AmazonClientException {
35
38
S3Params s3Params = S3ParamsExtractor .extract (new URL (s3Url ));
36
39
S3Aws s3Aws = new S3Aws (s3Params , s3Params .getRegion ());
37
40
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 ());
41
43
}
42
44
43
45
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 );
46
59
}
47
60
}
0 commit comments