File tree Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -95,8 +95,8 @@ private class DeferredListenableFuture<T>(
95
95
deferred.invokeOnCompletion {
96
96
try {
97
97
set(deferred.getCompleted())
98
- } catch (exception : Exception ) {
99
- setException(exception )
98
+ } catch (t : Throwable ) {
99
+ setException(t )
100
100
}
101
101
}
102
102
}
Original file line number Diff line number Diff line change @@ -153,6 +153,21 @@ class ListenableFutureTest : TestBase() {
153
153
finish(4 )
154
154
}
155
155
156
+ @Test
157
+ fun testAsListenableFutureThrowable () {
158
+ val deferred = async {
159
+ throw OutOfMemoryError ()
160
+ }
161
+
162
+ val future = deferred.asListenableFuture()
163
+ try {
164
+ future.get()
165
+ } catch (e: ExecutionException ) {
166
+ assertTrue(future.isDone)
167
+ assertTrue(e.cause is OutOfMemoryError )
168
+ }
169
+ }
170
+
156
171
@Test
157
172
fun testCancellableAwait () = runBlocking {
158
173
expect(1 )
Original file line number Diff line number Diff line change @@ -93,8 +93,8 @@ public fun <T> Deferred<T>.asCompletableFuture(): CompletableFuture<T> {
93
93
invokeOnCompletion {
94
94
try {
95
95
future.complete(getCompleted())
96
- } catch (exception : Exception ) {
97
- future.completeExceptionally(exception )
96
+ } catch (t : Throwable ) {
97
+ future.completeExceptionally(t )
98
98
}
99
99
}
100
100
return future
Original file line number Diff line number Diff line change @@ -21,16 +21,6 @@ class FutureTest : TestBase() {
21
21
ignoreLostThreads(" ForkJoinPool.commonPool-worker-" )
22
22
}
23
23
24
- @Test
25
- fun testSimpleAwait () {
26
- val future = future {
27
- CompletableFuture .supplyAsync {
28
- " O"
29
- }.await() + " K"
30
- }
31
- assertThat(future.get(), IsEqual (" OK" ))
32
- }
33
-
34
24
@Test
35
25
fun testCompletedFuture () {
36
26
val toAwait = CompletableFuture <String >()
@@ -186,6 +176,21 @@ class FutureTest : TestBase() {
186
176
finish(4 )
187
177
}
188
178
179
+ @Test
180
+ fun testAsCompletableFutureThrowable () {
181
+ val deferred = async {
182
+ throw OutOfMemoryError ()
183
+ }
184
+
185
+ val future = deferred.asCompletableFuture()
186
+ try {
187
+ future.get()
188
+ } catch (e: ExecutionException ) {
189
+ assertTrue(future.isCompletedExceptionally)
190
+ assertTrue(e.cause is OutOfMemoryError )
191
+ }
192
+ }
193
+
189
194
@Test
190
195
fun testCancellableAwaitFuture () = runBlocking {
191
196
expect(1 )
You can’t perform that action at this time.
0 commit comments