1+ using System ;
2+ using System . Linq ;
3+ using System . Threading . Tasks ;
4+ using Cleipnir . ResilientFunctions . Helpers ;
5+ using Cleipnir . ResilientFunctions . Storage ;
6+ using Cleipnir . ResilientFunctions . Tests . Utils ;
7+ using Shouldly ;
8+
9+ namespace Cleipnir . ResilientFunctions . Tests . TestTemplates ;
10+
11+ public abstract class ReplicaStoreTests
12+ {
13+ public abstract Task SunshineScenarioTest ( ) ;
14+ protected async Task SunshineScenarioTest ( Task < IFunctionStore > storeTask )
15+ {
16+ var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
17+ await store . GetAll ( ) . ShouldBeEmptyAsync ( ) ;
18+ var replicaId1 = Guid . NewGuid ( ) ;
19+ var replicaId2 = Guid . NewGuid ( ) ;
20+
21+ {
22+ await store . Insert ( replicaId1 ) ;
23+ var all = await store . GetAll ( ) ;
24+ all . Count . ShouldBe ( 1 ) ;
25+ var stored = all . Single ( ) ;
26+ stored . ReplicaId . ShouldBe ( replicaId1 ) ;
27+ stored . Heartbeat . ShouldBe ( 0 ) ;
28+ }
29+
30+ {
31+ await store . Insert ( replicaId2 ) ;
32+ var all = await store . GetAll ( ) ;
33+ all . Count . ShouldBe ( 2 ) ;
34+ var stored = all . Single ( id => id . ReplicaId == replicaId2 ) ;
35+ stored . ReplicaId . ShouldBe ( replicaId2 ) ;
36+ stored . Heartbeat . ShouldBe ( 0 ) ;
37+ }
38+
39+ await store . UpdateHeartbeat ( replicaId1 ) ;
40+ {
41+ var all = await store . GetAll ( ) ;
42+ all . Count . ShouldBe ( 2 ) ;
43+ var stored1 = all . Single ( r => r . ReplicaId == replicaId1 ) ;
44+ stored1 . Heartbeat . ShouldBe ( 1 ) ;
45+ var stored2 = all . Single ( r => r . ReplicaId == replicaId2 ) ;
46+ stored2 . Heartbeat . ShouldBe ( 0 ) ;
47+ }
48+
49+ await store . UpdateHeartbeat ( replicaId2 ) ;
50+ {
51+ var all = await store . GetAll ( ) ;
52+ all . Count . ShouldBe ( 2 ) ;
53+ var stored1 = all . Single ( r => r . ReplicaId == replicaId1 ) ;
54+ stored1 . Heartbeat . ShouldBe ( 1 ) ;
55+ var stored2 = all . Single ( r => r . ReplicaId == replicaId2 ) ;
56+ stored2 . Heartbeat . ShouldBe ( 1 ) ;
57+ }
58+
59+ await store . Delete ( replicaId1 ) ;
60+ {
61+ var all = await store . GetAll ( ) ;
62+ all . Count . ShouldBe ( 1 ) ;
63+ var stored2 = all . Single ( r => r . ReplicaId == replicaId2 ) ;
64+ stored2 . Heartbeat . ShouldBe ( 1 ) ;
65+ }
66+
67+ await store . Delete ( replicaId2 ) ;
68+ {
69+ var all = await store . GetAll ( ) ;
70+ all . ShouldBeEmpty ( ) ;
71+ }
72+ }
73+ }
0 commit comments