26
26
import org .reactivestreams .Subscriber ;
27
27
import reactor .core .Disposable ;
28
28
import reactor .core .publisher .Flux ;
29
- import reactor .core .publisher .FluxSink ;
30
29
import reactor .core .publisher .Mono ;
30
+ import reactor .core .publisher .Sinks ;
31
31
import reactor .util .annotation .Nullable ;
32
32
33
33
import java .util .ArrayList ;
42
42
/**
43
43
* Test {@link Client} implementation that allows specification of expectations and assertions.
44
44
*/
45
- @ SuppressWarnings ("deprecation" )
46
45
public final class TestClient implements Client {
47
46
48
47
public static final TestClient NO_OP = new TestClient (false , true , null , null , Flux .empty (), IDLE , new Version ("9.4" ));
@@ -51,15 +50,13 @@ public final class TestClient implements Client {
51
50
52
51
private final boolean connected ;
53
52
54
- private final reactor . core . publisher . EmitterProcessor <NotificationResponse > notificationProcessor = reactor . core . publisher . EmitterProcessor . create ( false );
53
+ private final Sinks . Many <NotificationResponse > notificationProcessor = Sinks . many (). multicast (). onBackpressureBuffer ( );
55
54
56
55
private final Integer processId ;
57
56
58
- private final reactor . core . publisher . EmitterProcessor <FrontendMessage > requestProcessor = reactor . core . publisher . EmitterProcessor . create ( false );
57
+ private final Sinks . Many <FrontendMessage > requestProcessor = Sinks . many (). multicast (). onBackpressureBuffer ( );
59
58
60
- private final FluxSink <FrontendMessage > requests = this .requestProcessor .sink ();
61
-
62
- private final reactor .core .publisher .EmitterProcessor <Flux <BackendMessage >> responseProcessor = reactor .core .publisher .EmitterProcessor .create (false );
59
+ private final Sinks .Many <Flux <BackendMessage >> responseProcessor = Sinks .many ().replay ().all ();
63
60
64
61
private final Integer secretKey ;
65
62
@@ -75,14 +72,12 @@ private TestClient(boolean expectClose, boolean connected, @Nullable Integer pro
75
72
this .transactionStatus = Assert .requireNonNull (transactionStatus , "transactionStatus must not be null" );
76
73
this .version = version ;
77
74
78
- FluxSink <Flux <BackendMessage >> responses = this .responseProcessor .sink ();
79
-
80
75
Assert .requireNonNull (windows , "windows must not be null" )
81
76
.map (window -> window .exchanges )
82
77
.map (exchanges -> exchanges
83
78
.concatMap (exchange ->
84
79
85
- this .requestProcessor .zipWith (exchange .requests )
80
+ this .requestProcessor .asFlux (). zipWith (exchange .requests )
86
81
.handle ((tuple , sink ) -> {
87
82
FrontendMessage actual = tuple .getT1 ();
88
83
FrontendMessage expected = tuple .getT2 ();
@@ -92,7 +87,7 @@ private TestClient(boolean expectClose, boolean connected, @Nullable Integer pro
92
87
}
93
88
})
94
89
.thenMany (exchange .responses )))
95
- .subscribe (responses :: next , responses :: error , responses :: complete );
90
+ .subscribe (this . responseProcessor :: tryEmitNext , this . responseProcessor :: tryEmitError , this . responseProcessor :: tryEmitComplete );
96
91
}
97
92
98
93
public static Builder builder () {
@@ -108,20 +103,20 @@ public Mono<Void> close() {
108
103
public Flux <BackendMessage > exchange (Publisher <FrontendMessage > requests ) {
109
104
Assert .requireNonNull (requests , "requests must not be null" );
110
105
111
- return this .responseProcessor
106
+ return this .responseProcessor . asFlux ()
112
107
.doOnSubscribe (s ->
113
108
Flux .from (requests )
114
- .subscribe (this .requests :: next , this .requests :: error ))
109
+ .subscribe (this .requestProcessor :: tryEmitNext , this .requestProcessor :: tryEmitError ))
115
110
.next ()
116
111
.flatMapMany (Function .identity ());
117
112
}
118
113
119
114
@ Override
120
115
public Flux <BackendMessage > exchange (Predicate <BackendMessage > takeUntil , Publisher <FrontendMessage > requests ) {
121
- return this .responseProcessor
116
+ return this .responseProcessor . asFlux ()
122
117
.doOnSubscribe (s ->
123
118
Flux .from (requests )
124
- .subscribe (this .requests :: next , this .requests :: error ))
119
+ .subscribe (this .requestProcessor :: tryEmitNext , this .requestProcessor :: tryEmitError ))
125
120
.next ()
126
121
.flatMapMany (Function .identity ())
127
122
.takeWhile (takeUntil .negate ());
@@ -169,21 +164,21 @@ public Mono<Void> cancelRequest() {
169
164
170
165
@ Override
171
166
public void send (FrontendMessage message ) {
172
- this .requests . next (message );
167
+ this .requestProcessor . tryEmitNext (message );
173
168
}
174
169
175
170
@ Override
176
171
public Disposable addNotificationListener (Consumer <NotificationResponse > consumer ) {
177
- return this .notificationProcessor .subscribe (consumer );
172
+ return this .notificationProcessor .asFlux (). subscribe (consumer );
178
173
}
179
174
180
175
@ Override
181
- public Disposable addNotificationListener (Subscriber <NotificationResponse > consumer ) {
182
- return this .notificationProcessor .subscribe (consumer :: onNext , consumer :: onError , consumer :: onComplete , consumer :: onSubscribe );
176
+ public void addNotificationListener (Subscriber <NotificationResponse > consumer ) {
177
+ this .notificationProcessor .asFlux (). subscribe (consumer );
183
178
}
184
179
185
180
public void notify (NotificationResponse notification ) {
186
- this .notificationProcessor .onNext (notification );
181
+ this .notificationProcessor .tryEmitNext (notification );
187
182
}
188
183
189
184
public static final class Builder {
0 commit comments