Skip to content

Commit 780fdb9

Browse files
committed
Move StoredEffect's ResultType next to Result and make it required
1 parent 85bb569 commit 780fdb9

10 files changed

Lines changed: 104 additions & 49 deletions

File tree

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

Lines changed: 48 additions & 20 deletions
Large diffs are not rendered by default.

‎Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/ControlPanelTests.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ await store.SetEffectResult(
12111211
"SomeId".GetHashCode().ToEffectId(),
12121212
WorkStatus.Completed,
12131213
Result: "SomeResult".ToJson().ToUtf8Bytes(),
1214+
ResultType: null,
12141215
StoredException: null,
12151216
Alias: null
12161217
).ToStoredChange(rAction.MapToStoredId(functionId.Instance), Insert),
@@ -1251,6 +1252,7 @@ await store.SetEffectResult(
12511252
"SomeId".GetHashCode().ToEffectId(),
12521253
WorkStatus.Completed,
12531254
Result: "SomeResult".ToJson().ToUtf8Bytes(),
1255+
ResultType: null,
12541256
StoredException: null,
12551257
Alias: null
12561258
).ToStoredChange(rAction.MapToStoredId(functionId.Instance), Insert),

‎Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/EffectTests.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ public async Task ExistingEffectsFuncIsOnlyInvokedAfterGettingValue(Task<IFuncti
418418
effectId,
419419
WorkStatus.Completed,
420420
Result: serializedResult,
421+
ResultType: typeMapper.GetTypeId(typeof(int)),
421422
StoredException: null,
422-
Alias: "test_alias",
423-
ResultType: typeMapper.GetTypeId(typeof(int))
423+
Alias: "test_alias"
424424
);
425425

426426
// Pass existing effects to constructor - they should be eagerly loaded
@@ -744,6 +744,7 @@ public async Task DelayedFlushIsReflectedInUnderlyingStoreForSet(Task<IFunctionS
744744
effectId1,
745745
WorkStatus.Completed,
746746
Result: "hello world".ToUtf8Bytes(),
747+
ResultType: null,
747748
StoredException: null,
748749
Alias: null
749750
);
@@ -758,6 +759,7 @@ await effectStore
758759
effectId2,
759760
WorkStatus.Completed,
760761
Result: "hello universe".ToUtf8Bytes(),
762+
ResultType: null,
761763
StoredException: null,
762764
Alias: null
763765
);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ await store.SetEffectResult(
177177
);
178178
await store.SetEffectResult(
179179
storedId,
180-
new StoredEffect(2.ToEffectId(), WorkStatus.Completed, Result: null, StoredException: null, Alias: null).ToStoredChange(storedId, Insert),
180+
new StoredEffect(2.ToEffectId(), WorkStatus.Completed, Result: null, ResultType: null, StoredException: null, Alias: null).ToStoredChange(storedId, Insert),
181181
owner: null, session: null
182182
);
183183
await store.MessageStore.AppendMessage(new StoredMessage(storedId, "SomeJson".ToUtf8Bytes(), new TypeId(123), Replica: ReplicaId.Empty, Position: 0));
@@ -524,13 +524,15 @@ public async Task RestartExecutionsIncludesExistingEffects(Task<IFunctionStore>
524524
EffectId: "effect1".GetHashCode().ToEffectId(),
525525
WorkStatus: WorkStatus.Completed,
526526
Result: "result1".ToUtf8Bytes(),
527+
ResultType: null,
527528
StoredException: null,
528529
Alias: null
529530
);
530531
var effect2 = new StoredEffect(
531532
EffectId: "effect2".GetHashCode().ToEffectId(),
532533
WorkStatus: WorkStatus.Completed,
533534
Result: "result2".ToUtf8Bytes(),
535+
ResultType: null,
534536
StoredException: null,
535537
Alias: null
536538
);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ protected async Task DefaultStateCanSetAndFetchedAfterwards(Task<IFunctionStore>
856856
);
857857
session.ShouldBeNull();
858858

859-
await effectsStore.SetEffectResult(functionId, new StoredEffect(0.ToEffectId(), WorkStatus.Completed, "some default state".ToUtf8Bytes(), StoredException: null, Alias: null).ToStoredChange(functionId, Insert), owner: null, session: null);
859+
await effectsStore.SetEffectResult(functionId, new StoredEffect(0.ToEffectId(), WorkStatus.Completed, "some default state".ToUtf8Bytes(), ResultType: null, StoredException: null, Alias: null).ToStoredChange(functionId, Insert), owner: null, session: null);
860860

861861
var storedEffects = await effectsStore.GetEffectResults(functionId);
862862
storedEffects.Count.ShouldBe(1);
@@ -1204,6 +1204,7 @@ protected async Task FunctionCanBeCreatedWithMessagesAndEffects(Task<IFunctionSt
12041204
effectId1,
12051205
WorkStatus.Completed,
12061206
Result: "hello world".ToUtf8Bytes(),
1207+
ResultType: null,
12071208
StoredException: null,
12081209
Alias: null
12091210
);
@@ -1212,6 +1213,7 @@ protected async Task FunctionCanBeCreatedWithMessagesAndEffects(Task<IFunctionSt
12121213
effectId2,
12131214
WorkStatus.Completed,
12141215
Result: "hello universe".ToUtf8Bytes(),
1216+
ResultType: null,
12151217
StoredException: null,
12161218
Alias: null
12171219
);
@@ -1365,6 +1367,7 @@ protected async Task FunctionCanBeCreatedWithEffectsOnly(Task<IFunctionStore> st
13651367
effectId1,
13661368
WorkStatus.Completed,
13671369
Result: "hello world".ToUtf8Bytes(),
1370+
ResultType: null,
13681371
StoredException: null,
13691372
Alias: null
13701373
);
@@ -1373,6 +1376,7 @@ protected async Task FunctionCanBeCreatedWithEffectsOnly(Task<IFunctionStore> st
13731376
effectId2,
13741377
WorkStatus.Completed,
13751378
Result: "hello universe".ToUtf8Bytes(),
1379+
ResultType: null,
13761380
StoredException: null,
13771381
Alias: null
13781382
);
@@ -1449,6 +1453,7 @@ await store.SetEffectResult(
14491453
"Test".GetHashCode().ToEffectId(),
14501454
WorkStatus.Completed,
14511455
"hallo effect".ToUtf8Bytes(),
1456+
ResultType: null,
14521457
StoredException: null,
14531458
Alias: null
14541459
).ToStoredChange(functionId, Insert),

‎Core/Cleipnir.ResilientFunctions.Tests/UtilsTests/PrintEffectsTests.cs‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void PrintSingleCompletedEffect()
2929
new EffectId([1]),
3030
WorkStatus.Completed,
3131
Result: null,
32+
ResultType: null,
3233
StoredException: null,
3334
Alias: null
3435
)
@@ -63,6 +64,7 @@ public void PrintEffectWithAlias()
6364
new EffectId([1]),
6465
WorkStatus.Completed,
6566
Result: null,
67+
ResultType: null,
6668
StoredException: null,
6769
Alias: "my-effect"
6870
)
@@ -97,6 +99,7 @@ public void PrintFailedEffect()
9799
new EffectId([1]),
98100
WorkStatus.Failed,
99101
Result: null,
102+
ResultType: null,
100103
StoredException: new StoredException(
101104
"Something went wrong",
102105
"Stack trace here",
@@ -135,6 +138,7 @@ public void PrintStartedEffect()
135138
new EffectId([1]),
136139
WorkStatus.Started,
137140
Result: null,
141+
ResultType: null,
138142
StoredException: null,
139143
Alias: "in-progress"
140144
)
@@ -169,20 +173,23 @@ public void PrintEffectHierarchy()
169173
new EffectId([1]),
170174
WorkStatus.Completed,
171175
Result: null,
176+
ResultType: null,
172177
StoredException: null,
173178
Alias: "parent"
174179
),
175180
new StoredEffect(
176181
new EffectId([1, 1]),
177182
WorkStatus.Completed,
178183
Result: null,
184+
ResultType: null,
179185
StoredException: null,
180186
Alias: "child-1"
181187
),
182188
new StoredEffect(
183189
new EffectId([1, 2]),
184190
WorkStatus.Completed,
185191
Result: null,
192+
ResultType: null,
186193
StoredException: null,
187194
Alias: "child-2"
188195
)
@@ -220,27 +227,31 @@ public void PrintDeepEffectHierarchy()
220227
new EffectId([1]),
221228
WorkStatus.Completed,
222229
Result: null,
230+
ResultType: null,
223231
StoredException: null,
224232
Alias: "root"
225233
),
226234
new StoredEffect(
227235
new EffectId([1, 1]),
228236
WorkStatus.Completed,
229237
Result: null,
238+
ResultType: null,
230239
StoredException: null,
231240
Alias: "level-1"
232241
),
233242
new StoredEffect(
234243
new EffectId([1, 1, 1]),
235244
WorkStatus.Completed,
236245
Result: null,
246+
ResultType: null,
237247
StoredException: null,
238248
Alias: "level-2"
239249
),
240250
new StoredEffect(
241251
new EffectId([1, 1, 1, 1]),
242252
WorkStatus.Failed,
243253
Result: null,
254+
ResultType: null,
244255
StoredException: new StoredException("Deep error", null, "System.Exception"),
245256
Alias: "level-3-failed"
246257
)
@@ -279,20 +290,23 @@ public void PrintMultipleRootEffects()
279290
new EffectId([1]),
280291
WorkStatus.Completed,
281292
Result: null,
293+
ResultType: null,
282294
StoredException: null,
283295
Alias: "first-root"
284296
),
285297
new StoredEffect(
286298
new EffectId([2]),
287299
WorkStatus.Started,
288300
Result: null,
301+
ResultType: null,
289302
StoredException: null,
290303
Alias: "second-root"
291304
),
292305
new StoredEffect(
293306
new EffectId([3]),
294307
WorkStatus.Failed,
295308
Result: null,
309+
ResultType: null,
296310
StoredException: new StoredException("Error", null, "System.Exception"),
297311
Alias: "third-root"
298312
)
@@ -326,13 +340,13 @@ public void PrintComplexEffectTree()
326340
var storedId = TestStoredId.Create();
327341
var existingEffects = new List<StoredEffect>
328342
{
329-
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, "root-1"),
330-
new StoredEffect(new EffectId([1, 1]), WorkStatus.Completed, null, null, "root-1-child-1"),
331-
new StoredEffect(new EffectId([1, 2]), WorkStatus.Completed, null, null, "root-1-child-2"),
332-
new StoredEffect(new EffectId([1, 2, 1]), WorkStatus.Failed, null,
343+
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, null, "root-1"),
344+
new StoredEffect(new EffectId([1, 1]), WorkStatus.Completed, null, null, null, "root-1-child-1"),
345+
new StoredEffect(new EffectId([1, 2]), WorkStatus.Completed, null, null, null, "root-1-child-2"),
346+
new StoredEffect(new EffectId([1, 2, 1]), WorkStatus.Failed, null, null,
333347
new StoredException("Error", null, "TestException"), "root-1-child-2-grandchild"),
334-
new StoredEffect(new EffectId([2]), WorkStatus.Started, null, null, "root-2"),
335-
new StoredEffect(new EffectId([2, 1]), WorkStatus.Completed, null, null, "root-2-child-1")
348+
new StoredEffect(new EffectId([2]), WorkStatus.Started, null, null, null, "root-2"),
349+
new StoredEffect(new EffectId([2, 1]), WorkStatus.Completed, null, null, null, "root-2-child-1")
336350
};
337351

338352
var effectResults = new EffectResults(
@@ -367,9 +381,9 @@ public void PrintEffectTreeWithMissingIntermediateEffect()
367381
var storedId = TestStoredId.Create();
368382
var existingEffects = new List<StoredEffect>
369383
{
370-
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, "root"),
384+
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, null, "root"),
371385
// Missing [1, 2] - this should be automatically added
372-
new StoredEffect(new EffectId([1, 2, 1]), WorkStatus.Completed, null, null, "grandchild")
386+
new StoredEffect(new EffectId([1, 2, 1]), WorkStatus.Completed, null, null, null, "grandchild")
373387
};
374388

375389
var effectResults = new EffectResults(
@@ -401,9 +415,9 @@ public void PrintEffectTreeWithMultipleMissingAncestors()
401415
var storedId = TestStoredId.Create();
402416
var existingEffects = new List<StoredEffect>
403417
{
404-
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, "root"),
418+
new StoredEffect(new EffectId([1]), WorkStatus.Completed, null, null, null, "root"),
405419
// Missing [1, 2] and [1, 2, 3] - both should be automatically added
406-
new StoredEffect(new EffectId([1, 2, 3, 4]), WorkStatus.Failed, null,
420+
new StoredEffect(new EffectId([1, 2, 3, 4]), WorkStatus.Failed, null, null,
407421
new StoredException("Deep error", null, "System.Exception"), "deep-failed")
408422
};
409423

‎Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,15 @@ public IReadOnlyList<StoredEffect> MapInitialEffects(IEnumerable<InitialEffect>
507507
e.Id,
508508
e.Status ?? WorkStatus.Completed,
509509
Result: resultBytes,
510+
ResultType: resultType,
510511
StoredException: null,
511-
Alias: e.Alias ?? e.Id.Serialize().ToStringValue(),
512-
ResultType: resultType);
512+
Alias: e.Alias ?? e.Id.Serialize().ToStringValue());
513513
}
514514
return new StoredEffect(
515515
e.Id,
516516
WorkStatus.Failed,
517517
Result: null,
518+
ResultType: null,
518519
StoredException: FatalWorkflowException.CreateNonGeneric(flowId, e.Exception).ToStoredException(),
519520
Alias: e.Alias
520521
);

‎Core/Cleipnir.ResilientFunctions/Domain/EffectPrinter.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private static void AddMissingAncestors(Dictionary<EffectId, PendingEffectChange
113113
parentId,
114114
WorkStatus.Started,
115115
Result: null,
116+
ResultType: null,
116117
StoredException: null,
117118
Alias: null
118119
);

‎Core/Cleipnir.ResilientFunctions/Domain/ExistingEffects.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ private async Task Set(StoredEffect storedEffect)
116116

117117
public Task SetStarted(int effectId) => SetStarted(effectId.ToEffectId());
118118
public Task SetStarted(EffectId effectId)
119-
=> Set(new StoredEffect(effectId, WorkStatus.Started, Result: null, StoredException: null, Alias: null));
119+
=> Set(new StoredEffect(effectId, WorkStatus.Started, Result: null, ResultType: null, StoredException: null, Alias: null));
120120

121121
public Task SetSucceeded(int effectId) => SetSucceeded(effectId.ToEffectId());
122122
public Task SetSucceeded(EffectId effectId)
123-
=> Set(new StoredEffect(effectId, WorkStatus.Completed, Result: null, StoredException: null, Alias: null));
123+
=> Set(new StoredEffect(effectId, WorkStatus.Completed, Result: null, ResultType: null, StoredException: null, Alias: null));
124124

125125
public Task SetSucceeded<TResult>(int effectId, TResult result) => SetSucceeded(effectId.ToEffectId(), result);
126126
public Task SetSucceeded<TResult>(EffectId effectId, TResult result)
@@ -132,16 +132,16 @@ public Task SetSucceeded<TResult>(EffectId effectId, TResult result)
132132
effectId,
133133
WorkStatus.Completed,
134134
Result: serializedResult,
135+
ResultType: typeMapper.GetTypeId(resultType),
135136
StoredException: null,
136-
Alias: null,
137-
ResultType: typeMapper.GetTypeId(resultType)
137+
Alias: null
138138
)
139139
);
140140
}
141141

142142
public Task SetFailed(int effectId, Exception exception) => SetFailed(effectId.ToEffectId(), exception);
143143
public Task SetFailed(EffectId effectId, Exception exception)
144-
=> Set(new StoredEffect(effectId, WorkStatus.Failed, Result: null, StoredException: FatalWorkflowException.CreateNonGeneric(flowId, exception).ToStoredException(), Alias: null));
144+
=> Set(new StoredEffect(effectId, WorkStatus.Failed, Result: null, ResultType: null, StoredException: FatalWorkflowException.CreateNonGeneric(flowId, exception).ToStoredException(), Alias: null));
145145

146146
public string EffectTree()
147147
{

‎Core/Cleipnir.ResilientFunctions/Storage/Types.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ public record StoredEffect(
126126
EffectId EffectId,
127127
WorkStatus WorkStatus,
128128
byte[]? Result,
129-
StoredException? StoredException,
130-
string? Alias,
131129
// The id of the type Result was serialized as (see TypeMapper) - null when there is no result. Persisted
132130
// alongside the result so it can be deserialized without the caller stating the type; the id -> type mapping
133131
// is persisted to the type store before any effect referencing it.
134-
TypeId? ResultType = null
132+
TypeId? ResultType,
133+
StoredException? StoredException,
134+
string? Alias
135135
)
136136
{
137137
public static StoredEffect CreateCompleted(EffectId effectId, byte[]? result, TypeId? resultType, string? alias)
138-
=> new(effectId, WorkStatus.Completed, result, StoredException: null, alias, resultType);
138+
=> new(effectId, WorkStatus.Completed, result, resultType, StoredException: null, alias);
139139
public static StoredEffect CreateCompleted(EffectId effectId, string? alias)
140-
=> new(effectId, WorkStatus.Completed, Result: null, StoredException: null, alias);
140+
=> new(effectId, WorkStatus.Completed, Result: null, ResultType: null, StoredException: null, alias);
141141
public static StoredEffect CreateStarted(EffectId effectId, string? alias)
142-
=> new(effectId, WorkStatus.Started, Result: null, StoredException: null, alias);
142+
=> new(effectId, WorkStatus.Started, Result: null, ResultType: null, StoredException: null, alias);
143143
public static StoredEffect CreateFailed(EffectId effectId, StoredException storedException, string? alias)
144-
=> new(effectId, WorkStatus.Failed, Result: null, storedException, alias);
144+
=> new(effectId, WorkStatus.Failed, Result: null, ResultType: null, storedException, alias);
145145

146146
public byte[] Serialize()
147147
{
@@ -172,7 +172,7 @@ public static StoredEffect Deserialize(byte[] bytes)
172172
? default(TypeId?)
173173
: TypeId.Deserialize(parts[5]);
174174

175-
return new StoredEffect(effect, status, result, exception, alias, resultType);
175+
return new StoredEffect(effect, status, result, resultType, exception, alias);
176176
}
177177
};
178178

0 commit comments

Comments
 (0)