@@ -16,7 +16,7 @@ public abstract class ReplicaWatchdogTests
16
16
public async Task SunshineScenario ( Task < IFunctionStore > storeTask )
17
17
{
18
18
var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
19
- var replicaId1 = new ReplicaId ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
19
+ var replicaId1 = new ClusterInfo ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
20
20
using var watchdog1 = new ReplicaWatchdog (
21
21
replicaId1 ,
22
22
store ,
@@ -26,10 +26,10 @@ public async Task SunshineScenario(Task<IFunctionStore> storeTask)
26
26
await watchdog1 . Initialize ( ) ;
27
27
var allReplicas = await store . GetAll ( ) ;
28
28
allReplicas . Count . ShouldBe ( 1 ) ;
29
- var storedReplica1 = allReplicas . Single ( sr => sr . ReplicaId == replicaId1 . Id ) ;
29
+ var storedReplica1 = allReplicas . Single ( sr => sr . ReplicaId == replicaId1 . ReplicaId ) ;
30
30
storedReplica1 . Heartbeat . ShouldBe ( 0 ) ;
31
31
32
- var replicaId2 = new ReplicaId ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
32
+ var replicaId2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
33
33
using var watchdog2 = new ReplicaWatchdog (
34
34
replicaId2 ,
35
35
store ,
@@ -39,38 +39,38 @@ public async Task SunshineScenario(Task<IFunctionStore> storeTask)
39
39
await watchdog2 . Initialize ( ) ;
40
40
allReplicas = await store . GetAll ( ) ;
41
41
allReplicas . Count . ShouldBe ( 2 ) ;
42
- storedReplica1 = allReplicas . Single ( sr => sr . ReplicaId == replicaId1 . Id ) ;
42
+ storedReplica1 = allReplicas . Single ( sr => sr . ReplicaId == replicaId1 . ReplicaId ) ;
43
43
storedReplica1 . Heartbeat . ShouldBe ( 0 ) ;
44
- var storedReplica2 = allReplicas . Single ( sr => sr . ReplicaId == replicaId2 . Id ) ;
44
+ var storedReplica2 = allReplicas . Single ( sr => sr . ReplicaId == replicaId2 . ReplicaId ) ;
45
45
storedReplica2 . Heartbeat . ShouldBe ( 0 ) ;
46
46
47
47
await watchdog1 . PerformIteration ( ) ;
48
48
var replicas = await store . GetAll ( ) ;
49
- replicas . Single ( sr => sr . ReplicaId == replicaId1 . Id ) . Heartbeat . ShouldBe ( 1 ) ;
50
- replicas . Single ( sr => sr . ReplicaId == replicaId2 . Id ) . Heartbeat . ShouldBe ( 0 ) ;
51
- watchdog1 . Strikes [ new StoredReplica ( replicaId2 . Id , Heartbeat : 0 ) ] . ShouldBe ( 0 ) ;
52
- watchdog1 . Strikes [ new StoredReplica ( replicaId1 . Id , Heartbeat : 1 ) ] . ShouldBe ( 0 ) ;
49
+ replicas . Single ( sr => sr . ReplicaId == replicaId1 . ReplicaId ) . Heartbeat . ShouldBe ( 1 ) ;
50
+ replicas . Single ( sr => sr . ReplicaId == replicaId2 . ReplicaId ) . Heartbeat . ShouldBe ( 0 ) ;
51
+ watchdog1 . Strikes [ new StoredReplica ( replicaId2 . ReplicaId , Heartbeat : 0 ) ] . ShouldBe ( 0 ) ;
52
+ watchdog1 . Strikes [ new StoredReplica ( replicaId1 . ReplicaId , Heartbeat : 1 ) ] . ShouldBe ( 0 ) ;
53
53
54
54
await watchdog1 . PerformIteration ( ) ;
55
55
replicas = await store . GetAll ( ) ;
56
- replicas . Single ( sr => sr . ReplicaId == replicaId1 . Id ) . Heartbeat . ShouldBe ( 2 ) ;
57
- replicas . Single ( sr => sr . ReplicaId == replicaId2 . Id ) . Heartbeat . ShouldBe ( 0 ) ;
58
- watchdog1 . Strikes [ new StoredReplica ( replicaId2 . Id , Heartbeat : 0 ) ] . ShouldBe ( 1 ) ;
59
- watchdog1 . Strikes [ new StoredReplica ( replicaId1 . Id , Heartbeat : 2 ) ] . ShouldBe ( 0 ) ;
56
+ replicas . Single ( sr => sr . ReplicaId == replicaId1 . ReplicaId ) . Heartbeat . ShouldBe ( 2 ) ;
57
+ replicas . Single ( sr => sr . ReplicaId == replicaId2 . ReplicaId ) . Heartbeat . ShouldBe ( 0 ) ;
58
+ watchdog1 . Strikes [ new StoredReplica ( replicaId2 . ReplicaId , Heartbeat : 0 ) ] . ShouldBe ( 1 ) ;
59
+ watchdog1 . Strikes [ new StoredReplica ( replicaId1 . ReplicaId , Heartbeat : 2 ) ] . ShouldBe ( 0 ) ;
60
60
61
61
await watchdog1 . PerformIteration ( ) ;
62
62
replicas = await store . GetAll ( ) ;
63
63
replicas . Count . ShouldBe ( 1 ) ;
64
- replicas . Single ( sr => sr . ReplicaId == replicaId1 . Id ) . Heartbeat . ShouldBe ( 3 ) ;
64
+ replicas . Single ( sr => sr . ReplicaId == replicaId1 . ReplicaId ) . Heartbeat . ShouldBe ( 3 ) ;
65
65
watchdog1 . Strikes . Count . ShouldBe ( 1 ) ;
66
- watchdog1 . Strikes [ new StoredReplica ( replicaId1 . Id , Heartbeat : 3 ) ] . ShouldBe ( 0 ) ;
66
+ watchdog1 . Strikes [ new StoredReplica ( replicaId1 . ReplicaId , Heartbeat : 3 ) ] . ShouldBe ( 0 ) ;
67
67
}
68
68
69
69
public abstract Task ReplicaWatchdogStartResultsInAddedReplicaInStore ( ) ;
70
70
public async Task ReplicaWatchdogStartResultsInAddedReplicaInStore ( Task < IFunctionStore > storeTask )
71
71
{
72
72
var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
73
- var replicaId1 = new ReplicaId ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
73
+ var replicaId1 = new ClusterInfo ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
74
74
using var watchdog1 = new ReplicaWatchdog (
75
75
replicaId1 ,
76
76
store ,
@@ -81,7 +81,7 @@ public async Task ReplicaWatchdogStartResultsInAddedReplicaInStore(Task<IFunctio
81
81
var allReplicas = await store . GetAll ( ) ;
82
82
allReplicas . Count . ShouldBe ( 1 ) ;
83
83
84
- var replicaId2 = new ReplicaId ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
84
+ var replicaId2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
85
85
using var watchdog2 = new ReplicaWatchdog (
86
86
replicaId2 ,
87
87
store ,
@@ -100,7 +100,7 @@ public async Task StrikedOutReplicaIsRemovedFromStore(Task<IFunctionStore> store
100
100
var toBeStrikedOut = Guid . NewGuid ( ) ;
101
101
Guid ? strikedOut = null ;
102
102
await store . Insert ( toBeStrikedOut ) ;
103
- var replicaId1 = new ReplicaId ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
103
+ var replicaId1 = new ClusterInfo ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
104
104
using var watchdog1 = new ReplicaWatchdog (
105
105
replicaId1 ,
106
106
store ,
@@ -117,15 +117,15 @@ public async Task StrikedOutReplicaIsRemovedFromStore(Task<IFunctionStore> store
117
117
118
118
var all = await store . GetAll ( ) ;
119
119
all . Count . ShouldBe ( 1 ) ;
120
- all . Single ( ) . ReplicaId . ShouldBe ( replicaId1 . Id ) ;
120
+ all . Single ( ) . ReplicaId . ShouldBe ( replicaId1 . ReplicaId ) ;
121
121
}
122
122
123
123
public abstract Task RunningWatchdogUpdatesItsOwnHeartbeat ( ) ;
124
124
public async Task RunningWatchdogUpdatesItsOwnHeartbeat ( Task < IFunctionStore > storeTask )
125
125
{
126
126
var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
127
127
var anyStrikesOut = false ;
128
- var replicaId1 = new ReplicaId ( Guid . NewGuid ( ) ) ;
128
+ var replicaId1 = new ClusterInfo ( Guid . NewGuid ( ) ) ;
129
129
using var watchdog1 = new ReplicaWatchdog (
130
130
replicaId1 ,
131
131
store ,
@@ -140,7 +140,7 @@ await BusyWait.Until(async () =>
140
140
var all = await store . GetAll ( ) ;
141
141
all . Count . ShouldBe ( 1 ) ;
142
142
var single = all . Single ( ) ;
143
- single . ReplicaId . ShouldBe ( replicaId1 . Id ) ;
143
+ single . ReplicaId . ShouldBe ( replicaId1 . ReplicaId ) ;
144
144
return single . Heartbeat > 0 ;
145
145
} ) ;
146
146
@@ -152,9 +152,9 @@ public async Task ReplicaIdOffsetIfCalculatedCorrectly(Task<IFunctionStore> stor
152
152
{
153
153
var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
154
154
155
- var replicaId1 = new ReplicaId ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
156
- var replicaId2 = new ReplicaId ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
157
- var replicaId3 = new ReplicaId ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) ) ;
155
+ var replicaId1 = new ClusterInfo ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
156
+ var replicaId2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
157
+ var replicaId3 = new ClusterInfo ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) ) ;
158
158
159
159
var watchdog1 = new ReplicaWatchdog ( replicaId1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , onStrikeOut : _ => { } ) ;
160
160
var watchdog2 = new ReplicaWatchdog ( replicaId2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , onStrikeOut : _ => { } ) ;
@@ -172,6 +172,54 @@ public async Task ReplicaIdOffsetIfCalculatedCorrectly(Task<IFunctionStore> stor
172
172
replicaId1 . Offset . ShouldBe ( 0 ) ;
173
173
}
174
174
175
+ public abstract Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted ( ) ;
176
+ public async Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted ( Task < IFunctionStore > storeTask )
177
+ {
178
+ var store = await storeTask . SelectAsync ( s => s . ReplicaStore ) ;
179
+
180
+ var cluster1 = new ClusterInfo ( Guid . Parse ( "10000000-0000-0000-0000-000000000000" ) ) ;
181
+ var cluster2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) ) ;
182
+ var cluster3 = new ClusterInfo ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) ) ;
183
+
184
+ var watchdog1 = new ReplicaWatchdog ( cluster1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , onStrikeOut : _ => { } ) ;
185
+ var watchdog2 = new ReplicaWatchdog ( cluster2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , onStrikeOut : _ => { } ) ;
186
+ var watchdog3 = new ReplicaWatchdog ( cluster3 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , onStrikeOut : _ => { } ) ;
187
+
188
+ await watchdog3 . Initialize ( ) ;
189
+ cluster3 . Offset . ShouldBe ( 0 ) ;
190
+ cluster3 . ReplicaCount . ShouldBe ( 1 ) ;
191
+
192
+ await watchdog2 . Initialize ( ) ;
193
+ await watchdog3 . PerformIteration ( ) ;
194
+ cluster3 . Offset . ShouldBe ( 1 ) ;
195
+ cluster3 . ReplicaCount . ShouldBe ( 2 ) ;
196
+ cluster2 . Offset . ShouldBe ( 0 ) ;
197
+ cluster2 . ReplicaCount . ShouldBe ( 2 ) ;
198
+
199
+ await watchdog1 . Initialize ( ) ;
200
+ await watchdog2 . PerformIteration ( ) ;
201
+ await watchdog3 . PerformIteration ( ) ;
202
+ cluster3 . Offset . ShouldBe ( 2 ) ;
203
+ cluster3 . ReplicaCount . ShouldBe ( 3 ) ;
204
+ cluster2 . Offset . ShouldBe ( 1 ) ;
205
+ cluster2 . ReplicaCount . ShouldBe ( 3 ) ;
206
+ cluster1 . Offset . ShouldBe ( 0 ) ;
207
+ cluster1 . ReplicaCount . ShouldBe ( 3 ) ;
208
+
209
+ await store . Delete ( cluster1 . ReplicaId ) ;
210
+ await watchdog3 . PerformIteration ( ) ;
211
+ await watchdog2 . PerformIteration ( ) ;
212
+ cluster3 . Offset . ShouldBe ( 1 ) ;
213
+ cluster3 . ReplicaCount . ShouldBe ( 2 ) ;
214
+ cluster2 . Offset . ShouldBe ( 0 ) ;
215
+ cluster2 . ReplicaCount . ShouldBe ( 2 ) ;
216
+
217
+ await store . Delete ( cluster2 . ReplicaId ) ;
218
+ await watchdog3 . PerformIteration ( ) ;
219
+ cluster3 . Offset . ShouldBe ( 0 ) ;
220
+ cluster3 . ReplicaCount . ShouldBe ( 1 ) ;
221
+ }
222
+
175
223
public abstract Task NonExistingReplicaIdOffsetIsNull ( ) ;
176
224
public Task NonExistingReplicaIdOffsetIsNull ( Task < IFunctionStore > storeTask )
177
225
{
0 commit comments