Skip to content

Commit 0cdab18

Browse files
committed
Removed result from StoredFlow
1 parent 6161dfd commit 0cdab18

19 files changed

Lines changed: 98 additions & 67 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,14 @@ protected async Task SucceedingExistingFunctionFromControlPanelSucceeds(Task<IFu
359359
await controlPanel.Refresh();
360360
controlPanel.Status.ShouldBe(Status.Succeeded);
361361
controlPanel.Result.ShouldBe("hello world");
362-
363-
var sf = await store.GetFunction(rFunc.MapToStoredId(functionId.Instance));
362+
363+
var storedId = rFunc.MapToStoredId(functionId.Instance);
364+
var sf = await store.GetFunction(storedId);
364365
sf.ShouldNotBeNull();
365366
sf.Status.ShouldBe(Status.Succeeded);
366-
var result = DefaultSerializer.Instance.Deserialize<string>(sf.Result!);
367+
var results = await store.GetResults([storedId]);
368+
var resultBytes = results[storedId];
369+
var result = DefaultSerializer.Instance.Deserialize<string>(resultBytes!);
367370
result.ShouldBe("hello world");
368371

369372
unhandledExceptionCatcher.ShouldNotHaveExceptions();

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/ReInvocationTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ protected async Task FuncReInvocationSunshineScenario(Task<IFunctionStore> store
193193
var controlPanel = await rFunc.ControlPanel(flowInstance).ShouldNotBeNullAsync();
194194
await controlPanel.Restart();
195195

196-
var function = await store.GetFunction(rFunc.MapToStoredId(functionId.Instance));
196+
var storedId = rFunc.MapToStoredId(functionId.Instance);
197+
var function = await store.GetFunction(storedId);
197198
function.ShouldNotBeNull();
198199
function.Status.ShouldBe(Status.Succeeded);
199-
function.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("something");
200+
var results = await store.GetResults([storedId]);
201+
var resultBytes = results[storedId];
202+
resultBytes!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("something");
200203

201204
unhandledExceptionCatcher.ShouldNotHaveExceptions();
202205
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/ScheduleReInvocationTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ protected async Task FuncReInvocationSunshineScenario(Task<IFunctionStore> store
9999
var controlPanel = await rFunc.ControlPanel(flowInstance).ShouldNotBeNullAsync();
100100
await controlPanel.ScheduleRestart();
101101

102+
var storedId = rFunc.MapToStoredId(functionId.Instance);
102103
await BusyWait.Until(
103-
() => store.GetFunction(rFunc.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded)
104+
() => store.GetFunction(storedId).Map(sf => sf?.Status == Status.Succeeded)
104105
);
105106

106-
var function = await store.GetFunction(rFunc.MapToStoredId(functionId.Instance));
107+
var function = await store.GetFunction(storedId);
107108
function.ShouldNotBeNull();
108109
function.Status.ShouldBe(Status.Succeeded);
109-
function.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("something");
110+
var results = await store.GetResults([storedId]);
111+
var resultBytes = results[storedId];
112+
resultBytes!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("something");
110113

111114
unhandledExceptionCatcher.ShouldNotHaveExceptions();
112115
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/SunshineTests.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ async Task<string> ToUpper(string s)
4343
var result = await rFunc("hello", "hello");
4444
result.ShouldBe("HELLO");
4545

46-
var storedFunction = await store.GetFunction(
47-
reg.MapToStoredId("hello".ToFlowInstance())
48-
);
46+
var storedId = reg.MapToStoredId("hello".ToFlowInstance());
47+
var storedFunction = await store.GetFunction(storedId);
4948
storedFunction.ShouldNotBeNull();
5049
storedFunction.Status.ShouldBe(Status.Succeeded);
51-
storedFunction.Result.ShouldNotBeNull();
52-
var storedResult = storedFunction.Result.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>();
50+
var results = await store.GetResults([storedId]);
51+
var resultBytes = results[storedId];
52+
resultBytes.ShouldNotBeNull();
53+
var storedResult = resultBytes.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>();
5354
storedResult.ShouldBe("HELLO");
5455

5556
unhandledExceptionHandler.ShouldNotHaveExceptions();
@@ -75,16 +76,19 @@ public async Task SunshineScenarioParamless(Task<IFunctionStore> storeTask)
7576

7677
await invoke("SomeInstanceId");
7778
flag.Position.ShouldBe(FlagPosition.Raised);
78-
79-
var storedFunction = await store.GetFunction(reg.MapToStoredId("SomeInstanceId"));
79+
80+
var storedId = reg.MapToStoredId("SomeInstanceId");
81+
var storedFunction = await store.GetFunction(storedId);
8082
storedFunction.ShouldNotBeNull();
8183
storedFunction.Status.ShouldBe(Status.Succeeded);
82-
storedFunction.Result.ShouldBeNull();
84+
var results = await store.GetResults([storedId]);
85+
var resultBytes = results.TryGetValue(storedId, out var rb) ? rb : null;
86+
resultBytes.ShouldBeNull();
8387
storedFunction.Parameter.ShouldBeNull();
84-
88+
8589
unhandledExceptionHandler.ShouldNotHaveExceptions();
8690
}
87-
91+
8892
public abstract Task SunshineScenarioParamlessWithResultReturnType();
8993
public async Task SunshineScenarioParamlessWithResultReturnType(Task<IFunctionStore> storeTask)
9094
{
@@ -106,16 +110,19 @@ public async Task SunshineScenarioParamlessWithResultReturnType(Task<IFunctionSt
106110

107111
await invoke("SomeInstanceId");
108112
flag.Position.ShouldBe(FlagPosition.Raised);
109-
110-
var storedFunction = await store.GetFunction(reg.MapToStoredId("SomeInstanceId"));
113+
114+
var storedId = reg.MapToStoredId("SomeInstanceId");
115+
var storedFunction = await store.GetFunction(storedId);
111116
storedFunction.ShouldNotBeNull();
112117
storedFunction.Status.ShouldBe(Status.Succeeded);
113-
storedFunction.Result.ShouldBeNull();
118+
var results = await store.GetResults([storedId]);
119+
var resultBytes = results.TryGetValue(storedId, out var rb) ? rb : null;
120+
resultBytes.ShouldBeNull();
114121
storedFunction.Parameter.ShouldBeNull();
115-
122+
116123
unhandledExceptionHandler.ShouldNotHaveExceptions();
117124
}
118-
125+
119126
public abstract Task SunshineScenarioAction();
120127
public async Task SunshineScenarioAction(Task<IFunctionStore> storeTask)
121128
{

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ async Task<string> ToUpper(string s, Workflow workflow)
3737
result.ShouldBe("HELLO");
3838

3939
var functionId = new FlowId(flowType, "hello".ToFlowInstance());
40-
var storedFunction = await store.GetFunction(registration.MapToStoredId(functionId.Instance));
40+
var storedId = registration.MapToStoredId(functionId.Instance);
41+
var storedFunction = await store.GetFunction(storedId);
4142
storedFunction.ShouldNotBeNull();
42-
storedFunction.Result.ShouldNotBeNull();
43-
var storedResult = storedFunction.Result.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>();
43+
var results = await store.GetResults([storedId]);
44+
var resultBytes = results[storedId];
45+
resultBytes.ShouldNotBeNull();
46+
var storedResult = resultBytes.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>();
4447
storedResult.ShouldBe("HELLO");
4548
var effects = await store.EffectsStore.GetEffectResults(registration.MapToStoredId(functionId.Instance));
4649
effects

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ await store.CreateFunction(
3838
var stored = await store.GetFunction(StoredId);
3939
stored!.StoredId.ShouldBe(StoredId);
4040
stored.Parameter.ShouldBe(Param.ToUtf8Bytes());
41-
stored.Result.ShouldBeNull();
41+
var results = await store.GetResults([StoredId]);
42+
var resultBytes = results.TryGetValue(StoredId, out var rb) ? rb : null;
43+
resultBytes.ShouldBeNull();
4244
stored.Status.ShouldBe(Status.Executing);
4345
stored.Expires.ShouldBe(leaseExpiration);
4446
}
@@ -62,11 +64,13 @@ await store.CreateFunction(
6264
var stored = await store.GetFunction(StoredId);
6365
stored!.StoredId.ShouldBe(StoredId);
6466
stored.Parameter.ShouldBe(Param.ToUtf8Bytes());
65-
stored.Result.ShouldBeNull();
67+
var results = await store.GetResults([StoredId]);
68+
var resultBytes = results.TryGetValue(StoredId, out var rb) ? rb : null;
69+
resultBytes.ShouldBeNull();
6670
stored.Status.ShouldBe(Status.Executing);
6771
stored.Expires.ShouldBe(leaseExpiration);
6872
}
69-
73+
7074
public abstract Task FunctionCanBeCreatedWithTwoParametersAndStateSuccessfully();
7175
protected async Task FunctionCanBeCreatedWithTwoParametersAndStateSuccessfully(Task<IFunctionStore> storeTask)
7276
{
@@ -86,7 +90,9 @@ await store.CreateFunction(
8690
var stored = await store.GetFunction(StoredId);
8791
stored!.StoredId.ShouldBe(StoredId);
8892
stored.Parameter.ShouldBe(Param.ToUtf8Bytes());
89-
stored.Result.ShouldBeNull();
93+
var results = await store.GetResults([StoredId]);
94+
var resultBytes = results.TryGetValue(StoredId, out var rb) ? rb : null;
95+
resultBytes.ShouldBeNull();
9096
stored.Status.ShouldBe(Status.Executing);
9197
stored.Expires.ShouldBe(leaseExpiration);
9298
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ await store.SucceedFunction(
6060

6161
storedFunction = await store.GetFunction(functionId);
6262
storedFunction.ShouldNotBeNull();
63-
storedFunction.Result.ShouldNotBeNull();
64-
storedFunction.Result.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe(result);
63+
var results = await store.GetResults([functionId]);
64+
var resultBytes = results[functionId];
65+
resultBytes.ShouldNotBeNull();
66+
resultBytes.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe(result);
6567
}
6668

6769
public abstract Task NullParamScenarioTest();

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ await store.CreateFunction(
108108

109109
await flag.WaitForRaised();
110110

111+
var storedId = registration.MapToStoredId(functionId.Instance);
111112
await BusyWait.Until(
112-
() => store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded)
113+
() => store.GetFunction(storedId).Map(sf => sf?.Status == Status.Succeeded)
113114
);
114-
var resultJson = await store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Result);
115+
var results = await store.GetResults([storedId]);
116+
var resultJson = results[storedId];
115117
resultJson.ShouldNotBeNull();
116118
JsonConvert.DeserializeObject<string>(resultJson.ToStringFromUtf8Bytes()).ShouldBe("HELLO WORLD");
117119
}
@@ -145,11 +147,13 @@ await store.CreateFunction(
145147

146148
await flag.WaitForRaised();
147149

150+
var storedId = registration.MapToStoredId(functionId.Instance);
148151
await BusyWait.Until(
149-
() => store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded)
152+
() => store.GetFunction(storedId).Map(sf => sf?.Status == Status.Succeeded)
150153
);
151-
152-
var resultJson = await store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Result);
154+
155+
var results = await store.GetResults([storedId]);
156+
var resultJson = results[storedId];
153157
resultJson.ShouldNotBeNull();
154158
JsonConvert.DeserializeObject<string>(resultJson.ToStringFromUtf8Bytes()).ShouldBe("HELLO WORLD");
155159
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,15 @@ public async Task FunctionCompoundTest(Task<IFunctionStore> storeTask)
118118
(Param p) => $"{p.Id}-{p.Value}".ToTask()
119119
);
120120

121+
var storedId = registration.MapToStoredId(functionId.Instance);
121122
await BusyWait.Until(async () =>
122-
await store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf!.Status) == Status.Succeeded
123+
await store.GetFunction(storedId).Map(sf => sf!.Status) == Status.Succeeded
123124
);
124-
125-
var storedFunction = await store.GetFunction(registration.MapToStoredId(functionId.Instance));
126-
storedFunction!.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().CastTo<string>().ShouldBe($"{param.Id}-{param.Value}");
125+
126+
var storedFunction = await store.GetFunction(storedId);
127+
var results = await store.GetResults([storedId]);
128+
var resultBytes = results[storedId];
129+
resultBytes!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().CastTo<string>().ShouldBe($"{param.Id}-{param.Value}");
127130
}
128131
}
129132

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,22 +328,25 @@ public async Task Interrupt(IReadOnlyList<StoredId> storedIds)
328328
public async Task<FunctionState<TParam, TReturn>?> GetFunction(StoredId storedId, FlowId flowId)
329329
{
330330
var sf = await _functionStore.GetFunction(storedId);
331-
if (sf == null)
331+
if (sf == null)
332332
return null;
333333

334+
var results = await _functionStore.GetResults([storedId]);
335+
var resultBytes = results.TryGetValue(storedId, out var rb) ? rb : null;
336+
334337
return new FunctionState<TParam, TReturn>(
335338
sf.Status,
336339
sf.Expires,
337340
sf.OwnerId,
338341
Param:
339-
sf.Parameter == null
342+
sf.Parameter == null
340343
? default
341344
: Serializer.Deserialize<TParam>(sf.Parameter),
342-
Result: sf.Result == null
343-
? default
344-
: Serializer.Deserialize<TReturn>(sf.Result),
345-
FatalWorkflowException: sf.Exception == null
346-
? null
345+
Result: resultBytes == null
346+
? default
347+
: Serializer.Deserialize<TReturn>(resultBytes),
348+
FatalWorkflowException: sf.Exception == null
349+
? null
347350
: Serializer.DeserializeException(flowId, sf.Exception)
348351
);
349352
}

0 commit comments

Comments
 (0)