9
9
using System . Collections . Generic ;
10
10
using System . Linq ;
11
11
using System . Threading ;
12
+ using System . Threading . Tasks ;
12
13
using Akka . Streams . Dsl ;
13
14
using Akka . Streams . TestKit ;
14
15
using Akka . TestKit ;
@@ -46,10 +47,9 @@ public MergeFixture(GraphDsl.Builder<NotUsed> builder) : base(builder)
46
47
}
47
48
48
49
[ Fact ]
49
- public void A_Merge_must_work_in_the_happy_case ( )
50
+ public async Task A_Merge_must_work_in_the_happy_case ( )
50
51
{
51
- this . AssertAllStagesStopped ( ( ) =>
52
- {
52
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
53
53
// Different input sizes(4 and 6)
54
54
var source1 = Source . From ( Enumerable . Range ( 0 , 4 ) ) ;
55
55
var source2 = Source . From ( Enumerable . Range ( 4 , 6 ) ) ;
@@ -63,27 +63,27 @@ public void A_Merge_must_work_in_the_happy_case()
63
63
var sink = Sink . FromSubscriber ( probe ) ;
64
64
65
65
b . From ( source1 ) . To ( m1 . In ( 0 ) ) ;
66
- b . From ( m1 . Out ) . Via ( Flow . Create < int > ( ) . Select ( x => x * 2 ) ) . To ( m2 . In ( 0 ) ) ;
67
- b . From ( m2 . Out ) . Via ( Flow . Create < int > ( ) . Select ( x => x / 2 ) . Select ( x=> x + 1 ) ) . To ( sink ) ;
66
+ b . From ( m1 . Out ) . Via ( Flow . Create < int > ( ) . Select ( x => x * 2 ) ) . To ( m2 . In ( 0 ) ) ;
67
+ b . From ( m2 . Out ) . Via ( Flow . Create < int > ( ) . Select ( x => x / 2 ) . Select ( x => x + 1 ) ) . To ( sink ) ;
68
68
b . From ( source2 ) . To ( m1 . In ( 1 ) ) ;
69
69
b . From ( source3 ) . To ( m2 . In ( 1 ) ) ;
70
70
71
71
return ClosedShape . Instance ;
72
72
} ) ) . Run ( Materializer ) ;
73
73
74
- var subscription = probe . ExpectSubscription ( ) ;
74
+ var subscription = await probe . ExpectSubscriptionAsync ( ) ;
75
75
var collected = new List < int > ( ) ;
76
76
for ( var i = 1 ; i <= 10 ; i ++ )
77
77
{
78
78
subscription . Request ( 1 ) ;
79
- collected . Add ( probe . ExpectNext ( ) ) ;
79
+ collected . Add ( await probe . ExpectNextAsync ( ) ) ;
80
80
}
81
81
82
82
collected . Where ( i => i <= 4 ) . ShouldOnlyContainInOrder ( 1 , 2 , 3 , 4 ) ;
83
83
collected . Where ( i => i >= 5 ) . ShouldOnlyContainInOrder ( 5 , 6 , 7 , 8 , 9 , 10 ) ;
84
84
85
85
collected . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 1 , 10 ) . ToArray ( ) ) ;
86
- probe . ExpectComplete ( ) ;
86
+ await probe . ExpectCompleteAsync ( ) ;
87
87
} , Materializer ) ;
88
88
}
89
89
@@ -109,7 +109,7 @@ public void A_Merge_must_work_with_one_way_merge()
109
109
}
110
110
111
111
[ Fact ]
112
- public void A_Merge_must_work_with_n_way_merge ( )
112
+ public async Task A_Merge_must_work_with_n_way_merge ( )
113
113
{
114
114
var source1 = Source . Single ( 1 ) ;
115
115
var source2 = Source . Single ( 2 ) ;
@@ -135,76 +135,71 @@ public void A_Merge_must_work_with_n_way_merge()
135
135
return ClosedShape . Instance ;
136
136
} ) ) . Run ( Materializer ) ;
137
137
138
- var subscription = probe . ExpectSubscription ( ) ;
138
+ var subscription = await probe . ExpectSubscriptionAsync ( ) ;
139
139
140
140
var collected = new List < int > ( ) ;
141
141
for ( var i = 1 ; i <= 5 ; i ++ )
142
142
{
143
143
subscription . Request ( 1 ) ;
144
- collected . Add ( probe . ExpectNext ( ) ) ;
144
+ collected . Add ( await probe . ExpectNextAsync ( ) ) ;
145
145
}
146
146
147
147
collected . Should ( ) . BeEquivalentTo ( Enumerable . Range ( 1 , 5 ) ) ;
148
- probe . ExpectComplete ( ) ;
148
+ await probe . ExpectCompleteAsync ( ) ;
149
149
}
150
150
151
151
[ Fact ]
152
- public void A_Merge_must_work_with_one_immediately_completed_and_one_nonempty_publisher ( )
152
+ public async Task A_Merge_must_work_with_one_immediately_completed_and_one_nonempty_publisher ( )
153
153
{
154
- this . AssertAllStagesStopped ( ( ) =>
155
- {
154
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
156
155
var subscriber1 = Setup ( CompletedPublisher < int > ( ) , NonEmptyPublisher ( Enumerable . Range ( 1 , 4 ) ) ) ;
157
- var subscription1 = subscriber1 . ExpectSubscription ( ) ;
156
+ var subscription1 = await subscriber1 . ExpectSubscriptionAsync ( ) ;
158
157
subscription1 . Request ( 4 ) ;
159
- subscriber1 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectComplete ( ) ;
158
+ await subscriber1 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectCompleteAsync ( ) ;
160
159
161
160
var subscriber2 = Setup ( NonEmptyPublisher ( Enumerable . Range ( 1 , 4 ) ) , CompletedPublisher < int > ( ) ) ;
162
- var subscription2 = subscriber2 . ExpectSubscription ( ) ;
161
+ var subscription2 = await subscriber2 . ExpectSubscriptionAsync ( ) ;
163
162
subscription2 . Request ( 4 ) ;
164
- subscriber2 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectComplete ( ) ;
163
+ await subscriber2 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectCompleteAsync ( ) ;
165
164
} , Materializer ) ;
166
165
}
167
166
168
167
[ Fact ]
169
- public void A_Merge_must_work_with_one_delayed_completed_and_one_nonempty_publisher ( )
168
+ public async Task A_Merge_must_work_with_one_delayed_completed_and_one_nonempty_publisher ( )
170
169
{
171
- this . AssertAllStagesStopped ( ( ) =>
172
- {
170
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
173
171
var subscriber1 = Setup ( SoonToCompletePublisher < int > ( ) , NonEmptyPublisher ( Enumerable . Range ( 1 , 4 ) ) ) ;
174
- var subscription1 = subscriber1 . ExpectSubscription ( ) ;
172
+ var subscription1 = await subscriber1 . ExpectSubscriptionAsync ( ) ;
175
173
subscription1 . Request ( 4 ) ;
176
- subscriber1 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectComplete ( ) ;
174
+ await subscriber1 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectCompleteAsync ( ) ;
177
175
178
176
var subscriber2 = Setup ( NonEmptyPublisher ( Enumerable . Range ( 1 , 4 ) ) , SoonToCompletePublisher < int > ( ) ) ;
179
- var subscription2 = subscriber2 . ExpectSubscription ( ) ;
177
+ var subscription2 = await subscriber2 . ExpectSubscriptionAsync ( ) ;
180
178
subscription2 . Request ( 4 ) ;
181
- subscriber2 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectComplete ( ) ;
179
+ await subscriber2 . ExpectNext ( 1 , 2 , 3 , 4 ) . ExpectCompleteAsync ( ) ;
182
180
} , Materializer ) ;
183
181
}
184
182
185
183
[ Fact ( Skip = "This is nondeterministic, multiple scenarios can happen" ) ]
186
- public void A_Merge_must_work_with_one_immediately_failed_and_one_nonempty_publisher ( )
184
+ public async Task A_Merge_must_work_with_one_immediately_failed_and_one_nonempty_publisher ( )
187
185
{
188
- this . AssertAllStagesStopped ( ( ) =>
189
- {
190
-
186
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
187
+ return Task . CompletedTask ;
191
188
} , Materializer ) ;
192
189
}
193
190
194
191
[ Fact ( Skip = "This is nondeterministic, multiple scenarios can happen" ) ]
195
- public void A_Merge_must_work_with_one_delayed_failed_and_one_nonempty_publisher ( )
192
+ public async Task A_Merge_must_work_with_one_delayed_failed_and_one_nonempty_publisher ( )
196
193
{
197
- this . AssertAllStagesStopped ( ( ) =>
198
- {
199
-
194
+ await this . AssertAllStagesStoppedAsync ( ( ) => {
195
+ return Task . CompletedTask ;
200
196
} , Materializer ) ;
201
197
}
202
198
203
199
[ Fact ]
204
- public void A_Merge_must_pass_along_early_cancellation ( )
200
+ public async Task A_Merge_must_pass_along_early_cancellation ( )
205
201
{
206
- this . AssertAllStagesStopped ( ( ) =>
207
- {
202
+ await this . AssertAllStagesStoppedAsync ( async ( ) => {
208
203
var up1 = this . CreateManualPublisherProbe < int > ( ) ;
209
204
var up2 = this . CreateManualPublisherProbe < int > ( ) ;
210
205
var down = this . CreateManualSubscriberProbe < int > ( ) ;
@@ -224,14 +219,14 @@ public void A_Merge_must_pass_along_early_cancellation()
224
219
return ClosedShape . Instance ;
225
220
} ) ) . Run ( Materializer ) ;
226
221
227
- var downstream = down . ExpectSubscription ( ) ;
222
+ var downstream = await down . ExpectSubscriptionAsync ( ) ;
228
223
downstream . Cancel ( ) ;
229
224
up1 . Subscribe ( t . Item1 ) ;
230
225
up2 . Subscribe ( t . Item2 ) ;
231
- var upSub1 = up1 . ExpectSubscription ( ) ;
232
- upSub1 . ExpectCancellation ( ) ;
233
- var upSub2 = up2 . ExpectSubscription ( ) ;
234
- upSub2 . ExpectCancellation ( ) ;
226
+ var upSub1 = await up1 . ExpectSubscriptionAsync ( ) ;
227
+ await upSub1 . ExpectCancellationAsync ( ) ;
228
+ var upSub2 = await up2 . ExpectSubscriptionAsync ( ) ;
229
+ await upSub2 . ExpectCancellationAsync ( ) ;
235
230
} , Materializer ) ;
236
231
}
237
232
}
0 commit comments