Skip to content

Commit

Permalink
Inlined IsState boolean in EffectId
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Dec 20, 2024
1 parent 935f656 commit 5783bf9
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@ namespace Cleipnir.ResilientFunctions.Tests.InMemoryTests;
public class DelimiterTests
{
[TestMethod]
public void flowInstanceMustNotContainUnitDelimiter()
public void FlowInstanceMustNotContainUnitDelimiter()
{
var invalidId = "Test" + Delimiters.UnitSeparator;
Assert.ThrowsException<ArgumentException>(() => new FlowInstance(invalidId));
}

[TestMethod]
public void flowTypeMustNotContainUnitDelimiter()
public void FlowTypeMustNotContainUnitDelimiter()
{
var invalidId = "Test" + Delimiters.UnitSeparator;
Assert.ThrowsException<ArgumentException>(() => new FlowType(invalidId));
}

[TestMethod]
public void EffectIdIdMustNotContainUnitDelimiter()
{
var invalidId = "Test" + Delimiters.UnitSeparator;
Assert.ThrowsException<ArgumentException>(() => new EffectId(invalidId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ protected async Task SunshineScenarioTest(Task<IEffectsStore> storeTask)
var store = await storeTask;
var functionId = TestStoredId.Create();
var storedEffect1 = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
);
var storedEffect2 = new StoredEffect(
"EffectId2",
"EffectId2".ToStoredEffectId(),
IsState: false,
"EffectId2".ToEffectId(),
"EffectId2".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: null,
StoredException: null
Expand Down Expand Up @@ -66,9 +64,8 @@ protected async Task SingleEffectWithResultLifeCycle(Task<IEffectsStore> storeTa
var store = await storeTask;
var functionId = TestStoredId.Create();
var effect = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
Expand All @@ -90,7 +87,6 @@ await store.GetEffectResults(functionId)
storedEffect.StoredException.ShouldBe(effect.StoredException);
storedEffect.Result!.ToStringFromUtf8Bytes().ShouldBe(effect.Result.ToStringFromUtf8Bytes());
storedEffect.WorkStatus.ShouldBe(effect.WorkStatus);
storedEffect.IsState.ShouldBe(effect.IsState);

}

Expand All @@ -105,9 +101,8 @@ protected async Task SingleFailingEffectLifeCycle(Task<IEffectsStore> storeTask)
"Some Exception Type"
);
var storedEffect = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
Expand All @@ -133,17 +128,15 @@ protected async Task EffectCanBeDeleted(Task<IEffectsStore> storeTask)
var store = await storeTask;
var functionId = TestStoredId.Create();
var storedEffect1 = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
);
var storedEffect2 = new StoredEffect(
"EffectId2",
"EffectId2".ToStoredEffectId(),
IsState: false,
"EffectId2".ToEffectId(),
"EffectId2".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: null,
StoredException: null
Expand Down Expand Up @@ -181,17 +174,15 @@ protected async Task DeleteFunctionIdDeletesAllRelatedEffects(Task<IEffectsStore
var otherFunctionId = new StoredId((functionId.Type.Value + 1).ToStoredType(), Instance: (functionId.Instance + "123").ToStoredInstance());

var storedEffect1 = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
);
var storedEffect2 = new StoredEffect(
"EffectId2",
"EffectId2".ToStoredEffectId(),
IsState: false,
"EffectId2".ToEffectId(),
"EffectId2".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: null,
StoredException: null
Expand Down Expand Up @@ -227,17 +218,15 @@ protected async Task TruncateDeletesAllEffects(Task<IEffectsStore> storeTask)
var otherFunctionId = new StoredId(functionId.Type, Instance: (functionId.Instance + "123").ToStoredInstance());

var storedEffect1 = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: null,
StoredException: null
);
var storedEffect2 = new StoredEffect(
"EffectId2",
"EffectId2".ToStoredEffectId(),
IsState: false,
"EffectId2".ToEffectId(),
"EffectId2".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: null,
StoredException: null
Expand Down Expand Up @@ -266,17 +255,15 @@ protected async Task BulkInsertTest(Task<IEffectsStore> storeTask)
var store = await storeTask;
var storedId = TestStoredId.Create();
var storedEffect1 = new StoredEffect(
"EffectId1",
"EffectId1".ToStoredEffectId(),
IsState: false,
"EffectId1".ToEffectId(),
"EffectId1".ToStoredEffectId(isState: false),
WorkStatus.Started,
Result: "some result 1".ToUtf8Bytes(),
StoredException: null
);
var storedEffect2 = new StoredEffect(
"EffectId2",
"EffectId2".ToStoredEffectId(),
IsState: false,
"EffectId2".ToEffectId(),
"EffectId2".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: "some result 2".ToUtf8Bytes(),
StoredException: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,9 +1283,8 @@ protected async Task EffectsAreOnlyFetchedOnPropertyInvocation(Task<IFunctionSto
await store.EffectsStore.SetEffectResult(
rAction.MapToStoredId(functionId),
new StoredEffect(
new EffectId("SomeId"),
"SomeId".ToStoredEffectId(),
IsState: false,
"SomeId".ToEffectId(),
"SomeId".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: "SomeResult".ToJson().ToUtf8Bytes(),
StoredException: null
Expand Down Expand Up @@ -1321,9 +1320,8 @@ protected async Task EffectsAreCachedAfterInitialFetch(Task<IFunctionStore> stor
await store.EffectsStore.SetEffectResult(
rAction.MapToStoredId(functionId),
new StoredEffect(
new EffectId("SomeId"),
"SomeId".ToStoredEffectId(),
IsState: false,
new EffectId("SomeId", IsState: false),
"SomeId".ToStoredEffectId(isState: false),
WorkStatus.Completed,
Result: "SomeResult".ToJson().ToUtf8Bytes(),
StoredException: null
Expand Down Expand Up @@ -1362,7 +1360,7 @@ protected async Task EffectsAreUpdatedAfterRefresh(Task<IFunctionStore> storeTas

await secondControlPanel.Refresh();
await secondControlPanel.Effects.GetValue<string>("Id").ShouldBeAsync("SomeResult");
await secondControlPanel.Effects.GetStatus("Id").ShouldBeAsync(WorkStatus.Completed);
await secondControlPanel.Effects.GetStatus("Id".ToEffectId(isState: false)).ShouldBeAsync(WorkStatus.Completed);

unhandledExceptionCatcher.ShouldNotHaveExceptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ await store
storedFunction.ShouldNotBeNull();
storedFunction.Status.ShouldBe(Status.Succeeded);
var effects = await store.EffectsStore.GetEffectResults(registration.MapToStoredId(functionId));
var stateResult = effects.Single(e => e.EffectId == "State").Result!;
var stateResult = effects.Single(e => e.EffectId == "State".ToEffectId(isState: true)).Result!;
stateResult.ShouldNotBeNull();
stateResult.ToStringFromUtf8Bytes().DeserializeFromJsonTo<State>().Value.ShouldBe(1);
await rFunc(flowInstance.Value, param).ShouldBeAsync("TEST");
Expand Down Expand Up @@ -252,7 +252,7 @@ await store
storedFunction.ShouldNotBeNull();
storedFunction.Status.ShouldBe(Status.Succeeded);
var effects = await store.EffectsStore.GetEffectResults(registration.MapToStoredId(functionId));
var state = effects.Single(e => e.EffectId == "State").Result;
var state = effects.Single(e => e.EffectId == "State".ToEffectId(isState: true)).Result;
state!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<State>().Value.ShouldBe(1);
await rAction(flowInstance.Value, param);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ await BusyWait.Until(() =>

syncedCounter.Current.ShouldBe(1);
var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
effectResults.Single(r => r.EffectId == "0").WorkStatus.ShouldBe(WorkStatus.Completed);
effectResults.Single(r => r.EffectId == "0".ToEffectId()).WorkStatus.ShouldBe(WorkStatus.Completed);

var controlPanel = await rAction.ControlPanel(flowId.Instance);
controlPanel.ShouldNotBeNull();
await controlPanel.Restart();

effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
effectResults.Single(r => r.EffectId == "0").WorkStatus.ShouldBe(WorkStatus.Completed);
effectResults.Single(r => r.EffectId == "0".ToEffectId()).WorkStatus.ShouldBe(WorkStatus.Completed);
syncedCounter.Current.ShouldBe(1);
}

Expand Down Expand Up @@ -72,14 +72,14 @@ await BusyWait.Until(() =>

syncedCounter.Current.ShouldBe(1);
var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
effectResults.Single(r => r.EffectId == "0").WorkStatus.ShouldBe(WorkStatus.Completed);
effectResults.Single(r => r.EffectId == "0".ToEffectId()).WorkStatus.ShouldBe(WorkStatus.Completed);

var controlPanel = await rAction.ControlPanel(flowId.Instance);
controlPanel.ShouldNotBeNull();
await controlPanel.Restart();

effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
effectResults.Single(r => r.EffectId == "0").WorkStatus.ShouldBe(WorkStatus.Completed);
effectResults.Single(r => r.EffectId == "0".ToEffectId()).WorkStatus.ShouldBe(WorkStatus.Completed);
syncedCounter.Current.ShouldBe(1);
}

Expand Down Expand Up @@ -112,7 +112,7 @@ await BusyWait.Until(() =>

syncedCounter.Current.ShouldBe(1);
var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
var storedEffect = effectResults.Single(r => r.EffectId == "0");
var storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("hello");

Expand All @@ -121,7 +121,7 @@ await BusyWait.Until(() =>
await controlPanel.Restart();

effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
storedEffect = effectResults.Single(r => r.EffectId == "0");
storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("hello");
syncedCounter.Current.ShouldBe(1);
Expand Down Expand Up @@ -156,7 +156,7 @@ await BusyWait.Until(() =>

syncedCounter.Current.ShouldBe(1);
var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
var storedEffect = effectResults.Single(r => r.EffectId == "0");
var storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("hello");

Expand All @@ -165,7 +165,7 @@ await BusyWait.Until(() =>
await controlPanel.Restart();

effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
storedEffect = effectResults.Single(r => r.EffectId == "0");
storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<string>().ShouldBe("hello");
syncedCounter.Current.ShouldBe(1);
Expand Down Expand Up @@ -200,7 +200,7 @@ await BusyWait.Until(() =>

syncedCounter.Current.ShouldBe(1);
var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
var storedEffect = effectResults.Single(r => r.EffectId == "0");
var storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Failed);
storedEffect.StoredException.ShouldNotBeNull();
storedEffect.StoredException.ExceptionType.ShouldContain("InvalidOperationException");
Expand All @@ -210,7 +210,7 @@ await BusyWait.Until(() =>
await Should.ThrowAsync<EffectException>(() => controlPanel.Restart());

effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
storedEffect = effectResults.Single(r => r.EffectId == "0");
storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Failed);
storedEffect.StoredException.ShouldNotBeNull();
storedEffect.StoredException.ExceptionType.ShouldContain("InvalidOperationException");
Expand Down Expand Up @@ -238,7 +238,7 @@ async Task<int> (string param, Workflow workflow) =>
result.ShouldBe(2);

var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
var storedEffect = effectResults.Single(r => r.EffectId == "0");
var storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<int>().ShouldBe(2);
}
Expand All @@ -264,7 +264,7 @@ async Task<int[]> (string param, Workflow workflow) =>
result.ShouldBe(new [] { 1, 2 });

var effectResults = await store.EffectsStore.GetEffectResults(rAction.MapToStoredId(flowId));
var storedEffect = effectResults.Single(r => r.EffectId == "0");
var storedEffect = effectResults.Single(r => r.EffectId == "0".ToEffectId());
storedEffect.WorkStatus.ShouldBe(WorkStatus.Completed);
storedEffect.Result!.ToStringFromUtf8Bytes().DeserializeFromJsonTo<int[]>().ShouldBe(new [] {1, 2});
}
Expand Down Expand Up @@ -296,8 +296,8 @@ async Task(string _, Workflow workflow) =>
var effects = controlPanel.Effects;
var effectIds = (await effects.AllIds).ToList();
effectIds.Count.ShouldBe(2);
effectIds.Any(id => id == "0").ShouldBeTrue();
effectIds.Any(id => id == "1").ShouldBeTrue();
effectIds.Any(id => id == "0".ToEffectId()).ShouldBeTrue();
effectIds.Any(id => id == "1".ToEffectId()).ShouldBeTrue();

await effects.GetValue<string>("0").ShouldBeAsync("0");
await effects.GetValue<string>("1").ShouldBeAsync("1");
Expand Down
Loading

0 comments on commit 5783bf9

Please sign in to comment.