Skip to content

Commit e9d820a

Browse files
committed
Refactored effect store
1 parent 4c44ce9 commit e9d820a

File tree

17 files changed

+204
-114
lines changed

17 files changed

+204
-114
lines changed

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/EffectStoreTests.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ protected async Task SunshineScenarioTest(Task<IEffectsStore> storeTask)
1717
var functionId = TestStoredId.Create();
1818
var storedEffect1 = new StoredEffect(
1919
"EffectId1",
20+
"EffectId1".ToStoredEffectId(),
2021
IsState: false,
2122
WorkStatus.Started,
2223
Result: null,
2324
StoredException: null
2425
);
2526
var storedEffect2 = new StoredEffect(
2627
"EffectId2",
28+
"EffectId2".ToStoredEffectId(),
2729
IsState: false,
2830
WorkStatus.Completed,
2931
Result: null,
@@ -65,6 +67,7 @@ protected async Task SingleEffectWithResultLifeCycle(Task<IEffectsStore> storeTa
6567
var functionId = TestStoredId.Create();
6668
var effect = new StoredEffect(
6769
"EffectId1",
70+
"EffectId1".ToStoredEffectId(),
6871
IsState: false,
6972
WorkStatus.Started,
7073
Result: null,
@@ -103,6 +106,7 @@ protected async Task SingleFailingEffectLifeCycle(Task<IEffectsStore> storeTask)
103106
);
104107
var storedEffect = new StoredEffect(
105108
"EffectId1",
109+
"EffectId1".ToStoredEffectId(),
106110
IsState: false,
107111
WorkStatus.Started,
108112
Result: null,
@@ -130,13 +134,15 @@ protected async Task EffectCanBeDeleted(Task<IEffectsStore> storeTask)
130134
var functionId = TestStoredId.Create();
131135
var storedEffect1 = new StoredEffect(
132136
"EffectId1",
137+
"EffectId1".ToStoredEffectId(),
133138
IsState: false,
134139
WorkStatus.Started,
135140
Result: null,
136141
StoredException: null
137142
);
138143
var storedEffect2 = new StoredEffect(
139144
"EffectId2",
145+
"EffectId2".ToStoredEffectId(),
140146
IsState: false,
141147
WorkStatus.Completed,
142148
Result: null,
@@ -150,17 +156,17 @@ await store
150156
.SelectAsync(sas => sas.Count() == 2)
151157
.ShouldBeTrueAsync();
152158

153-
await store.DeleteEffectResult(functionId, storedEffect2.EffectId, isState: false);
159+
await store.DeleteEffectResult(functionId, storedEffect2.EffectId.ToStoredEffectId(), isState: false);
154160
var storedEffects = await store.GetEffectResults(functionId);
155161
storedEffects.Count.ShouldBe(1);
156162
storedEffects[0].EffectId.ShouldBe(storedEffect1.EffectId);
157163

158-
await store.DeleteEffectResult(functionId, storedEffect2.EffectId, isState: false);
164+
await store.DeleteEffectResult(functionId, storedEffect2.EffectId.ToStoredEffectId(), isState: false);
159165
storedEffects = await store.GetEffectResults(functionId);
160166
storedEffects.Count.ShouldBe(1);
161167
storedEffects[0].EffectId.ShouldBe(storedEffect1.EffectId);
162168

163-
await store.DeleteEffectResult(functionId, storedEffect1.EffectId, isState: false);
169+
await store.DeleteEffectResult(functionId, storedEffect1.EffectId.ToStoredEffectId(), isState: false);
164170
await store
165171
.GetEffectResults(functionId)
166172
.SelectAsync(sas => sas.Any())
@@ -176,13 +182,15 @@ protected async Task DeleteFunctionIdDeletesAllRelatedEffects(Task<IEffectsStore
176182

177183
var storedEffect1 = new StoredEffect(
178184
"EffectId1",
185+
"EffectId1".ToStoredEffectId(),
179186
IsState: false,
180187
WorkStatus.Started,
181188
Result: null,
182189
StoredException: null
183190
);
184191
var storedEffect2 = new StoredEffect(
185192
"EffectId2",
193+
"EffectId2".ToStoredEffectId(),
186194
IsState: false,
187195
WorkStatus.Completed,
188196
Result: null,
@@ -220,13 +228,15 @@ protected async Task TruncateDeletesAllEffects(Task<IEffectsStore> storeTask)
220228

221229
var storedEffect1 = new StoredEffect(
222230
"EffectId1",
231+
"EffectId1".ToStoredEffectId(),
223232
IsState: false,
224233
WorkStatus.Started,
225234
Result: null,
226235
StoredException: null
227236
);
228237
var storedEffect2 = new StoredEffect(
229238
"EffectId2",
239+
"EffectId2".ToStoredEffectId(),
230240
IsState: false,
231241
WorkStatus.Completed,
232242
Result: null,
@@ -249,6 +259,4 @@ await store
249259
.SelectAsync(e => e.Any())
250260
.ShouldBeFalseAsync();
251261
}
252-
253-
254262
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/ControlPanelTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Cleipnir.ResilientFunctions.Messaging;
1111
using Cleipnir.ResilientFunctions.Reactive.Extensions;
1212
using Cleipnir.ResilientFunctions.Storage;
13-
using Cleipnir.ResilientFunctions.Tests.TestTemplates.WatchDogsTests;
1413
using Cleipnir.ResilientFunctions.Tests.Utils;
1514
using Shouldly;
1615

@@ -1285,6 +1284,7 @@ await store.EffectsStore.SetEffectResult(
12851284
rAction.MapToStoredId(functionId),
12861285
new StoredEffect(
12871286
new EffectId("SomeId"),
1287+
"SomeId".ToStoredEffectId(),
12881288
IsState: false,
12891289
WorkStatus.Completed,
12901290
Result: "SomeResult".ToJson().ToUtf8Bytes(),
@@ -1322,6 +1322,7 @@ await store.EffectsStore.SetEffectResult(
13221322
rAction.MapToStoredId(functionId),
13231323
new StoredEffect(
13241324
new EffectId("SomeId"),
1325+
"SomeId".ToStoredEffectId(),
13251326
IsState: false,
13261327
WorkStatus.Completed,
13271328
Result: "SomeResult".ToJson().ToUtf8Bytes(),

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StatesStoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ await statesStore.SetEffectResult(
3838
state2.IsState.ShouldBeTrue();
3939
state2.Result.ShouldBe("SomeJson#2".ToUtf8Bytes());
4040

41-
await statesStore.DeleteEffectResult(flowId, state1.EffectId, isState: true);
41+
await statesStore.DeleteEffectResult(flowId, state1.EffectId.ToStoredEffectId(), isState: true);
4242

4343
states = await statesStore.GetEffectResults(flowId);
4444
states.Count.ShouldBe(1);

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreCrudTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ await store.EffectsStore.SetEffectResult(
167167
await store.CorrelationStore.SetCorrelation(functionId, "SomeCorrelationId");
168168
await store.EffectsStore.SetEffectResult(
169169
functionId,
170-
new StoredEffect("SomeEffectId", IsState: false, WorkStatus.Completed, Result: null, StoredException: null)
170+
new StoredEffect("SomeEffectId", "SomeEffectId".ToStoredEffectId(),IsState: false, WorkStatus.Completed, Result: null, StoredException: null)
171171
);
172172
await store.MessageStore.AppendMessage(functionId, new StoredMessage("SomeJson".ToUtf8Bytes(), "SomeType".ToUtf8Bytes()));
173173
await store.TimeoutStore.UpsertTimeout(

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ await store.CreateFunction(
11081108
parent: null
11091109
).ShouldBeTrueAsync();
11101110

1111-
await effectsStore.SetEffectResult(functionId, new StoredEffect(EffectId: "", IsState: true, WorkStatus.Completed, "some default state".ToUtf8Bytes(), StoredException: null));
1111+
await effectsStore.SetEffectResult(functionId, new StoredEffect(EffectId: "", "".ToStoredEffectId(), IsState: true, WorkStatus.Completed, "some default state".ToUtf8Bytes(), StoredException: null));
11121112

11131113
var storedEffects = await effectsStore.GetEffectResults(functionId);
11141114
storedEffects.Count.ShouldBe(1);

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableEffectStore.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4-
using Cleipnir.ResilientFunctions.Domain;
54
using Cleipnir.ResilientFunctions.Storage;
65

76
namespace Cleipnir.ResilientFunctions.Tests.TestTemplates.WatchDogsTests;
@@ -29,14 +28,19 @@ public Task Truncate()
2928
public Task SetEffectResult(StoredId storedId, StoredEffect storedEffect)
3029
=> _crashed
3130
? Task.FromException(new TimeoutException())
32-
: _inner.SetEffectResult(storedId, storedEffect);
31+
: _inner.SetEffectResult(storedId, storedEffect);
32+
33+
public Task SetEffectResults(StoredId storedId, IEnumerable<StoredEffect> storedEffects)
34+
=> _crashed
35+
? Task.FromException(new TimeoutException())
36+
: _inner.SetEffectResults(storedId, storedEffects);
3337

3438
public Task<IReadOnlyList<StoredEffect>> GetEffectResults(StoredId storedId)
3539
=> _crashed
3640
? Task.FromException<IReadOnlyList<StoredEffect>>(new TimeoutException())
3741
: _inner.GetEffectResults(storedId);
3842

39-
public Task DeleteEffectResult(StoredId storedId, EffectId effectId, bool isState)
43+
public Task DeleteEffectResult(StoredId storedId, StoredEffectId effectId, bool isState)
4044
=> _crashed
4145
? Task.FromException(new TimeoutException())
4246
: _inner.DeleteEffectResult(storedId, effectId, isState);

Core/Cleipnir.ResilientFunctions/Domain/Effect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public async Task Clear(string id)
283283
if (!effectResults.ContainsKey(id))
284284
return;
285285

286-
await effectsStore.DeleteEffectResult(storedId, id, isState: false);
286+
await effectsStore.DeleteEffectResult(storedId, id.ToStoredEffectId(), isState: false);
287287
lock (_sync)
288288
effectResults.Remove(id);
289289
}

Core/Cleipnir.ResilientFunctions/Domain/ExistingEffects.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task<WorkStatus> GetStatus(EffectId effectId)
4747
public async Task Remove(string effectId)
4848
{
4949
var storedEffects = await GetStoredEffects();
50-
await effectsStore.DeleteEffectResult(storedId, effectId, isState: false);
50+
await effectsStore.DeleteEffectResult(storedId, effectId.ToStoredEffectId(), isState: false);
5151
storedEffects.Remove(effectId);
5252
}
5353

@@ -61,14 +61,14 @@ private async Task Set(StoredEffect storedEffect)
6161
public Task SetValue<TValue>(string effectId, TValue value) => SetSucceeded(effectId, value);
6262

6363
public Task SetStarted(string effectId)
64-
=> Set(new StoredEffect(effectId, IsState: false, WorkStatus.Started, Result: null, StoredException: null));
64+
=> Set(new StoredEffect(effectId, StoredEffectId.Create(effectId), IsState: false, WorkStatus.Started, Result: null, StoredException: null));
6565

6666
public Task SetSucceeded(string effectId)
67-
=> Set(new StoredEffect(effectId, IsState: false, WorkStatus.Completed, Result: null, StoredException: null));
67+
=> Set(new StoredEffect(effectId, StoredEffectId.Create(effectId), IsState: false, WorkStatus.Completed, Result: null, StoredException: null));
6868

6969
public Task SetSucceeded<TResult>(string effectId, TResult result)
70-
=> Set(new StoredEffect(effectId, IsState: false, WorkStatus.Completed, Result: serializer.SerializeEffectResult(result), StoredException: null));
70+
=> Set(new StoredEffect(effectId,StoredEffectId.Create(effectId), IsState: false, WorkStatus.Completed, Result: serializer.SerializeEffectResult(result), StoredException: null));
7171

7272
public Task SetFailed(string effectId, Exception exception)
73-
=> Set(new StoredEffect(effectId, IsState: false, WorkStatus.Failed, Result: null, StoredException: serializer.SerializeException(exception)));
73+
=> Set(new StoredEffect(effectId, StoredEffectId.Create(effectId), IsState: false, WorkStatus.Failed, Result: null, StoredException: serializer.SerializeException(exception)));
7474
}

Core/Cleipnir.ResilientFunctions/Domain/ExistingStates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private async Task<Dictionary<StateId, StoredState>> GetStoredStates()
5656
public async Task Remove(string stateId)
5757
{
5858
var storedStates = await GetStoredStates();
59-
await _effectsStore.DeleteEffectResult(_storedId, stateId, isState: true);
59+
await _effectsStore.DeleteEffectResult(_storedId, stateId.ToStoredEffectId(), isState: true);
6060
storedStates.Remove(stateId);
6161
}
6262

Core/Cleipnir.ResilientFunctions/Domain/States.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private async Task RemoveInner(string id)
100100
if (!existingStoredStates.ContainsKey(id))
101101
return;
102102

103-
await _effectStore.DeleteEffectResult(_storedId, id, isState: true);
103+
await _effectStore.DeleteEffectResult(_storedId, id.ToStoredEffectId(), isState: true);
104104

105105
lock (_sync)
106106
{

0 commit comments

Comments
 (0)