Skip to content

Commit 93663cb

Browse files
committed
general cleanup of ddata MNTK specs
1 parent e9c4a3a commit 93663cb

10 files changed

Lines changed: 156 additions & 123 deletions

File tree

src/contrib/cluster/Akka.DistributedData.Tests.MultiNode/Akka.DistributedData.Tests.MultiNode.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="FluentAssertions, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
34+
<HintPath>..\..\..\packages\FluentAssertions.4.19.0\lib\net45\FluentAssertions.dll</HintPath>
35+
<Private>True</Private>
36+
</Reference>
37+
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
38+
<HintPath>..\..\..\packages\FluentAssertions.4.19.0\lib\net45\FluentAssertions.Core.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
3341
<Reference Include="System" />
3442
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
3543
<HintPath>..\..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>

src/contrib/cluster/Akka.DistributedData.Tests.MultiNode/DurableDataSpec.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ namespace Akka.DistributedData.Tests.MultiNode
1919
{
2020
public class DurableDataSpecConfig : MultiNodeConfig
2121
{
22-
public readonly RoleName First = new RoleName("first");
23-
public readonly RoleName Second = new RoleName("second");
22+
public RoleName First { get; }
23+
public RoleName Second { get; }
2424

2525
public DurableDataSpecConfig(bool writeBehind)
2626
{
27+
First = Role("first");
28+
Second = Role("second");
29+
2730
var writeBehindInterval = writeBehind ? "200ms" : "off";
2831
CommonConfig = ConfigurationFactory.ParseString($@"
2932
akka.loglevel = INFO
@@ -36,7 +39,7 @@ public DurableDataSpecConfig(bool writeBehind)
3639
write-behind-interval = ${writeBehindInterval}
3740
}}
3841
akka.test.single-expect-default = 5s
39-
");
42+
").WithFallback(DistributedData.DefaultConfig());
4043
}
4144
}
4245

@@ -375,17 +378,9 @@ public class DurableDataSpecNode1 : DurableDataSpec
375378
{
376379
public DurableDataSpecNode1() : base(new DurableDataSpecConfig(writeBehind: false)) { }
377380
}
378-
public class DurableDataSpecNode2 : DurableDataSpec
379-
{
380-
public DurableDataSpecNode2() : base(new DurableDataSpecConfig(writeBehind: false)) { }
381-
}
382381

383382
public class DurableDataWriteBehindSpecNode1 : DurableDataSpec
384383
{
385384
public DurableDataWriteBehindSpecNode1() : base(new DurableDataSpecConfig(writeBehind: true)) { }
386385
}
387-
public class DurableDataWriteBehindSpecNode2 : DurableDataSpec
388-
{
389-
public DurableDataWriteBehindSpecNode2() : base(new DurableDataSpecConfig(writeBehind: true)) { }
390-
}
391386
}

src/contrib/cluster/Akka.DistributedData.Tests.MultiNode/DurablePrunningSpec.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ namespace Akka.DistributedData.Tests.MultiNode
1919
{
2020
public class DurablePrunningSpecConfig : MultiNodeConfig
2121
{
22-
public readonly RoleName First = new RoleName("first");
23-
public readonly RoleName Second = new RoleName("second");
22+
public readonly RoleName First;
23+
public readonly RoleName Second;
2424

2525
public DurablePrunningSpecConfig()
2626
{
27+
First = Role("first");
28+
Second = Role("second");
29+
2730
CommonConfig = DebugConfig(on: false).WithFallback(ConfigurationFactory.ParseString($@"
2831
akka.loglevel = INFO
2932
akka.actor.provider = ""cluster""
@@ -32,25 +35,25 @@ public DurablePrunningSpecConfig()
3235
akka.cluster.distributed-data.durable.lmdb {{
3336
dir = target/DurablePruningSpec-${DateTime.UtcNow.Ticks}-ddata
3437
map-size = 10 MiB
35-
}}"));
38+
}}")).WithFallback(DistributedData.DefaultConfig());
3639
}
3740
}
3841

39-
public abstract class DurablePrunningSpec : MultiNodeSpec
42+
public class DurablePrunningSpec : MultiNodeSpec
4043
{
4144
private readonly Cluster.Cluster cluster;
4245
private readonly RoleName first = new RoleName("first");
4346
private readonly RoleName second = new RoleName("second");
4447
private readonly TimeSpan maxPrunningDissemination = TimeSpan.FromSeconds(3);
45-
private readonly TimeSpan timemout;
48+
private readonly TimeSpan timeout;
4649
private readonly GCounterKey keyA = new GCounterKey("A");
4750
private readonly IActorRef replicator;
4851

4952
protected DurablePrunningSpec() : base(new DurablePrunningSpecConfig())
5053
{
5154
InitialParticipantsValueFactory = Roles.Count;
5255
cluster = Cluster.Cluster.Get(Sys);
53-
timemout = Dilated(TimeSpan.FromSeconds(5));
56+
timeout = Dilated(TimeSpan.FromSeconds(5));
5457
}
5558

5659
protected override int InitialParticipantsValueFactory { get; }
@@ -184,7 +187,4 @@ private void Join(RoleName from, RoleName to)
184187
EnterBarrier(from.Name + "-joined");
185188
}
186189
}
187-
188-
public class DurablePrunningSpecNode1 : DurablePrunningSpec { }
189-
public class DurablePrunningSpecNode2 : DurablePrunningSpec { }
190190
}

src/contrib/cluster/Akka.DistributedData.Tests.MultiNode/JepsenInspiredInsertSpec.cs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Akka.Remote.Transport;
1717
using Akka.TestKit;
1818
using Akka.Util;
19+
using FluentAssertions;
1920

2021
namespace 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

Comments
 (0)