1616using Akka . Remote . Transport ;
1717using Akka . TestKit ;
1818using Akka . Util ;
19+ using FluentAssertions ;
1920
2021namespace Akka . DistributedData . Tests . MultiNode
2122{
@@ -41,7 +42,7 @@ public class JepsenInspiredInsertSpec : MultiNodeSpec
4142 public IEnumerable < int > MyData => _data [ Myself ] ;
4243
4344 public JepsenInspiredInsertSpec ( ) : this ( new JepsenInspiredInsertSpecConfig ( ) ) { }
44- public JepsenInspiredInsertSpec ( JepsenInspiredInsertSpecConfig config ) : base ( config )
45+ protected JepsenInspiredInsertSpec ( JepsenInspiredInsertSpecConfig config ) : base ( config )
4546 {
4647 _cluster = Cluster . Cluster . Get ( Sys ) ;
4748 _replicator = DistributedData . Get ( Sys ) . Replicator ;
@@ -52,7 +53,7 @@ public JepsenInspiredInsertSpec(JepsenInspiredInsertSpecConfig config) : base(co
5253 var nodeindex = _nodes . Zip ( Enumerable . Range ( 0 , _nodes . Count - 1 ) , ( name , i ) => new KeyValuePair < int , RoleName > ( i , name ) )
5354 . ToImmutableDictionary ( ) ;
5455 _data = Enumerable . Range ( 0 , _totalCount ) . GroupBy ( i => nodeindex [ i % _nodeCount ] )
55- . ToImmutableDictionary ( x => x . Key , x => ( IEnumerable < int > ) x . ToArray ( ) ) ;
56+ . ToImmutableDictionary ( x => x . Key , x => ( IEnumerable < int > ) x . Reverse ( ) . ToArray ( ) ) ;
5657 }
5758
5859 [ MultiNodeFact ]
@@ -103,9 +104,9 @@ public void Insert_from_5_nodes_should_replicate_values_when_all_nodes_connected
103104 var successWriteAcks = writeAcks . OfType < UpdateSuccess > ( ) . ToArray ( ) ;
104105 var failureWriteAcks = writeAcks . OfType < IUpdateFailure > ( ) . ToArray ( ) ;
105106 successWriteAcks . Select ( x => ( int ) x . Request ) . ShouldBe ( MyData . ToArray ( ) ) ;
106- successWriteAcks . Length . ShouldBe ( MyData . Count ( ) ) ;
107- failureWriteAcks . ShouldBe ( new IUpdateFailure [ 0 ] ) ;
108- ( successWriteAcks . Length + failureWriteAcks . Length ) . ShouldBe ( MyData . Count ( ) ) ;
107+ successWriteAcks . Length . Should ( ) . Be ( MyData . Count ( ) ) ;
108+ failureWriteAcks . Should ( ) . BeEmpty ( ) ;
109+ ( successWriteAcks . Length + failureWriteAcks . Length ) . Should ( ) . Be ( MyData . Count ( ) ) ;
109110
110111 // eventually all nodes will have the data
111112 Within ( TimeSpan . FromSeconds ( 15 ) , ( ) =>
@@ -115,7 +116,7 @@ public void Insert_from_5_nodes_should_replicate_values_when_all_nodes_connected
115116 var readProbe = CreateTestProbe ( ) ;
116117 _replicator . Tell ( Dsl . Get ( key , ReadLocal . Instance ) , readProbe . Ref ) ;
117118 var result = readProbe . ExpectMsg < GetSuccess > ( g => Equals ( g . Key , key ) ) . Get ( key ) ;
118- result . Elements . ShouldBe ( _expectedData ) ;
119+ result . Elements . Should ( ) . BeEquivalentTo ( _expectedData ) ;
119120 } ) ;
120121 } ) ;
121122 } , _nodes . ToArray ( ) ) ;
@@ -140,18 +141,18 @@ public void Insert_from_5_nodes_should_read_write_to_majority_when_all_nodes_con
140141 } ) . ToArray ( ) ;
141142 var successWriteAcks = writeAcks . OfType < UpdateSuccess > ( ) . ToArray ( ) ;
142143 var failureWriteAcks = writeAcks . OfType < IUpdateFailure > ( ) . ToArray ( ) ;
143- successWriteAcks . Select ( x => ( int ) x . Request ) . ShouldBe ( MyData . ToArray ( ) ) ;
144- successWriteAcks . Length . ShouldBe ( MyData . Count ( ) ) ;
145- failureWriteAcks . ShouldBe ( new IUpdateFailure [ 0 ] ) ;
146- ( successWriteAcks . Length + failureWriteAcks . Length ) . ShouldBe ( MyData . Count ( ) ) ;
144+ successWriteAcks . Select ( x => ( int ) x . Request ) . Should ( ) . BeEquivalentTo ( MyData . ToArray ( ) ) ;
145+ successWriteAcks . Length . Should ( ) . Be ( MyData . Count ( ) ) ;
146+ failureWriteAcks . Should ( ) . BeEmpty ( ) ;
147+ ( successWriteAcks . Length + failureWriteAcks . Length ) . Should ( ) . Be ( MyData . Count ( ) ) ;
147148
148149 EnterBarrier ( "data-written-2" ) ;
149150
150151 // read from majority of nodes, which is enough to retrieve all data
151152 var readProbe = CreateTestProbe ( ) ;
152153 _replicator . Tell ( Dsl . Get ( key , readMajority ) , readProbe . Ref ) ;
153154 var result = readProbe . ExpectMsg < GetSuccess > ( g => Equals ( g . Key , key ) ) . Get ( key ) ;
154- result . Elements . ShouldBe ( _expectedData ) ;
155+ result . Elements . Should ( ) . BeEquivalentTo ( _expectedData ) ;
155156 } , _nodes . ToArray ( ) ) ;
156157
157158 RunOn ( ( ) => EnterBarrier ( "data-written-2" ) , Controller ) ;
@@ -190,10 +191,10 @@ public void Insert_from_5_nodes_should_replicate_values_after_partition()
190191 } ) . ToArray ( ) ;
191192 var successWriteAcks = writeAcks . OfType < UpdateSuccess > ( ) . ToArray ( ) ;
192193 var failureWriteAcks = writeAcks . OfType < IUpdateFailure > ( ) . ToArray ( ) ;
193- successWriteAcks . Select ( x => ( int ) x . Request ) . ShouldBe ( MyData . ToArray ( ) ) ;
194- successWriteAcks . Length . ShouldBe ( MyData . Count ( ) ) ;
195- failureWriteAcks . ShouldBe ( new IUpdateFailure [ 0 ] ) ;
196- ( successWriteAcks . Length + failureWriteAcks . Length ) . ShouldBe ( MyData . Count ( ) ) ;
194+ successWriteAcks . Select ( x => ( int ) x . Request ) . Should ( ) . BeEquivalentTo ( MyData . ToArray ( ) ) ;
195+ successWriteAcks . Length . Should ( ) . Be ( MyData . Count ( ) ) ;
196+ failureWriteAcks . Should ( ) . BeEmpty ( ) ;
197+ ( successWriteAcks . Length + failureWriteAcks . Length ) . Should ( ) . Be ( MyData . Count ( ) ) ;
197198
198199 EnterBarrier ( "partition-healed-3" ) ;
199200
@@ -203,7 +204,7 @@ public void Insert_from_5_nodes_should_replicate_values_after_partition()
203204 var readProbe = CreateTestProbe ( ) ;
204205 _replicator . Tell ( Dsl . Get ( key , ReadLocal . Instance ) , readProbe . Ref ) ;
205206 var result = readProbe . ExpectMsg < GetSuccess > ( g => Equals ( g . Key , key ) ) . Get ( key ) ;
206- result . Elements . ShouldBe ( _expectedData ) ;
207+ result . Elements . Should ( ) . BeEquivalentTo ( _expectedData ) ;
207208 } ) ) ;
208209 } , _nodes . ToArray ( ) ) ;
209210
@@ -246,19 +247,19 @@ public void Insert_from_5_nodes_should_write_to_majority_during_3_and_2_partitio
246247
247248 RunOn ( ( ) =>
248249 {
249- successWriteAcks . Select ( x => ( int ) x . Request ) . ShouldBe ( MyData . ToArray ( ) ) ;
250- successWriteAcks . Length . ShouldBe ( MyData . Count ( ) ) ;
251- failureWriteAcks . ShouldBe ( new IUpdateFailure [ 0 ] ) ;
250+ successWriteAcks . Select ( x => ( int ) x . Request ) . Should ( ) . BeEquivalentTo ( MyData . ToArray ( ) ) ;
251+ successWriteAcks . Length . Should ( ) . Be ( MyData . Count ( ) ) ;
252+ failureWriteAcks . Should ( ) . BeEmpty ( ) ;
252253 } , N1 , N4 , N5 ) ;
253254
254255 RunOn ( ( ) =>
255256 {
256257 // without delays all could teoretically have been written before the blackhole
257258 if ( _delayMillis != 0 )
258- failureWriteAcks . ShouldNotBe ( new IUpdateFailure [ 0 ] ) ;
259+ failureWriteAcks . Should ( ) . NotBeEmpty ( ) ;
259260 } , N2 , N3 ) ;
260261
261- ( successWriteAcks . Length + failureWriteAcks . Length ) . ShouldBe ( MyData . Count ( ) ) ;
262+ ( successWriteAcks . Length + failureWriteAcks . Length ) . Should ( ) . Be ( MyData . Count ( ) ) ;
262263
263264 EnterBarrier ( "partition-healed-4" ) ;
264265
@@ -268,7 +269,7 @@ public void Insert_from_5_nodes_should_write_to_majority_during_3_and_2_partitio
268269 var readProbe = CreateTestProbe ( ) ;
269270 _replicator . Tell ( Dsl . Get ( key , readMajority ) , readProbe . Ref ) ;
270271 var result = readProbe . ExpectMsg < GetSuccess > ( g => Equals ( g . Key , key ) ) . Get ( key ) ;
271- result . Elements . ShouldBe ( _expectedData ) ;
272+ result . Elements . Should ( ) . BeEquivalentTo ( _expectedData ) ;
272273 } , N2 , N3 ) ;
273274
274275 // but on the 3 node side, read from majority doesn't mean that we are guaranteed to see
@@ -280,7 +281,7 @@ public void Insert_from_5_nodes_should_write_to_majority_during_3_and_2_partitio
280281 var readProbe = CreateTestProbe ( ) ;
281282 _replicator . Tell ( Dsl . Get ( key , ReadLocal . Instance ) , readProbe . Ref ) ;
282283 var result = readProbe . ExpectMsg < GetSuccess > ( g => Equals ( g . Key , key ) ) . Get ( key ) ;
283- result . Elements . ShouldBe ( _expectedData ) ;
284+ result . Elements . Should ( ) . BeEquivalentTo ( _expectedData ) ;
284285 } ) ) ;
285286 } , _nodes . ToArray ( ) ) ;
286287
@@ -315,25 +316,32 @@ private void SleepDuringPartition()
315316 Thread . Sleep ( Math . Max ( 5000 , _delayMillis * _totalCount / _nodeCount / 2 ) ) ;
316317 }
317318 }
318-
319- public class JepsenInspiredInsertSpecNode1 : JepsenInspiredInsertSpec { }
320- public class JepsenInspiredInsertSpecNode2 : JepsenInspiredInsertSpec { }
321- public class JepsenInspiredInsertSpecNode3 : JepsenInspiredInsertSpec { }
322- public class JepsenInspiredInsertSpecNode4 : JepsenInspiredInsertSpec { }
323- public class JepsenInspiredInsertSpecNode5 : JepsenInspiredInsertSpec { }
324- public class JepsenInspiredInsertSpecNode6 : JepsenInspiredInsertSpec { }
325-
319+
326320 public class JepsenInspiredInsertSpecConfig : MultiNodeConfig
327321 {
322+ public RoleName Controller { get ; }
323+ public RoleName N1 { get ; }
324+ public RoleName N2 { get ; }
325+ public RoleName N3 { get ; }
326+ public RoleName N4 { get ; }
327+ public RoleName N5 { get ; }
328328 public JepsenInspiredInsertSpecConfig ( )
329329 {
330+ Controller = Role ( "controller" ) ;
331+ N1 = Role ( "n1" ) ;
332+ N2 = Role ( "n2" ) ;
333+ N3 = Role ( "n3" ) ;
334+ N4 = Role ( "n4" ) ;
335+ N5 = Role ( "n5" ) ;
336+
330337 CommonConfig = ConfigurationFactory . ParseString ( @"
331338 akka.loglevel = INFO
332339 akka.actor.provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster""
333340 akka.log-dead-letters = off
334341 akka.log-dead-letters-during-shutdown = off
335342 akka.remote.log-remote-lifecycle-events = ERROR
336- akka.testconductor.barrier-timeout = 60s" ) ;
343+ akka.testconductor.barrier-timeout = 60s" )
344+ . WithFallback ( DistributedData . DefaultConfig ( ) ) ;
337345
338346 TestTransport = true ;
339347 }
0 commit comments