Skip to content

Commit f0c7138

Browse files
committed
Updated AsyncS3ObjectIterator to improve code coverage
1 parent 1792986 commit f0c7138

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ext {
1414
}
1515

1616
group = 'me.aneeshneelam'
17-
version = '1.0'
17+
version = '1.1'
1818

1919
java {
2020
sourceCompatibility JavaVersion.VERSION_1_8

src/main/java/me/aneeshneelam/lib/aws/s3/v2/AsyncS3ObjectIterator.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ private void setListObjectsV2ResponsePaginationState(ListObjectsV2Response listO
6262

6363
@Override
6464
public boolean hasNext() {
65-
try {
66-
return this.checkListObjectsV2ResponseState()
67-
.thenApply(aVoid -> this.s3ObjectIterator.hasNext())
68-
.get(requestTimeoutDuration.getSeconds(), TimeUnit.SECONDS);
69-
} catch (InterruptedException | ExecutionException | TimeoutException e) {
70-
throw new RuntimeException(e);
71-
}
65+
CompletableFuture<Boolean> booleanCompletableFuture = this.checkListObjectsV2ResponseState()
66+
.thenApply(aVoid -> this.s3ObjectIterator.hasNext());
67+
return this.completableFutureGet(booleanCompletableFuture);
7268
}
7369

7470
@Override
7571
public S3Object next() {
72+
CompletableFuture<S3Object> s3ObjectCompletableFuture = this.checkListObjectsV2ResponseState()
73+
.thenApply(aVoid -> this.s3ObjectIterator.next());
74+
return this.completableFutureGet(s3ObjectCompletableFuture);
75+
}
76+
77+
private <T> T completableFutureGet(CompletableFuture<T> completableFuture) {
7678
try {
77-
return this.checkListObjectsV2ResponseState()
78-
.thenApply(aVoid -> this.s3ObjectIterator.next())
79-
.get(requestTimeoutDuration.getSeconds(), TimeUnit.SECONDS);
79+
return completableFuture.get(this.requestTimeoutDuration.getSeconds(), TimeUnit.SECONDS);
8080
} catch (InterruptedException | ExecutionException | TimeoutException e) {
8181
throw new RuntimeException(e);
8282
}

0 commit comments

Comments
 (0)