14
14
using System . Linq ;
15
15
using Akka . Util . Internal ;
16
16
using Xunit ;
17
+ using System . Threading . Tasks ;
17
18
18
19
namespace Akka . Tests . Event
19
20
{
@@ -61,25 +62,25 @@ private class CC { }
61
62
private class CCATBT : CC , ATT , BTT { }
62
63
63
64
[ Fact ]
64
- public void Manage_subscriptions ( )
65
+ public async Task Manage_subscriptions ( )
65
66
{
66
67
67
68
var bus = new EventStream ( true ) ;
68
69
bus . StartUnsubscriber ( Sys . AsInstanceOf < ActorSystemImpl > ( ) ) ;
69
70
bus . Subscribe ( TestActor , typeof ( M ) ) ;
70
71
71
72
bus . Publish ( new M { Value = 42 } ) ;
72
- ExpectMsg ( new M { Value = 42 } ) ;
73
+ await ExpectMsgAsync ( new M { Value = 42 } ) ;
73
74
bus . Unsubscribe ( TestActor ) ;
74
75
bus . Publish ( new M { Value = 43 } ) ;
75
- ExpectNoMsg ( TimeSpan . FromSeconds ( 1 ) ) ;
76
+ await ExpectNoMsgAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
76
77
}
77
78
78
79
[ Fact ]
79
80
public void Not_allow_null_as_subscriber ( )
80
81
{
81
82
var bus = new EventStream ( true ) ;
82
- XAssert . Throws < ArgumentNullException > ( ( ) =>
83
+ Assert . Throws < ArgumentNullException > ( ( ) =>
83
84
{
84
85
bus . Subscribe ( null , typeof ( M ) ) ;
85
86
} ) ;
@@ -89,18 +90,18 @@ public void Not_allow_null_as_subscriber()
89
90
public void Not_allow_null_as_unsubscriber ( )
90
91
{
91
92
var bus = new EventStream ( true ) ;
92
- XAssert . Throws < ArgumentNullException > ( ( ) =>
93
+ Assert . Throws < ArgumentNullException > ( ( ) =>
93
94
{
94
95
bus . Unsubscribe ( null , typeof ( M ) ) ;
95
96
} ) ;
96
- XAssert . Throws < ArgumentNullException > ( ( ) =>
97
+ Assert . Throws < ArgumentNullException > ( ( ) =>
97
98
{
98
99
bus . Unsubscribe ( null ) ;
99
100
} ) ;
100
101
}
101
102
102
103
[ Fact ]
103
- public void Be_able_to_log_unhandled_messages ( )
104
+ public async Task Be_able_to_log_unhandled_messages ( )
104
105
{
105
106
using ( var system = ActorSystem . Create ( "EventStreamSpecUnhandled" , GetDebugUnhandledMessagesConfig ( ) ) )
106
107
{
@@ -110,7 +111,7 @@ public void Be_able_to_log_unhandled_messages()
110
111
111
112
system . EventStream . Publish ( msg ) ;
112
113
113
- var debugMsg = ExpectMsg < Debug > ( ) ;
114
+ var debugMsg = await ExpectMsgAsync < Debug > ( ) ;
114
115
115
116
debugMsg . Message . ToString ( ) . StartsWith ( "Unhandled message from" ) . ShouldBeTrue ( ) ;
116
117
debugMsg . Message . ToString ( ) . EndsWith ( ": 42" ) . ShouldBeTrue ( ) ;
@@ -121,7 +122,7 @@ public void Be_able_to_log_unhandled_messages()
121
122
/// Reproduction spec for https://github.com/akkadotnet/akka.net/issues/3267
122
123
/// </summary>
123
124
[ Fact ]
124
- public void Bugfix3267_able_to_log_unhandled_messages_with_nosender ( )
125
+ public async Task Bugfix3267_able_to_log_unhandled_messages_with_nosender ( )
125
126
{
126
127
using ( var system = ActorSystem . Create ( "EventStreamSpecUnhandled" , GetDebugUnhandledMessagesConfig ( ) ) )
127
128
{
@@ -132,15 +133,15 @@ public void Bugfix3267_able_to_log_unhandled_messages_with_nosender()
132
133
133
134
system . EventStream . Publish ( msg ) ;
134
135
135
- var debugMsg = ExpectMsg < Debug > ( ) ;
136
+ var debugMsg = await ExpectMsgAsync < Debug > ( ) ;
136
137
137
138
debugMsg . Message . ToString ( ) . StartsWith ( "Unhandled message from" ) . ShouldBeTrue ( ) ;
138
139
debugMsg . Message . ToString ( ) . EndsWith ( ": 42" ) . ShouldBeTrue ( ) ;
139
140
}
140
141
}
141
142
142
143
[ Fact ]
143
- public void Manage_sub_channels_using_classes ( )
144
+ public async Task Manage_sub_channels_using_classes ( )
144
145
{
145
146
var a = new A ( ) ;
146
147
var b1 = new B1 ( ) ;
@@ -150,24 +151,24 @@ public void Manage_sub_channels_using_classes()
150
151
bus . Subscribe ( TestActor , typeof ( B2 ) ) ;
151
152
bus . Publish ( c ) ;
152
153
bus . Publish ( b2 ) ;
153
- ExpectMsg ( b2 ) ;
154
+ await ExpectMsgAsync ( b2 ) ;
154
155
bus . Subscribe ( TestActor , typeof ( A ) ) ;
155
156
bus . Publish ( c ) ;
156
- ExpectMsg ( c ) ;
157
+ await ExpectMsgAsync ( c ) ;
157
158
bus . Publish ( b1 ) ;
158
- ExpectMsg ( b1 ) ;
159
+ await ExpectMsgAsync ( b1 ) ;
159
160
160
161
bus . Unsubscribe ( TestActor , typeof ( B1 ) ) ;
161
162
bus . Publish ( c ) ; //should not publish
162
163
bus . Publish ( b2 ) ; //should publish
163
164
bus . Publish ( a ) ; //should publish
164
- ExpectMsg ( b2 ) ;
165
- ExpectMsg ( a ) ;
166
- ExpectNoMsg ( TimeSpan . FromSeconds ( 1 ) ) ;
165
+ await ExpectMsgAsync ( b2 ) ;
166
+ await ExpectMsgAsync ( a ) ;
167
+ await ExpectNoMsgAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
167
168
}
168
169
169
170
[ Fact ( DisplayName = "manage sub-channels using classes and traits (update on subscribe)" ) ]
170
- public void Manage_sub_channels_using_classes_and_interfaces_update_on_subscribe ( )
171
+ public async Task Manage_sub_channels_using_classes_and_interfaces_update_on_subscribe ( )
171
172
{
172
173
var es = new EventStream ( false ) ;
173
174
var tm1 = new CC ( ) ;
@@ -183,11 +184,11 @@ public void Manage_sub_channels_using_classes_and_interfaces_update_on_subscribe
183
184
es . Subscribe ( a4 . Ref , typeof ( CCATBT ) ) . ShouldBeTrue ( ) ;
184
185
es . Publish ( tm1 ) ;
185
186
es . Publish ( tm2 ) ;
186
- a1 . ExpectMsg ( ( object ) tm2 ) ;
187
- a2 . ExpectMsg ( ( object ) tm2 ) ;
188
- a3 . ExpectMsg ( ( object ) tm1 ) ;
189
- a3 . ExpectMsg ( ( object ) tm2 ) ;
190
- a4 . ExpectMsg ( ( object ) tm2 ) ;
187
+ await a1 . ExpectMsgAsync ( ( object ) tm2 ) ;
188
+ await a2 . ExpectMsgAsync ( ( object ) tm2 ) ;
189
+ await a3 . ExpectMsgAsync ( ( object ) tm1 ) ;
190
+ await a3 . ExpectMsgAsync ( ( object ) tm2 ) ;
191
+ await a4 . ExpectMsgAsync ( ( object ) tm2 ) ;
191
192
es . Unsubscribe ( a1 . Ref , typeof ( AT ) ) . ShouldBeTrue ( ) ;
192
193
es . Unsubscribe ( a2 . Ref , typeof ( BT ) ) . ShouldBeTrue ( ) ;
193
194
es . Unsubscribe ( a3 . Ref , typeof ( CC ) ) . ShouldBeTrue ( ) ;
@@ -196,7 +197,7 @@ public void Manage_sub_channels_using_classes_and_interfaces_update_on_subscribe
196
197
197
198
//"manage sub-channels using classes and traits (update on unsubscribe)"
198
199
[ Fact ]
199
- public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe ( )
200
+ public async Task Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe ( )
200
201
{
201
202
var es = new EventStream ( false ) ;
202
203
var tm1 = new CC ( ) ;
@@ -213,18 +214,18 @@ public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscri
213
214
es . Unsubscribe ( a3 . Ref , typeof ( CC ) ) ;
214
215
es . Publish ( tm1 ) ;
215
216
es . Publish ( tm2 ) ;
216
- a1 . ExpectMsg ( ( object ) tm2 ) ;
217
- a2 . ExpectMsg ( ( object ) tm2 ) ;
218
- a3 . ExpectNoMsg ( TimeSpan . FromSeconds ( 1 ) ) ;
219
- a4 . ExpectMsg ( ( object ) tm2 ) ;
217
+ await a1 . ExpectMsgAsync ( ( object ) tm2 ) ;
218
+ await a2 . ExpectMsgAsync ( ( object ) tm2 ) ;
219
+ await a3 . ExpectNoMsgAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
220
+ await a4 . ExpectMsgAsync ( ( object ) tm2 ) ;
220
221
es . Unsubscribe ( a1 . Ref , typeof ( AT ) ) . ShouldBeTrue ( ) ;
221
222
es . Unsubscribe ( a2 . Ref , typeof ( BT ) ) . ShouldBeTrue ( ) ;
222
223
es . Unsubscribe ( a3 . Ref , typeof ( CC ) ) . ShouldBeFalse ( ) ;
223
224
es . Unsubscribe ( a4 . Ref , typeof ( CCATBT ) ) . ShouldBeTrue ( ) ;
224
225
}
225
226
226
227
[ Fact ]
227
- public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe_all ( )
228
+ public async Task Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe_all ( )
228
229
{
229
230
var es = new EventStream ( false ) ;
230
231
var tm1 = new CC ( ) ;
@@ -241,10 +242,10 @@ public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscri
241
242
es . Unsubscribe ( a3 . Ref ) . ShouldBeTrue ( ) ;
242
243
es . Publish ( tm1 ) ;
243
244
es . Publish ( tm2 ) ;
244
- a1 . ExpectMsg ( ( object ) tm2 ) ;
245
- a2 . ExpectMsg ( ( object ) tm2 ) ;
246
- a3 . ExpectNoMsg ( TimeSpan . FromSeconds ( 1 ) ) ;
247
- a4 . ExpectMsg ( ( object ) tm2 ) ;
245
+ await a1 . ExpectMsgAsync ( ( object ) tm2 ) ;
246
+ await a2 . ExpectMsgAsync ( ( object ) tm2 ) ;
247
+ await a3 . ExpectNoMsgAsync ( TimeSpan . FromSeconds ( 1 ) ) ;
248
+ await a4 . ExpectMsgAsync ( ( object ) tm2 ) ;
248
249
es . Unsubscribe ( a1 . Ref , typeof ( AT ) ) . ShouldBeTrue ( ) ;
249
250
es . Unsubscribe ( a2 . Ref , typeof ( BT ) ) . ShouldBeTrue ( ) ;
250
251
es . Unsubscribe ( a3 . Ref , typeof ( CC ) ) . ShouldBeFalse ( ) ;
@@ -262,12 +263,12 @@ public SetTarget(IActorRef @ref)
262
263
}
263
264
264
265
[ Fact ]
265
- public void Manage_log_levels ( )
266
+ public async Task Manage_log_levels ( )
266
267
{
267
268
var bus = new EventStream ( false ) ;
268
269
bus . StartDefaultLoggers ( ( ActorSystemImpl ) Sys ) ;
269
270
bus . Publish ( new SetTarget ( TestActor ) ) ;
270
- ExpectMsg ( "OK" , TimeSpan . FromSeconds ( 5 ) ) ;
271
+ await ExpectMsgAsync ( "OK" , TimeSpan . FromSeconds ( 5 ) ) ;
271
272
272
273
verifyLevel ( bus , LogLevel . InfoLevel ) ;
273
274
bus . SetLogLevel ( LogLevel . WarningLevel ) ;
@@ -304,28 +305,26 @@ private static string GetDebugUnhandledMessagesConfig()
304
305
" . Replace ( "%logger%" , typeof ( MyLog ) . AssemblyQualifiedName ) ;
305
306
}
306
307
307
- public class MyLog : UntypedActor
308
+ public class MyLog : ReceiveActor
308
309
{
309
310
private IActorRef dst = Context . System . DeadLetters ;
310
-
311
- protected override void OnReceive ( object message )
311
+ public MyLog ( )
312
312
{
313
- PatternMatch . Match ( message )
314
- . With < InitializeLogger > ( m =>
313
+ Receive < InitializeLogger > ( m =>
315
314
{
316
315
var bus = m . LoggingBus ;
317
316
bus . Subscribe ( this . Self , typeof ( SetTarget ) ) ;
318
317
bus . Subscribe ( this . Self , typeof ( UnhandledMessage ) ) ;
319
318
320
319
Sender . Tell ( new LoggerInitialized ( ) ) ;
321
- } )
322
- . With < SetTarget > ( m =>
320
+ } ) ;
321
+ Receive < SetTarget > ( m =>
323
322
{
324
323
dst = m . Ref ;
325
324
dst . Tell ( "OK" ) ;
326
- } )
327
- . With < LogEvent > ( m => dst . Tell ( m ) )
328
- . With < UnhandledMessage > ( m => dst . Tell ( m ) ) ;
325
+ } ) ;
326
+ Receive < LogEvent > ( m => dst . Tell ( m ) ) ;
327
+ Receive < UnhandledMessage > ( m => dst . Tell ( m ) ) ;
329
328
}
330
329
}
331
330
0 commit comments