File tree 2 files changed +32
-7
lines changed
main/java/reactor/core/publisher
test/java/reactor/core/publisher
2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2016-2021 VMware Inc. or its affiliates, All Rights Reserved.
2
+ * Copyright (c) 2016-2022 VMware Inc. or its affiliates, All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .concurrent .CancellationException ;
21
21
import java .util .concurrent .CompletionException ;
22
22
import java .util .concurrent .CompletionStage ;
23
+ import java .util .concurrent .Future ;
23
24
24
25
import reactor .core .CoreSubscriber ;
25
26
import reactor .core .Exceptions ;
@@ -47,7 +48,15 @@ final class MonoCompletionStage<T> extends Mono<T>
47
48
@ Override
48
49
public void subscribe (CoreSubscriber <? super T > actual ) {
49
50
Operators .MonoSubscriber <T , T >
50
- sds = new Operators .MonoSubscriber <>(actual );
51
+ sds = new Operators .MonoSubscriber <T , T >(actual ) {
52
+ @ Override
53
+ public void cancel () {
54
+ super .cancel ();
55
+ if (future instanceof Future ) {
56
+ ((Future <?>) future ).cancel (true );
57
+ }
58
+ }
59
+ };
51
60
52
61
actual .onSubscribe (sds );
53
62
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2015-2021 VMware Inc. or its affiliates, All Rights Reserved.
2
+ * Copyright (c) 2015-2022 VMware Inc. or its affiliates, All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
33
33
public class
34
34
MonoCompletionStageTest {
35
35
36
+ //https://github.com/reactor/reactor-core/issues/3138
37
+ @ Test
38
+ public void propagateCancellationToCompletionFuture () {
39
+ CompletableFuture <Integer > future = new CompletableFuture <>();
40
+
41
+ Mono <Integer > mono = Mono
42
+ .fromFuture (future );
43
+
44
+ StepVerifier .create (mono )
45
+ .expectSubscription ()
46
+ .thenCancel ()
47
+ .verify ();
48
+
49
+ assertThat (future ).isCancelled ();
50
+ }
51
+
36
52
@ Test
37
53
public void cancelThenFutureFails () {
38
54
CompletableFuture <Integer > future = new CompletableFuture <>();
@@ -45,13 +61,13 @@ public void cancelThenFutureFails() {
45
61
StepVerifier .create (mono )
46
62
.expectSubscription ()
47
63
.then (() -> {
48
- subRef .get ().cancel ();
49
- future .completeExceptionally (new IllegalStateException ("boom" ));
50
- future .complete (1 );
64
+ subRef .get ().cancel ();
65
+ future .completeExceptionally (new IllegalStateException ("boom" ));
66
+ future .complete (1 );
51
67
})
52
68
.thenCancel ()//already cancelled but need to get to verification
53
69
.verifyThenAssertThat ()
54
- .hasDroppedErrorWithMessage ( "boom" );
70
+ .hasNotDroppedErrors ( );
55
71
}
56
72
57
73
@ Test
You can’t perform that action at this time.
0 commit comments