You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/utils/CancelOnInterruptWrapper.java
+22-3Lines changed: 22 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -48,17 +48,36 @@ public boolean isDone() {
48
48
returnf.isDone();
49
49
}
50
50
51
+
52
+
// This method attempts to cancel the wrapped future if the thread is interrupted while blocked on get(). This is done by
53
+
// attempting to cancel() the future when InterruptedException is thrown. If the the cancel() is unsuccessful (i.e.
54
+
// the future is completed either successfully or exceptionally), then get the result if present and return it.
Copy file name to clipboardExpand all lines: http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/internal/utils/CancelOnInterruptWrapperTest.java
+102-4Lines changed: 102 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -30,17 +30,24 @@
30
30
importjava.util.concurrent.Future;
31
31
importjava.util.concurrent.TimeUnit;
32
32
importjava.util.concurrent.TimeoutException;
33
+
importjava.util.concurrent.atomic.AtomicBoolean;
34
+
importorg.junit.jupiter.api.AfterEach;
33
35
importorg.junit.jupiter.api.BeforeEach;
34
36
importorg.junit.jupiter.api.Test;
35
37
36
-
publicclassCancelOnInterruptFutureTest {
38
+
publicclassCancelOnInterruptWrapperTest {
37
39
privateFuture<String> mockDelegate;
38
40
39
41
@BeforeEach
40
42
voidsetup() {
41
43
mockDelegate = mock(Future.class);
42
44
}
43
45
46
+
@AfterEach
47
+
voidteardown() {
48
+
Thread.interrupted(); // clear the flag if it was set by the last test
0 commit comments