diff --git a/Guflow.IntegrationTests/TimerResetTests.cs b/Guflow.IntegrationTests/TimerResetTests.cs new file mode 100644 index 0000000..90fcc1d --- /dev/null +++ b/Guflow.IntegrationTests/TimerResetTests.cs @@ -0,0 +1,116 @@ +// /Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root folder for license information. + +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Guflow.Decider; +using Guflow.Worker; +using NUnit.Framework; +using NUnit.Framework.Constraints; + +namespace Guflow.IntegrationTests +{ + [TestFixture] + public class TimerResetTests + { + private WorkflowHost _workflowHost; + private ActivityHost _activityHost; + private TestDomain _domain; + private static string _taskListName; + + [SetUp] + public async Task Setup() + { + _domain = new TestDomain(); + _taskListName = Guid.NewGuid().ToString(); + _activityHost = await HostAsync(typeof(TestActivityWithInput)); + } + + [TearDown] + public void TearDown() + { + _workflowHost.StopExecution(); + _activityHost.StopExecution(); + } + + [Test] + public async Task Reset_timer() + { + string result = ""; + var @event = new ManualResetEvent(false); + var workflow = new ResetTimerWorkflow(); + workflow.Closed += (s, e) => @event.Set(); + workflow.Completed += (s, e) => { result = e.Result; }; + _workflowHost = await HostAsync(workflow); + + var workflowId = await _domain.StartWorkflow("input", _taskListName); + Assert.True(workflow.WaitForWorkflowStart()); + Thread.Sleep(6000); // TODO: get rid of this in future. + await _domain.SendSignal(workflowId, "ResetTimer", ""); + @event.WaitOne(); + + Assert.That(workflow.TimerIsReset, Is.True); + } + + private async Task HostAsync(params Workflow[] workflows) + { + var hostedWorkflows = await _domain.Host(workflows); + hostedWorkflows.StartExecution(new TaskList(_taskListName)); + return hostedWorkflows; + } + + private async Task HostAsync(params Type[] activityTypes) + { + var hostedActivities = await _domain.Host(activityTypes); + hostedActivities.StartExecution(new TaskList(_taskListName)); + return hostedActivities; + } + + [WorkflowDescription(Names.Workflow.Test.Version, Name = Names.Workflow.Test.Name, DefaultChildPolicy = ChildPolicy.Abandon, DefaultExecutionStartToCloseTimeoutInSeconds = 900, DefaultTaskListName = "DefaultTaskList", + DefaultTaskPriority = 10, DefaultTaskStartToCloseTimeoutInSeconds = 900, Description = "Empty workflow")] + private class ResetTimerWorkflow : Workflow + { + private readonly AutoResetEvent _workflowStarted = new AutoResetEvent(false); + public ResetTimerWorkflow() + { + ScheduleTimer("Timer1").FireAfter(TimeSpan.FromSeconds(10)) + .OnFired(e => + { + if (Timer(e).AllEvents().OfType().Count() == 1) + TimerIsReset = true; + return Continue(e); + }); + ScheduleActivity("TestActivity", "1.0").OnTaskList((t) => _taskListName).AfterTimer("Timer1"); + + ScheduleAction(i => CompleteWorkflow(i.ParentActivity().Result())).AfterActivity("TestActivity", "1.0"); + } + + [SignalEvent] + public WorkflowAction ResetTimer() => Timer("Timer1").IsActive ? Timer("Timer1").Reset() : Ignore; + + [WorkflowEvent(EventName.WorkflowStarted)] + public WorkflowAction WorkflowStarted() + { + _workflowStarted.Set(); + return StartWorkflow(); + } + public bool TimerIsReset; + + public bool WaitForWorkflowStart() => _workflowStarted.WaitOne(TimeSpan.FromSeconds(20)); + + } + + + [ActivityDescription(Names.Activity.Test.Version, Name = Names.Activity.Test.Name, DefaultTaskListName = "DefaultTaskList", DefaultTaskPriority = 10, Description = "some activity", + DefaultHeartbeatTimeoutInSeconds = 10, DefaultScheduleToStartTimeoutInSeconds = 10, DefaultStartToCloseTimeoutInSeconds = 10, DefaultScheduleToCloseTimeoutInSeconds = 20)] + private class TestActivityWithInput : Activity + { + [ActivityMethod] + public string Execute() + { + return "result"; + } + } + } +} \ No newline at end of file diff --git a/Guflow.Tests/Decider/Action/CancelWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/CancelWorkflowActionTests.cs index 6a17b3a..49ddfaf 100644 --- a/Guflow.Tests/Decider/Action/CancelWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/CancelWorkflowActionTests.cs @@ -10,6 +10,9 @@ namespace Guflow.Tests.Decider public class CancelWorkflowActionTests { private EventGraphBuilder _builder; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; [SetUp] public void Setup() @@ -41,7 +44,8 @@ public void Serialize_complex_detail_object_to_json() public void Can_be_returned_as_custom_action_in_workflow() { var workflow = new SingleActivityWorkflow("detail"); - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(SingleActivityWorkflow.ActivityName, SingleActivityWorkflow.ActivityVersion, SingleActivityWorkflow.PositionalName), "id", "res"); + var activityIdentity = Identity.New(ActivityName,ActivityVersion, PositionalName).ScheduleId(); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(activityIdentity, "id", "res"); var completedActivityEvent = new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph); var decisions = completedActivityEvent.Interpret(workflow).Decisions(); @@ -51,9 +55,6 @@ public void Can_be_returned_as_custom_action_in_workflow() private class SingleActivityWorkflow : Workflow { - public const string ActivityName = "Download"; - public const string ActivityVersion = "1.0"; - public const string PositionalName = "First"; public SingleActivityWorkflow(string detail) { ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnCompletion(c => CancelWorkflow(detail)); diff --git a/Guflow.Tests/Decider/Action/CompleteWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/CompleteWorkflowActionTests.cs index 626888d..36cd9c3 100644 --- a/Guflow.Tests/Decider/Action/CompleteWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/CompleteWorkflowActionTests.cs @@ -9,6 +9,9 @@ namespace Guflow.Tests.Decider public class CompleteWorkflowActionTests { private EventGraphBuilder _builder; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; [SetUp] public void Setup() @@ -40,7 +43,8 @@ public void Serialize_complex_result_to_json() public void Can_be_returned_as_custom_action_in_workflow() { var workflow = new WorkflowReturningCompleteWorkflowAction("result"); - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(WorkflowReturningCompleteWorkflowAction.ActivityName, WorkflowReturningCompleteWorkflowAction.ActivityVersion, WorkflowReturningCompleteWorkflowAction.PositionalName), "id", "res"); + var activityIdentity = Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(activityIdentity, "id", "res"); var completedActivityEvent = new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph); var decisions = completedActivityEvent.Interpret(workflow).Decisions(); @@ -50,9 +54,6 @@ public void Can_be_returned_as_custom_action_in_workflow() private class WorkflowReturningCompleteWorkflowAction : Workflow { - public const string ActivityName = "Download"; - public const string ActivityVersion = "1.0"; - public const string PositionalName = "First"; public WorkflowReturningCompleteWorkflowAction(string result) { ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnCompletion(c => CompleteWorkflow(result)); diff --git a/Guflow.Tests/Decider/Action/ContinueWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/ContinueWorkflowActionTests.cs index 767d9af..afe1c64 100644 --- a/Guflow.Tests/Decider/Action/ContinueWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/ContinueWorkflowActionTests.cs @@ -44,7 +44,10 @@ public void Returns_the_scheduling_decision_for_all_child_activities() _eventsBuilder.AddNewEvents(CompletedActivityEventGraph(_activityName, _activityVersion, _positionalName)); var decisions = new WorkflowWithMultipleChilds().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0")), new ScheduleActivityDecision(Identity.New("Sync", "2.1")) })); + Assert.That(decisions, Is.EquivalentTo(new[] + { + new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()), new ScheduleActivityDecision(Identity.New("Sync", "2.1").ScheduleId()) + })); } [Test] @@ -63,7 +66,7 @@ public void Schedule_the_child_when_one_of_its_parents_branch_is_completed_and_o var decisions = new WorkflowWithMultipleParents().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0"))})); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()) })); } [Test] @@ -84,7 +87,7 @@ public void Does_not_schedule_the_child_when_one_of_its_parent_activity_is_activ { _eventsBuilder.AddNewEvents(CompletedActivityEventGraph(_activityName, _activityVersion, _positionalName)); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ActivityScheduledGraph(Identity.New(_siblingActivityName, _siblingActivityVersion)) + .ActivityScheduledGraph(Identity.New(_siblingActivityName, _siblingActivityVersion).ScheduleId()) .ToArray()); var workflow = new WorkflowWithMultipleParents(); @@ -104,7 +107,7 @@ public void Return_scheduling_decision_for_child_when_all_of_its_parents_are_com var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0")) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()) })); } [Test] public void Return_scheduling_decision_for_child_when_one_of_its_parent_is_completed_and_other_one_is_failed_but_configured_to_continue() @@ -115,7 +118,7 @@ public void Return_scheduling_decision_for_child_when_one_of_its_parent_is_compl var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0")) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()) })); } [Test] @@ -127,7 +130,7 @@ public void Return_scheduling_decision_for_child_when_one_of_its_parent_is_compl var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0")) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()) })); } [Test] @@ -140,7 +143,7 @@ public void Return_scheduling_decision_for_child_when_one_of_its_parent_is_compl var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0")) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Transcode", "2.0").ScheduleId()) })); } [Test] @@ -153,7 +156,7 @@ public void Should_return_scheduling_decision_for_child_timer_when_parent_timer_ var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.Timer(childTimer), childTimeout) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.Timer(childTimer).ScheduleId(), childTimeout) })); } [Test] @@ -165,7 +168,7 @@ public void Should_return_scheduling_decision_for_child_activity_when_parent_tim var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New(_activityName, _activityVersion)) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New(_activityName, _activityVersion).ScheduleId()) })); } [Test] @@ -176,7 +179,7 @@ public void Can_return_the_scheduling_decision_for_child_timer_when_parent_activ _eventsBuilder.AddNewEvents(CompletedActivityEventGraph(_activityName, _activityVersion, _positionalName)); var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.Timer(timerName),new TimeSpan())})); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.Timer(timerName).ScheduleId(),new TimeSpan())})); } [Test] @@ -204,26 +207,26 @@ public void Can_return_scheduling_decision_for_workflow_action_when_all_of_its_p private HistoryEvent [] FailedActivityEventGraph(string activityName, string activityVersion, string positionalName ="") { - return _eventGraphBuilder.ActivityFailedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res", "detail").ToArray(); + return _eventGraphBuilder.ActivityFailedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res", "detail").ToArray(); } private HistoryEvent[] CompletedActivityEventGraph(string activityName, string activityVersion, string positionalName ="") { - return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res").ToArray(); + return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res").ToArray(); } private HistoryEvent[] CancelledActivityEventGraph(string activityName, string activityVersion, string positionalName = "") { - return _eventGraphBuilder.ActivityCancelledGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res").ToArray(); + return _eventGraphBuilder.ActivityCancelledGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res").ToArray(); } private HistoryEvent[] TimedoutActivityEventGraph(string activityName, string activityVersion, string positionalName = "") { - return _eventGraphBuilder.ActivityTimedoutGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res", "det").ToArray(); + return _eventGraphBuilder.ActivityTimedoutGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res", "det").ToArray(); } private HistoryEvent[] TimerFiredEventGraph(string timerName) { - return _eventGraphBuilder.TimerFiredGraph(Identity.Timer(timerName), TimeSpan.FromSeconds(2)).ToArray(); + return _eventGraphBuilder.TimerFiredGraph(Identity.Timer(timerName).ScheduleId(), TimeSpan.FromSeconds(2)).ToArray(); } private class WorkflowWithMultipleChilds : Workflow diff --git a/Guflow.Tests/Decider/Action/FailWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/FailWorkflowActionTests.cs index e3280b1..fb1aca9 100644 --- a/Guflow.Tests/Decider/Action/FailWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/FailWorkflowActionTests.cs @@ -9,6 +9,9 @@ namespace Guflow.Tests.Decider public class FailWorkflowActionTests { private EventGraphBuilder _builder; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; [SetUp] public void Setup() @@ -41,7 +44,8 @@ public void Serialize_complex_detail_object_to_json() public void Can_be_returned_as_custom_action_in_workflow() { var workflow = new SingleActivityWorkflow("reason","detail"); - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(SingleActivityWorkflow.ActivityName, SingleActivityWorkflow.ActivityVersion, SingleActivityWorkflow.PositionalName), "id", "res"); + var activityIdentity = Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(activityIdentity, "id", "res"); var completedActivityEvent = new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph); var decisions = completedActivityEvent.Interpret(workflow).Decisions(); @@ -51,9 +55,6 @@ public void Can_be_returned_as_custom_action_in_workflow() private class SingleActivityWorkflow : Workflow { - public const string ActivityName = "Download"; - public const string ActivityVersion = "1.0"; - public const string PositionalName = "First"; public SingleActivityWorkflow(string reason, string detail) { ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnCompletion(c => FailWorkflow(reason, detail)); diff --git a/Guflow.Tests/Decider/Action/IgnoreWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/IgnoreWorkflowActionTests.cs index ac1fdfd..74abf53 100644 --- a/Guflow.Tests/Decider/Action/IgnoreWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/IgnoreWorkflowActionTests.cs @@ -43,7 +43,8 @@ public void Can_be_returned_as_custom_action_from_workflow() } private ActivityCompletedEvent CreateCompletedActivityEvent(string activityName, string activityVersion) { - var allHistoryEvents = _builder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, string.Empty), "id", "res"); + var activityIdentity = Identity.New(activityName, activityVersion, string.Empty).ScheduleId(); + var allHistoryEvents = _builder.ActivityCompletedGraph(activityIdentity, "id", "res"); return new ActivityCompletedEvent(allHistoryEvents.First(), allHistoryEvents); } private class WorkflowReturningStartWorkflowAction : Workflow diff --git a/Guflow.Tests/Decider/Action/JumpWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/JumpWorkflowActionTests.cs index e4b8743..50d0247 100644 --- a/Guflow.Tests/Decider/Action/JumpWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/JumpWorkflowActionTests.cs @@ -22,15 +22,15 @@ public class JumpWorkflowActionTests private const string ChildWorkflowName = "Cnmae"; private const string ChildWorkflowVersion = "1.0"; - private EventGraphBuilder _builder; - private HistoryEventsBuilder _eventsBuilder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); - _eventsBuilder = new HistoryEventsBuilder(); - _eventsBuilder.AddProcessedEvents(_builder.WorkflowStartedEvent()); - _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(new WorkflowHistoryEvents(new []{_builder.WorkflowStartedEvent()})); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent()); + _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(new WorkflowHistoryEvents(new []{_graphBuilder.WorkflowStartedEvent()})); } [Test] @@ -44,6 +44,36 @@ public void Returns_the_scheduling_decision_for_workflow_item() Assert.That(decisions, Is.EquivalentTo(workflowItem.ScheduleDecisions())); } + [Test] + public void Schedule_the_timer_with_default_scheduleid_when_it_has_not_already_scheduled() + { + var identity = Identity.Timer("Somename"); + var workflowItem = TimerItem.New(identity, _workflow.Object); + var workflowAction = WorkflowAction.JumpTo(workflowItem); + + var decisions = workflowAction.Decisions(); + + Assert.That(decisions, Is.EquivalentTo(new[]{new ScheduleTimerDecision(identity.ScheduleId(),TimeSpan.Zero) })); + } + + [Test] + public void Reuse_the_scheduleid_when_it_has_already_scheduled() + { + const string runId = "runid"; + var identity = Identity.Timer("Somename"); + var scheduleId = identity.ScheduleId(runId + "Reset"); + _builder.AddWorkflowRunId(runId); + _builder.AddProcessedEvents(_graphBuilder.TimerStartedGraph(scheduleId, TimeSpan.Zero).ToArray()); + _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_builder.Result()); + + var workflowItem = TimerItem.New(identity, _workflow.Object); + var workflowAction = WorkflowAction.JumpTo(workflowItem); + + var decisions = workflowAction.Decisions(); + + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(scheduleId, TimeSpan.Zero) })); + } + [Test] public void Returns_timer_decision_when_jumped_after_a_timeout() { @@ -52,104 +82,104 @@ public void Returns_timer_decision_when_jumped_after_a_timeout() var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.New("name", "ver", "pos"), TimeSpan.FromSeconds(2), true) })); + Assert.That(decisions, Is.EquivalentTo(new[] { new ScheduleTimerDecision(Identity.New("name", "ver", "pos").ScheduleId(), TimeSpan.FromSeconds(2), true) })); } [Test] public void Can_be_returned_as_workflow_action_when_scheduling_the_activity() { - _eventsBuilder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); + _builder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); var workflow = new WorkflowToReturnScheduleActivityAction(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName))})); + Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()) })); } [Test] public void Can_be_returned_as_workflow_action_when_scheduling_the_timer() { - _eventsBuilder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); + _builder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); var workflow = new WorkflowToReturnScheduleTimerAction(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new []{ new ScheduleTimerDecision(Identity.Timer("SomeTimer"), TimeSpan.FromSeconds(0))})); + Assert.That(decisions, Is.EqualTo(new []{ new ScheduleTimerDecision(Identity.Timer("SomeTimer").ScheduleId(), TimeSpan.FromSeconds(0))})); } [Test] public void Jump_to_a_timer_ignore_its_when_clause() { - _eventsBuilder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); + _builder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion, PositionalName)); var workflow = new JumpToTimerWithItsWhenClauseToBeAlwaysFalse(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer("SomeTimer"), TimeSpan.FromSeconds(0)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer("SomeTimer").ScheduleId(), TimeSpan.FromSeconds(0)) })); } [Test] public void Jump_to_an_activity_ignore_its_when_clause() { - _eventsBuilder.AddNewEvents(CompletedTimerGraph(TimerName)); + _builder.AddNewEvents(CompletedTimerGraph(TimerName)); var workflow = new JumpToActivityWithItsWhenClauseToBeAlwaysFalse(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()) })); } [Test] public void Jump_to_an_lambda_ignore_its_when_clause() { - _eventsBuilder.AddNewEvents(CompletedTimerGraph(TimerName)); + _builder.AddNewEvents(CompletedTimerGraph(TimerName)); var workflow = new JumpToLambdaIgnoresItsWhenClause(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName, PositionalName), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName, PositionalName).ScheduleId(), "input") })); } [Test] public void Jump_to_a_child_workflow_ignore_its_when_clause() { - _eventsBuilder.AddNewEvents(CompletedTimerGraph(TimerName)); + _builder.AddNewEvents(CompletedTimerGraph(TimerName)); var workflow = new JumpToChildWorkflowIgnoresItsWhenClause(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(ChildWorkflowName, ChildWorkflowVersion), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleId(), "input") })); } [Test] public void Jump_to_a_child_workflow_using_generic_api_ignore_its_when_clause() { - _eventsBuilder.AddNewEvents(CompletedTimerGraph(TimerName)); + _builder.AddNewEvents(CompletedTimerGraph(TimerName)); var workflow = new JumpToChildWorkflowUsingGenericApiIgnoresItsWhenClause(); - var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(ChildWorkflowName, ChildWorkflowVersion), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleId(), "input") })); } [Test] public void Jumping_out_to_different_parent_branch_is_not_allowed() { - _eventsBuilder.AddNewEvents(CompletedActivityGraph(SiblingActivityName, Version)); + _builder.AddNewEvents(CompletedActivityGraph(SiblingActivityName, Version)); var workflow = new WorkflowToJumpToDifferentBranch(); - Assert.Throws(()=> workflow.Decisions(_eventsBuilder.Result())); + Assert.Throws(()=> workflow.Decisions(_builder.Result())); } [Test] public void Jump_to_parent_lambda_item() { - _eventsBuilder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion)); + _builder.AddNewEvents(CompletedActivityGraph(ActivityName, ActivityVersion)); - var decisions = new WorkflowToJumpToParentLambda().Decisions(_eventsBuilder.Result()); + var decisions = new WorkflowToJumpToParentLambda().Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new []{new ScheduleLambdaDecision(Identity.Lambda(LambdaName,PositionalName),"input")})); + Assert.That(decisions, Is.EqualTo(new []{new ScheduleLambdaDecision(Identity.Lambda(LambdaName,PositionalName).ScheduleId(),"input")})); } private class WorkflowToReturnScheduleActivityAction : Workflow @@ -170,12 +200,12 @@ public WorkflowToReturnScheduleTimerAction() private HistoryEvent [] CompletedActivityGraph(string activityName, string activityVersion, string positionalName ="") { - return _builder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "result").ToArray(); + return _graphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "result").ToArray(); } private HistoryEvent[] CompletedTimerGraph(string timerName) { - return _builder.TimerFiredGraph(Identity.Timer(timerName), TimeSpan.Zero).ToArray(); + return _graphBuilder.TimerFiredGraph(Identity.Timer(timerName).ScheduleId(), TimeSpan.Zero).ToArray(); } private class WorkflowToJumpToDifferentBranch : Workflow diff --git a/Guflow.Tests/Decider/Action/RecordMarkerWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/RecordMarkerWorkflowActionTests.cs index 693a203..47632a1 100644 --- a/Guflow.Tests/Decider/Action/RecordMarkerWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/RecordMarkerWorkflowActionTests.cs @@ -9,12 +9,14 @@ namespace Guflow.Tests.Decider [TestFixture] public class RecordMarkerWorkflowActionTests { - private EventGraphBuilder _builder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); } [Test] public void Returns_record_marker_workflow_decision() @@ -29,10 +31,10 @@ public void Returns_record_marker_workflow_decision() [Test] public void Can_be_returned_as_custom_action_workflow() { - var timerFiredEventGraph = _builder.TimerFiredGraph(Identity.Timer("timer1"), TimeSpan.FromSeconds(2)); - var timerFiredEvent = new TimerFiredEvent(timerFiredEventGraph.First(),timerFiredEventGraph); + var timerFiredEventGraph = _graphBuilder.TimerFiredGraph(Identity.Timer("timer1").ScheduleId(), TimeSpan.FromSeconds(2)).ToArray(); + _builder.AddNewEvents(timerFiredEventGraph); - var decisions = timerFiredEvent.Interpret(new WorkflowToReturnRecordMarker("markerName", "details")).Decisions(); + var decisions = new WorkflowToReturnRecordMarker("markerName", "details").Decisions(_builder.Result()); Assert.That(decisions,Is.EqualTo(new []{new RecordMarkerWorkflowDecision("markerName","details")})); } diff --git a/Guflow.Tests/Decider/Action/RescheduleWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/RescheduleWorkflowActionTests.cs index 946ac22..03c2a06 100644 --- a/Guflow.Tests/Decider/Action/RescheduleWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/RescheduleWorkflowActionTests.cs @@ -18,7 +18,7 @@ public class RescheduleWorkflowActionTests private const string WorkflowName = "Workflow"; private const string WorkflowVersion = "1.0"; private const string ParentWorkflowId = "pid"; - private Identity _childWorkflowId; + private ScheduleId _scheduleId; private EventGraphBuilder _eventGraphBuilder; private HistoryEventsBuilder _eventsBuilder; @@ -28,7 +28,7 @@ public void Setup() _eventGraphBuilder = new EventGraphBuilder(); _eventsBuilder = new HistoryEventsBuilder(); _eventsBuilder.AddWorkflowRunId(ParentWorkflowId); - _childWorkflowId = Identity.New(WorkflowName, WorkflowVersion).ScheduleIdentity(ParentWorkflowId); + _scheduleId = Identity.New(WorkflowName, WorkflowVersion).ScheduleId(ParentWorkflowId); } @@ -41,7 +41,7 @@ public void Reschedule_activity() var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName))})); + Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()) })); } [Test] @@ -55,7 +55,7 @@ public void Reschedule_activity_when_total_number_of_scheduling_is_less_than_all var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion , PositionalName))})); + Assert.That(decisions, Is.EqualTo(new []{ new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion , PositionalName).ScheduleId()) })); } [Test] @@ -71,7 +71,7 @@ public void Consider_only_last_similar_events_for_activity_when_counting_the_res var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()) })); } [Test] @@ -100,7 +100,7 @@ public void Reschedule_timer_when_total_number_of_activity_scheduling_is_less_th var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.New(ActivityName, ActivityVersion, PositionalName), TimeSpan.FromSeconds(2), true) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(), TimeSpan.FromSeconds(2), true) })); } [Test] @@ -128,7 +128,7 @@ public void Reschedule_timer_when_total_number_of_timer_scheduling_is_less_than_ var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(2), true) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(2), true) })); } [Test] @@ -144,7 +144,7 @@ public void Consider_only_last_similar_events_for_timer_when_counting_the_resche var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(2), true) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(2), true) })); } @@ -164,6 +164,21 @@ public void Schedule_next_item_when_total_number_of_timer_scheduling_exceed_allo Assert.That(decisions, Is.EqualTo(new[] { new CompleteWorkflowDecision("completed") })); } + [Test] + public void Reschedule_timer_with_reset_id_when_timer_is_fired_with_reset_schedule_id() + { + const string runId = "runid"; + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddWorkflowRunId(runId); + var scheduleId = Identity.Timer(TimerName).ScheduleId(runId+"Reset"); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(scheduleId, TimeSpan.Zero).ToArray()); + var workflow = new WorkflowToRescheduleTimerWithTimerUpToLimit(2); + + var decisions = workflow.Decisions(_eventsBuilder.Result()); + + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(scheduleId, TimeSpan.FromSeconds(2), true) })); + } + [Test] public void Reschedule_lambda() { @@ -173,7 +188,7 @@ public void Reschedule_lambda() var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] @@ -186,7 +201,7 @@ public void Reschedule_lamdba_when_total_number_of_scheduling_is_less_than_allow var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] @@ -201,7 +216,7 @@ public void Consider_only_last_similar_events_for_lambda_when_counting_the_resch var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] @@ -215,7 +230,7 @@ public void Schedule_next_item_when_total_number_of_lambda_scheduled_events_exce var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } [Test] @@ -227,7 +242,7 @@ public void Reschedule_child_workflow_immediately() var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_childWorkflowId, "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); } [Test] @@ -241,7 +256,7 @@ public void Reschedule_child_workflow_after_timeout() Assert.That(decisions, Is.EqualTo(new[] { - new ScheduleTimerDecision(_childWorkflowId, TimeSpan.FromSeconds(2), true) + new ScheduleTimerDecision(_scheduleId, TimeSpan.FromSeconds(2), true) })); } @@ -256,41 +271,41 @@ public void Schedule_next_item_when_total_number_of_child_workflow_events_exceed var decisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } private HistoryEvent[] ChildWorkflowCompletedEventGraph() { return _eventGraphBuilder - .ChildWorkflowCompletedGraph(_childWorkflowId ,"rid", "input", "result") + .ChildWorkflowCompletedGraph(_scheduleId,"rid", "input", "result") .ToArray(); } private HistoryEvent[] LambdaCompletedEventGraph() { - return _eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName), "input", "type").ToArray(); + return _eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "type").ToArray(); } private HistoryEvent[] LambdaFailedEventGraph() { - return _eventGraphBuilder.LambdaFailedEventGraph(Identity.Lambda(LambdaName), "input", "type","details").ToArray(); + return _eventGraphBuilder.LambdaFailedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "type","details").ToArray(); } private HistoryEvent[] ActivityCompletedEventGraph(string activityName, string activityVersion, string positionalName) { - return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res").ToArray(); + return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res").ToArray(); } private HistoryEvent[] ActivityFailedEventGraph(string activityName, string activityVersion, string positionalName) { - return _eventGraphBuilder.ActivityFailedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res", "details").ToArray(); + return _eventGraphBuilder.ActivityFailedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res", "details").ToArray(); } private HistoryEvent[] TimerFiredEventGraph(string timerName, bool rescheduleTimer) { - return _eventGraphBuilder.TimerFiredGraph(Identity.Timer(timerName), TimeSpan.Zero, rescheduleTimer).ToArray(); + return _eventGraphBuilder.TimerFiredGraph(Identity.Timer(timerName).ScheduleId(), TimeSpan.Zero, rescheduleTimer).ToArray(); } private HistoryEvent[] TimerFailedEventGraph(string timerName) { - return _eventGraphBuilder.TimerStartFailedGraph(Identity.Timer(timerName), "blah").ToArray(); + return _eventGraphBuilder.TimerStartFailedGraph(Identity.Timer(timerName).ScheduleId(), "blah").ToArray(); } private class WorkflowToRescheduleActivity : Workflow diff --git a/Guflow.Tests/Decider/Action/RestartWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/RestartWorkflowActionTests.cs index 3769aed..cafa320 100644 --- a/Guflow.Tests/Decider/Action/RestartWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/RestartWorkflowActionTests.cs @@ -25,7 +25,7 @@ public void Can_be_returned_as_custom_action() var workflowStartedEvent = new WorkflowStartedEvent(workflowStartedEventGraph); _eventsBuilder.AddProcessedEvents(workflowStartedEventGraph); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ActivityCompletedGraph(Identity.New("activityName", "1.0"), "id", "result").ToArray()); + .ActivityCompletedGraph(Identity.New("activityName", "1.0").ScheduleId(), "id", "result").ToArray()); var workflow = new WorkflowToRestart(); @@ -48,7 +48,7 @@ public void Override_start_properties_when_restarting() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent("input")); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ActivityCompletedGraph(Identity.New("activityName", "1.0"), "id", "result").ToArray()); + .ActivityCompletedGraph(Identity.New("activityName", "1.0").ScheduleId(), "id", "result").ToArray()); var workflow = new WorkflowToRestartWithCustomProperties(); @@ -59,6 +59,31 @@ public void Override_start_properties_when_restarting() Assert.That(decision.ContinueAsNewWorkflowExecutionDecisionAttributes.LambdaRole, Is.EqualTo("new lambda role")); } + + [Test] + public void Restart_using_default_properties() + { + _eventsBuilder.AddNewEvents(_eventGraphBuilder + .ActivityCompletedGraph(Identity.New("activityName", "1.0").ScheduleId(), "id", "result").ToArray()); + + var workflow = new WorkflowToRestartWithDefault(); + + var decisions = workflow.Decisions(_eventsBuilder.Result()); + var decision = decisions.Single().SwfDecision(); + + Assert.That(decision.DecisionType, Is.EqualTo(DecisionType.ContinueAsNewWorkflowExecution)); + var attr = decision.ContinueAsNewWorkflowExecutionDecisionAttributes; + Assert.That(attr.LambdaRole, Is.Null); + Assert.That(attr.TaskList, Is.Null); + Assert.That(attr.ChildPolicy, Is.Null); + Assert.That(attr.ExecutionStartToCloseTimeout, Is.Null); + Assert.That(attr.Input, Is.Null); + Assert.That(attr.TagList, Is.Empty); + Assert.That(attr.TaskPriority, Is.Null); + Assert.That(attr.TaskStartToCloseTimeout, Is.Null); + Assert.That(attr.WorkflowTypeVersion, Is.Null); + } + [WorkflowDescription("1.0")] private class WorkflowToRestart : Workflow { @@ -81,5 +106,14 @@ public WorkflowToRestartWithCustomProperties() }); } } + + [WorkflowDescription("1.0")] + private class WorkflowToRestartWithDefault : Workflow + { + public WorkflowToRestartWithDefault() + { + ScheduleActivity("activityName", "1.0").OnCompletion(e => RestartWorkflow(true)); + } + } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Action/StartWorkflowActionTests.cs b/Guflow.Tests/Decider/Action/StartWorkflowActionTests.cs index 3f8a43e..91f75dc 100644 --- a/Guflow.Tests/Decider/Action/StartWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Action/StartWorkflowActionTests.cs @@ -38,7 +38,7 @@ public void Return_schedule_decisions_for_startup_items() var workflowStartedDecisions = workflow.Decisions(_eventsBuilder.Result()); - Assert.That(workflowStartedDecisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Download", "1.0")) })); + Assert.That(workflowStartedDecisions, Is.EquivalentTo(new[] { new ScheduleActivityDecision(Identity.New("Download", "1.0").ScheduleId()) })); } [Test] @@ -72,7 +72,7 @@ public WorkflowToScheduleAction(string reason, string details) } private ActivityCompletedEvent CreateCompletedActivityEvent(string activityName, string activityVersion) { - var allHistoryEvents = _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion), "id", "res"); + var allHistoryEvents = _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, activityVersion).ScheduleId(), "id", "res"); return new ActivityCompletedEvent(allHistoryEvents.First(), allHistoryEvents); } private class TestWorkflow : Workflow diff --git a/Guflow.Tests/Decider/Activity/ActivityCancelRequestedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityCancelRequestedEventTests.cs index 5410e7a..faacb32 100644 --- a/Guflow.Tests/Decider/Activity/ActivityCancelRequestedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityCancelRequestedEventTests.cs @@ -9,10 +9,10 @@ namespace Guflow.Tests.Decider { public class ActivityCancelRequestedEventTests { - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; - private const string _workerId = "id"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; + private const string WorkerId = "id"; private ActivityCancelRequestedEvent _activityCancelRequestedEvent; private EventGraphBuilder _builder; @@ -21,7 +21,8 @@ public class ActivityCancelRequestedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var activityCancelRequestedGraph = _builder.ActivityCancelRequestedGraph(Identity.New(_activityName, _activityVersion, _positionalName),_workerId); + var scheduleId = Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var activityCancelRequestedGraph = _builder.ActivityCancelRequestedGraph(scheduleId,WorkerId); _activityCancelRequestedEvent = new ActivityCancelRequestedEvent(activityCancelRequestedGraph.First()); } diff --git a/Guflow.Tests/Decider/Activity/ActivityCancellationFailedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityCancellationFailedEventTests.cs index daaa795..f54b338 100644 --- a/Guflow.Tests/Decider/Activity/ActivityCancellationFailedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityCancellationFailedEventTests.cs @@ -21,7 +21,7 @@ public class ActivityCancellationFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var historyEventGraph = _builder.ActivityCancellationFailedGraph(Identity.New(_activityName,_activityVersion),_cause); + var historyEventGraph = _builder.ActivityCancellationFailedGraph(Identity.New(_activityName,_activityVersion).ScheduleId(), _cause); _activityCancellationFailedEvent = new ActivityCancellationFailedEvent(historyEventGraph.First()); } diff --git a/Guflow.Tests/Decider/Activity/ActivityCancelledEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityCancelledEventTests.cs index 05101ad..e64c3c4 100644 --- a/Guflow.Tests/Decider/Activity/ActivityCancelledEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityCancelledEventTests.cs @@ -11,11 +11,11 @@ namespace Guflow.Tests.Decider public class ActivityCancelledEventTests { private ActivityCancelledEvent _activityCancelledEvent; - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; - private const string _identity = "machine name"; - private const string _detail = "detail"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; + private const string Identity = "machine name"; + private const string Detail = "detail"; private EventGraphBuilder _builder; @@ -23,15 +23,16 @@ public class ActivityCancelledEventTests public void Setup() { _builder = new EventGraphBuilder(); - var cancelledActivityEventGraph = _builder.ActivityCancelledGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, _detail); + var scheduleId = Guflow.Decider.Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var cancelledActivityEventGraph = _builder.ActivityCancelledGraph(scheduleId, Identity, Detail); _activityCancelledEvent = new ActivityCancelledEvent(cancelledActivityEventGraph.First(), cancelledActivityEventGraph); } [Test] public void Should_populate_properties_from_event_attributes() { - Assert.That(_activityCancelledEvent.Details, Is.EqualTo(_detail)); - Assert.That(_activityCancelledEvent.WorkerIdentity, Is.EqualTo(_identity)); + Assert.That(_activityCancelledEvent.Details, Is.EqualTo(Detail)); + Assert.That(_activityCancelledEvent.WorkerIdentity, Is.EqualTo(Identity)); Assert.That(_activityCancelledEvent.IsActive,Is.False); } @@ -42,7 +43,7 @@ public void By_default_return_cancel_workflow_decision() var decisions = _activityCancelledEvent.Interpret(workflow).Decisions(); - Assert.That(decisions, Is.EqualTo(new []{new CancelWorkflowDecision(_detail)}) ); + Assert.That(decisions, Is.EqualTo(new []{new CancelWorkflowDecision(Detail)}) ); } [Test] @@ -68,7 +69,7 @@ private class SingleActivityWorkflow : Workflow { public SingleActivityWorkflow() { - ScheduleActivity(_activityName, _activityVersion, _positionalName); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName); } } @@ -76,7 +77,7 @@ private class WorkflowWithCustomAction : Workflow { public WorkflowWithCustomAction(WorkflowAction workflowAction) { - ScheduleActivity(_activityName, _activityVersion, _positionalName).OnCancelled(c => workflowAction); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnCancelled(c => workflowAction); } } } diff --git a/Guflow.Tests/Decider/Activity/ActivityCompletedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityCompletedEventTests.cs index 2720c80..4933753 100644 --- a/Guflow.Tests/Decider/Activity/ActivityCompletedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityCompletedEventTests.cs @@ -11,31 +11,33 @@ namespace Guflow.Tests.Decider [TestFixture] public class ActivityCompletedEventTests { - private const string _result = "result"; - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; - private const string _identity = "machine name"; - private const string _input = "input"; + private const string Result = "result"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; + private const string Identity = "machine name"; + private const string Input = "input"; private ActivityCompletedEvent _activityCompletedEvent; private EventGraphBuilder _builder; + private ScheduleId _scheduleId; [SetUp] public void Setup() { _builder = new EventGraphBuilder(); - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, _result,_input); + _scheduleId = Guflow.Decider.Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(_scheduleId, Identity, Result,Input); _activityCompletedEvent = new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph); } [Test] public void Populate_activity_details_from_history_events() { - Assert.That(_activityCompletedEvent.Result, Is.EqualTo(_result)); - Assert.That(_activityCompletedEvent.WorkerIdentity, Is.EqualTo(_identity)); + Assert.That(_activityCompletedEvent.Result, Is.EqualTo(Result)); + Assert.That(_activityCompletedEvent.WorkerIdentity, Is.EqualTo(Identity)); Assert.That(_activityCompletedEvent.IsActive,Is.False); - Assert.That(_activityCompletedEvent.Input,Is.EqualTo(_input)); + Assert.That(_activityCompletedEvent.Input,Is.EqualTo(Input)); } [Test] @@ -49,7 +51,7 @@ public void Throws_exception_when_completed_activity_is_not_found_in_workflow() [Test] public void Does_not_populate_worker_id_when_activity_started_event_not_found_in_event_graph() { - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, _result); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(_scheduleId, Identity, Result); var activityCompletedEvent= new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph.Where(h=>h.EventType!=EventType.ActivityTaskStarted)); @@ -58,7 +60,7 @@ public void Does_not_populate_worker_id_when_activity_started_event_not_found_in [Test] public void Throws_exception_when_activity_scheduled_event_not_found_in_event_graph() { - var completedActivityEventGraph = _builder.ActivityCompletedGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, _result); + var completedActivityEventGraph = _builder.ActivityCompletedGraph(_scheduleId, Identity, Result); Assert.Throws(() => new ActivityCompletedEvent(completedActivityEventGraph.First(), completedActivityEventGraph.Where(h => h.EventType != EventType.ActivityTaskScheduled))); } @@ -70,7 +72,7 @@ public void By_default_return_continue_workflow_action() var workflowAction = _activityCompletedEvent.Interpret(workflow); - Assert.That(workflowAction,Is.EqualTo(WorkflowAction.ContinueWorkflow(new ActivityItem(Identity.New(_activityName,_activityVersion,_positionalName),null)))); + Assert.That(workflowAction,Is.EqualTo(WorkflowAction.ContinueWorkflow(new ActivityItem(Guflow.Decider.Identity.New(ActivityName,ActivityVersion,PositionalName),null)))); } [Test] @@ -88,7 +90,7 @@ private class SingleActivityWorkflow : Workflow { public SingleActivityWorkflow() { - ScheduleActivity(_activityName,_activityVersion,_positionalName); + ScheduleActivity(ActivityName,ActivityVersion,PositionalName); } } @@ -96,7 +98,7 @@ private class WorkflowWithCustomAction : Workflow { public WorkflowWithCustomAction(WorkflowAction workflowAction) { - ScheduleActivity(_activityName, _activityVersion, _positionalName).OnCompletion(c => workflowAction); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnCompletion(c => workflowAction); } } } diff --git a/Guflow.Tests/Decider/Activity/ActivityFailedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityFailedEventTests.cs index 9d8ee50..829e181 100644 --- a/Guflow.Tests/Decider/Activity/ActivityFailedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityFailedEventTests.cs @@ -11,28 +11,30 @@ namespace Guflow.Tests.Decider public class ActivityFailedEventTests { private ActivityFailedEvent _activityFailedEvent; - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; - private const string _identity = "machine name"; - private const string _reason = "reason"; - private const string _detail = "detail"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; + private const string Identity = "machine name"; + private const string Reason = "reason"; + private const string Detail = "detail"; private EventGraphBuilder _builder; + private ScheduleId _scheduleId; [SetUp] public void Setup() { _builder = new EventGraphBuilder(); - var failedActivityEventGraph = _builder.ActivityFailedGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, _reason, _detail); + _scheduleId = Guflow.Decider.Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(); + var failedActivityEventGraph = _builder.ActivityFailedGraph(_scheduleId, Identity, Reason, Detail); _activityFailedEvent = new ActivityFailedEvent(failedActivityEventGraph.First(), failedActivityEventGraph); } [Test] public void Populate_event_attributes() { - Assert.That(_activityFailedEvent.WorkerIdentity,Is.EqualTo(_identity)); - Assert.That(_activityFailedEvent.Reason,Is.EqualTo(_reason)); - Assert.That(_activityFailedEvent.Details,Is.EqualTo(_detail)); + Assert.That(_activityFailedEvent.WorkerIdentity,Is.EqualTo(Identity)); + Assert.That(_activityFailedEvent.Reason,Is.EqualTo(Reason)); + Assert.That(_activityFailedEvent.Details,Is.EqualTo(Detail)); Assert.That(_activityFailedEvent.IsActive,Is.False); } @@ -51,7 +53,7 @@ public void By_default_return_fail_workflow_decision() var decisions = _activityFailedEvent.Interpret(workflow).Decisions(); - Assert.That(decisions,Is.EqualTo(new []{new FailWorkflowDecision(_reason,_detail)})); + Assert.That(decisions,Is.EqualTo(new []{new FailWorkflowDecision(Reason,Detail)})); } [Test] public void Can_return_the_custom_workflow_action() @@ -68,14 +70,14 @@ private class SingleActivityWorkflow : Workflow { public SingleActivityWorkflow() { - ScheduleActivity(_activityName, _activityVersion, _positionalName); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName); } } private class WorkflowWithCustomAction : Workflow { public WorkflowWithCustomAction(WorkflowAction workflowAction) { - ScheduleActivity(_activityName, _activityVersion, _positionalName).OnFailure(e => workflowAction); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnFailure(e => workflowAction); } } } diff --git a/Guflow.Tests/Decider/Activity/ActivityItemExtensionTests.cs b/Guflow.Tests/Decider/Activity/ActivityItemExtensionTests.cs index 340119d..2947759 100644 --- a/Guflow.Tests/Decider/Activity/ActivityItemExtensionTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityItemExtensionTests.cs @@ -220,32 +220,32 @@ public void Last_completed_event_is_null_when_the_latest_event_is_cancelled_even private ActivityCompletedEvent CompletedEvent(string result) { - var eventGraph = _builder.ActivityCompletedGraph(Identity.New("a1", "v1"), "id", + var eventGraph = _builder.ActivityCompletedGraph(Identity.New("a1", "v1").ScheduleId(), "id", result, "input"); return new ActivityCompletedEvent(eventGraph.First(), eventGraph); } private ActivityFailedEvent FailedEvent(string reason, string detail) { - var eventGraph = _builder.ActivityFailedGraph(Identity.New("a","v"),"id",reason, detail); + var eventGraph = _builder.ActivityFailedGraph(Identity.New("a","v").ScheduleId(),"id",reason, detail); return new ActivityFailedEvent(eventGraph.First(), eventGraph); } private ActivityTimedoutEvent TimedoutEvent(string timeoutType, string details) { - var eventGraph = _builder.ActivityTimedoutGraph(Identity.New("a", "v"), "id", timeoutType, details); + var eventGraph = _builder.ActivityTimedoutGraph(Identity.New("a", "v").ScheduleId(), "id", timeoutType, details); return new ActivityTimedoutEvent(eventGraph.First(), eventGraph); } private ActivityCancelledEvent CancelledEvent(string details) { - var eventGraph = _builder.ActivityCancelledGraph(Identity.New("a", "v"), "id", details); + var eventGraph = _builder.ActivityCancelledGraph(Identity.New("a", "v").ScheduleId(), "id", details); return new ActivityCancelledEvent(eventGraph.First(), eventGraph); } private ActivityStartedEvent StartedEvent() { - var eventGraph = _builder.ActivityStartedGraph(Identity.New("a", "v"), "id"); + var eventGraph = _builder.ActivityStartedGraph(Identity.New("a", "v").ScheduleId(), "id"); return new ActivityStartedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/Activity/ActivityItemTests.cs b/Guflow.Tests/Decider/Activity/ActivityItemTests.cs index 034c878..1c093ee 100644 --- a/Guflow.Tests/Decider/Activity/ActivityItemTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityItemTests.cs @@ -12,7 +12,8 @@ namespace Guflow.Tests.Decider [TestFixture] public class ActivityItemTests { - private readonly Identity _activityIdenity = Identity.New("somename", "1.0", "name"); + private readonly Identity _activityIdentity = Identity.New("somename", "1.0", "name"); + private ScheduleId _scheduleId; private Mock _workflow; private EventGraphBuilder _eventGraphBuilder; @@ -25,13 +26,14 @@ public void Setup() _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowStartedEvent()); _workflow = new Mock(); _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_eventsBuilder.Result); + _scheduleId = _activityIdentity.ScheduleId(); } [Test] public void By_default_workflow_input_is_passed_as_activity_input() { const string workflowInput = "actvity"; _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(new WorkflowHistoryEvents(_eventGraphBuilder.WorkflowStartedGraph(workflowInput))); - var activityItem = new ActivityItem(_activityIdenity,_workflow.Object); + var activityItem = new ActivityItem(_activityIdentity,_workflow.Object); var decision = ScheduleDecision(activityItem); @@ -42,7 +44,7 @@ public void By_default_workflow_input_is_passed_as_activity_input() public void Can_be_configured_to_schedule_activity_with_custom_input_string() { const string activityInput = "actvity"; - var activityItem = new ActivityItem(_activityIdenity, null); + var activityItem = new ActivityItem(_activityIdentity, null); activityItem.WithInput(a => activityInput); var decision = ScheduleDecision(activityItem); @@ -53,7 +55,7 @@ public void Can_be_configured_to_schedule_activity_with_custom_input_string() public void Can_be_configured_to_schedule_activity_with_primitive_string() { DateTime activityInput = DateTime.Now; - var activityItem = new ActivityItem(_activityIdenity, null); + var activityItem = new ActivityItem(_activityIdentity, null); activityItem.WithInput(a => activityInput); var decision = ScheduleDecision(activityItem); @@ -64,7 +66,7 @@ public void Can_be_configured_to_schedule_activity_with_primitive_string() [Test] public void Can_be_configured_to_schedule_activity_with_custom_input_object() { - var activityItem = new ActivityItem(_activityIdenity, null); + var activityItem = new ActivityItem(_activityIdentity, null); activityItem.WithInput(a => new{InputFile ="SomeFile", Rate =50}); var decision = ScheduleDecision(activityItem); @@ -75,7 +77,7 @@ public void Can_be_configured_to_schedule_activity_with_custom_input_object() [Test] public void Can_be_configured_to_schedule_activity_with_null_input() { - var activityItem = new ActivityItem(_activityIdenity, null); + var activityItem = new ActivityItem(_activityIdentity, null); activityItem.WithInput(a => null); var decision = ScheduleDecision(activityItem); @@ -86,7 +88,7 @@ public void Can_be_configured_to_schedule_activity_with_null_input() [Test] public void By_default_schedule_activity_with_empty_task_list() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); var decision = ScheduleDecision(activityItem); @@ -97,7 +99,7 @@ public void By_default_schedule_activity_with_empty_task_list() public void Can_be_configured_to_schedule_activity_with_custom_task_list() { const string taskList = "taskList"; - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); activityItem.OnTaskList(a => taskList); var decision = ScheduleDecision(activityItem); @@ -108,7 +110,7 @@ public void Can_be_configured_to_schedule_activity_with_custom_task_list() [Test] public void Does_not_schedule_activity_when_when_func_is_evaluated_to_false() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); activityItem.When(a => false); var decisions = activityItem.ScheduleDecisions(); @@ -119,7 +121,7 @@ public void Does_not_schedule_activity_when_when_func_is_evaluated_to_false() [Test] public void By_default_schedule_activity_without_priority() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); var decision = ScheduleDecision(activityItem); @@ -129,7 +131,7 @@ public void By_default_schedule_activity_without_priority() [Test] public void Can_be_configured_to_schedule_activity_with_priority() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); activityItem.WithPriority(a => 10); var decision = ScheduleDecision(activityItem); @@ -139,7 +141,7 @@ public void Can_be_configured_to_schedule_activity_with_priority() [Test] public void By_default_schedule_activity_with_empty_timeouts() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); var decision = ScheduleDecision(activityItem); @@ -152,7 +154,7 @@ public void By_default_schedule_activity_with_empty_timeouts() [Test] public void Can_be_configured_to_schedule_activity_with_timeouts() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); activityItem.WithTimeouts( a => new ActivityTimeouts() @@ -173,10 +175,10 @@ public void Can_be_configured_to_schedule_activity_with_timeouts() [Test] public void Last_event_is_cached() { - var eventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "id"); + var eventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "id"); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(workflowHistoryEvents); - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); var latestEvent = activityItem.LastEvent(true); var latestEventCached = activityItem.LastEvent(true); @@ -189,7 +191,7 @@ public void Last_event_can_be_null() { var workflowHistoryEvents = new WorkflowHistoryEvents(_eventGraphBuilder.WorkflowStartedGraph()); _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(workflowHistoryEvents); - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); var latestEvent = activityItem.LastEvent(); @@ -199,8 +201,8 @@ public void Last_event_can_be_null() [Test] public void Last_event_is_timer_event_when_timer_events_are_newer_then_activity_event() { - var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_activityIdenity, "workerid", "reason", "detail"); - var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity,TimeSpan.FromSeconds(2)); + var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_scheduleId, "workerid", "reason", "detail"); + var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId, TimeSpan.FromSeconds(2)); var activityItem = CreateActivityItemWith(activityFailedEventGraph.Concat(timerStartedEventGraph)); @@ -212,8 +214,8 @@ public void Last_event_is_timer_event_when_timer_events_are_newer_then_activity_ [Test] public void Last_event_is_activity_event_when_activity_events_are_newer_then_timer_event() { - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_activityIdenity, TimeSpan.FromSeconds(2)); - var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_activityIdenity, "workerid", "reason", "detail"); + var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.FromSeconds(2)); + var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_scheduleId, "workerid", "reason", "detail"); var eventGraph = timerFiredEventGraph.Concat(activityFailedEventGraph); var activityItem = CreateActivityItemWith(eventGraph); @@ -226,7 +228,7 @@ public void Last_event_is_activity_event_when_activity_events_are_newer_then_tim [Test] public void Last_event_is_activity_started_event_when_its_cancel_request_is_in_progress() { - var eventGraph = _eventGraphBuilder.ActivityCancelRequestedGraph(_activityIdenity, "id").ToArray(); + var eventGraph = _eventGraphBuilder.ActivityCancelRequestedGraph(_scheduleId, "id").ToArray(); var activityItem = CreateActivityItemWith(eventGraph); @@ -238,7 +240,7 @@ public void Last_event_is_activity_started_event_when_its_cancel_request_is_in_p [Test] public void Last_event_is_activity_started_event_when_its_cancel_request_is_failed() { - var eventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_activityIdenity, "cause").ToArray(); + var eventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_scheduleId, "cause").ToArray(); var activityItem = CreateActivityItemWith(eventGraph); @@ -247,11 +249,22 @@ public void Last_event_is_activity_started_event_when_its_cancel_request_is_fail Assert.That(last, Is.EqualTo(new ActivityStartedEvent(eventGraph.Skip(1).First(), eventGraph))); } + [Test] + public void Last_event_filters_out_activity_scheduling_failed_event() + { + var activityScheduled = _eventGraphBuilder.ActivityScheduledGraph(_scheduleId); + var activityScheduleFailed = _eventGraphBuilder.ActivitySchedulingFailedGraph(_scheduleId, "DUPLICATE_ID"); + var activityItem = CreateActivityItemWith(activityScheduleFailed.Concat(activityScheduled)); + + var @event = activityItem.LastEvent(); + Assert.That(@event, Is.EqualTo(new ActivityScheduledEvent(activityScheduled.First(), activityScheduled))); + } + [Test] public void Last_event_by_default_filter_out_reschedule_timer_events() { - var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_activityIdenity, "workerid", "reason", "detail"); - var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity, TimeSpan.FromSeconds(2)); + var activityFailedEventGraph = _eventGraphBuilder.ActivityFailedGraph(_scheduleId, "workerid", "reason", "detail"); + var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId, TimeSpan.FromSeconds(2)); var activityItem = CreateActivityItemWith(activityFailedEventGraph.Concat(timerStartedEventGraph)); @@ -263,7 +276,7 @@ public void Last_event_by_default_filter_out_reschedule_timer_events() [Test] public void By_default_last_similar_events_is_empty() { - var activityItem = new ActivityItem(_activityIdenity, _workflow.Object); + var activityItem = new ActivityItem(_activityIdentity, _workflow.Object); Assert.That(activityItem.LastSimilarEvents(), Is.Empty); } @@ -271,7 +284,7 @@ public void By_default_last_similar_events_is_empty() [Test] public void All_events_can_return_completed_event() { - var eventGraph = _eventGraphBuilder.ActivityCompletedGraph(_activityIdenity, "workerid", "detail"); + var eventGraph = _eventGraphBuilder.ActivityCompletedGraph(_scheduleId, "workerid", "detail"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -282,8 +295,8 @@ public void All_events_can_return_completed_event() [Test] public void All_events_can_return_completed_event_and_started_event() { - var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_activityIdenity, "workerid", "detail"); - var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "id"); + var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_scheduleId, "workerid", "detail"); + var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "id"); var activityItem = CreateActivityItemWith(completedEventGraph.Concat(startedEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -294,8 +307,8 @@ public void All_events_can_return_completed_event_and_started_event() [Test] public void All_events_can_return_completed_event_and_scheduled_event() { - var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_activityIdenity, "workerid", "detail"); - var scheduledEventGraph = _eventGraphBuilder.ActivityScheduledGraph(_activityIdenity); + var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_scheduleId, "workerid", "detail"); + var scheduledEventGraph = _eventGraphBuilder.ActivityScheduledGraph(_scheduleId); var activityItem = CreateActivityItemWith(completedEventGraph.Concat(scheduledEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -306,7 +319,7 @@ public void All_events_can_return_completed_event_and_scheduled_event() [Test] public void All_events_can_return_failed_event() { - var eventGraph = _eventGraphBuilder.ActivityFailedGraph(_activityIdenity, "workerid", "reason","detail"); + var eventGraph = _eventGraphBuilder.ActivityFailedGraph(_scheduleId, "workerid", "reason","detail"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -317,7 +330,7 @@ public void All_events_can_return_failed_event() [Test] public void All_events_can_return_timedout_event() { - var eventGraph = _eventGraphBuilder.ActivityTimedoutGraph(_activityIdenity, "workerid", "reason", "detail"); + var eventGraph = _eventGraphBuilder.ActivityTimedoutGraph(_scheduleId, "workerid", "reason", "detail"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -328,7 +341,7 @@ public void All_events_can_return_timedout_event() [Test] public void All_events_can_return_cancelled_event_and_cancel_requested_event() { - var eventGraph = _eventGraphBuilder.ActivityCancelledGraph(_activityIdenity, "workerid", "detail"); + var eventGraph = _eventGraphBuilder.ActivityCancelledGraph(_scheduleId, "workerid", "detail"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -343,8 +356,8 @@ public void All_events_can_return_cancelled_event_and_cancel_requested_event() [Test] public void All_events_can_return_multiple_cancel_requested_event_from_different_graph() { - var cancelledEventGraph = _eventGraphBuilder.ActivityCancelledGraph(_activityIdenity, "workerid", "detail").ToArray(); - var cancelRequestedEventGraph = _eventGraphBuilder.ActivityCancelRequestedGraph(_activityIdenity,"id").ToArray(); + var cancelledEventGraph = _eventGraphBuilder.ActivityCancelledGraph(_scheduleId, "workerid", "detail").ToArray(); + var cancelRequestedEventGraph = _eventGraphBuilder.ActivityCancelRequestedGraph(_scheduleId, "id").ToArray(); var activityItem = CreateActivityItemWith(cancelRequestedEventGraph.Concat(cancelledEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -361,7 +374,7 @@ public void All_events_can_return_multiple_cancel_requested_event_from_different [Test] public void All_events_can_return_cancellation_failed_event_and_activity_started_event() { - var eventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_activityIdenity, "cause").ToArray(); + var eventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_scheduleId, "cause").ToArray(); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -376,8 +389,8 @@ public void All_events_can_return_cancellation_failed_event_and_activity_started [Test] public void All_events_can_return_cancelled_event_and_cancellation_request_failed_event() { - var cancelledEventGraph = _eventGraphBuilder.ActivityCancelledGraph(_activityIdenity, "workerid", "detail").ToArray(); - var activityCancellationFailedEventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_activityIdenity, "id").ToArray(); + var cancelledEventGraph = _eventGraphBuilder.ActivityCancelledGraph(_scheduleId, "workerid", "detail").ToArray(); + var activityCancellationFailedEventGraph = _eventGraphBuilder.ActivityCancellationFailedGraph(_scheduleId, "id").ToArray(); var activityItem = CreateActivityItemWith(activityCancellationFailedEventGraph.Concat(cancelledEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -394,7 +407,7 @@ public void All_events_can_return_cancelled_event_and_cancellation_request_faile [Test] public void All_events_can_return_activity_started_event() { - var eventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "workerid"); + var eventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "workerid"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -405,7 +418,7 @@ public void All_events_can_return_activity_started_event() [Test] public void All_events_can_return_activity_scheduled_event() { - var eventGraph = _eventGraphBuilder.ActivityScheduledGraph(_activityIdenity); + var eventGraph = _eventGraphBuilder.ActivityScheduledGraph(_scheduleId); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -416,7 +429,7 @@ public void All_events_can_return_activity_scheduled_event() [Test] public void All_events_can_return_activity_scheduling_failed_event() { - var eventGraph = _eventGraphBuilder.ActivitySchedulingFailedGraph(_activityIdenity,"cause"); + var eventGraph = _eventGraphBuilder.ActivitySchedulingFailedGraph(_scheduleId, "cause"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -427,7 +440,7 @@ public void All_events_can_return_activity_scheduling_failed_event() [Test] public void All_events_can_return_timer_fired_event() { - var eventGraph = _eventGraphBuilder.TimerFiredGraph(_activityIdenity, TimeSpan.FromSeconds(3),true); + var eventGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.FromSeconds(3),true); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -438,9 +451,9 @@ public void All_events_can_return_timer_fired_event() [Test] public void All_events_return_the_events_in_the_order_of_their_occurrence() { - var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "id"); - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); - var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_activityIdenity, "workerid", "detail"); + var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "id"); + var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.FromSeconds(3), true); + var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_scheduleId, "workerid", "detail"); var activityItem = CreateActivityItemWith(startedEventGraph.Concat(timerFiredEventGraph).Concat(completedEventGraph)); @@ -455,9 +468,9 @@ public void All_events_return_the_events_in_the_order_of_their_occurrence() [Test] public void All_events_by_default_filters_out_reschedule_timer_events() { - var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "id"); - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); - var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_activityIdenity, "workerid", "detail"); + var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "id"); + var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.FromSeconds(3), true); + var completedEventGraph = _eventGraphBuilder.ActivityCompletedGraph(_scheduleId, "workerid", "detail"); var activityItem = CreateActivityItemWith(startedEventGraph.Concat(timerFiredEventGraph).Concat(completedEventGraph)); @@ -471,8 +484,8 @@ public void All_events_by_default_filters_out_reschedule_timer_events() [Test] public void All_events_can_return_timer_fired_and_timer_started_event_event() { - var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity,TimeSpan.FromSeconds(3),true); - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); + var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId,TimeSpan.FromSeconds(3),true); + var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.FromSeconds(3), true); var activityItem = CreateActivityItemWith(timerStartedEventGraph.Concat(timerFiredEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -484,7 +497,7 @@ public void All_events_can_return_timer_fired_and_timer_started_event_event() [Test] public void All_events_can_return_timer_cancelled_event() { - var eventGraph = _eventGraphBuilder.TimerCancelledGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); + var eventGraph = _eventGraphBuilder.TimerCancelledGraph(_scheduleId, TimeSpan.FromSeconds(3), true); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -495,8 +508,8 @@ public void All_events_can_return_timer_cancelled_event() [Test] public void All_events_can_return_timer_cancelled_and_timer_started_event() { - var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity,TimeSpan.FromSeconds(3),true); - var timerCancelledEventGraph = _eventGraphBuilder.TimerCancelledGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); + var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId,TimeSpan.FromSeconds(3),true); + var timerCancelledEventGraph = _eventGraphBuilder.TimerCancelledGraph(_scheduleId, TimeSpan.FromSeconds(3), true); var activityItem = CreateActivityItemWith(timerStartedEventGraph.Concat(timerCancelledEventGraph)); var allEvents = activityItem.AllEvents(true); @@ -508,39 +521,40 @@ public void All_events_can_return_timer_cancelled_and_timer_started_event() [Test] public void All_events_can_return_timer_cancellattion_failed_event_and_timer_started_event() { - var eventGraph = _eventGraphBuilder.TimerCancellationFailedGraph(_activityIdenity, "cause"); - var activityItem = CreateActivityItemWith(eventGraph); + var startedGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId, TimeSpan.Zero); + var failedGraph = _eventGraphBuilder.TimerCancellationFailedGraph(_scheduleId, "cause"); + var activityItem = CreateActivityItemWith(failedGraph.Concat(startedGraph)); var allEvents = activityItem.AllEvents(true); Assert.That(allEvents, Is.EqualTo(new WorkflowItemEvent[] { - new TimerCancellationFailedEvent(eventGraph.First()), - new TimerStartedEvent(eventGraph.Skip(1).First(), eventGraph) + new TimerCancellationFailedEvent(failedGraph.First()), + new TimerStartedEvent(startedGraph.First(), startedGraph) })); } [Test] - public void All_events_can_return_timer_started_and_cancellattion_failed_event() + public void All_events_can_return_timer_fired_and_cancellattion_failed_event() { - var failedEventGraph = _eventGraphBuilder.TimerCancellationFailedGraph(_activityIdenity, "cause"); - var timerStartedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity, TimeSpan.FromSeconds(3)); - var activityItem = CreateActivityItemWith(timerStartedEventGraph.Concat(failedEventGraph)); + var firedGraph = _eventGraphBuilder.TimerFiredGraph(_scheduleId, TimeSpan.Zero); + var failedGraph = _eventGraphBuilder.TimerCancellationFailedGraph(_scheduleId, "cause"); + + var activityItem = CreateActivityItemWith(failedGraph.Concat(firedGraph)); var allEvents = activityItem.AllEvents(true); Assert.That(allEvents, Is.EqualTo(new WorkflowItemEvent[] { - new TimerStartedEvent(timerStartedEventGraph.First(), timerStartedEventGraph), - new TimerCancellationFailedEvent(failedEventGraph.First()), - new TimerStartedEvent(failedEventGraph.Skip(1).First(), failedEventGraph), + new TimerCancellationFailedEvent(failedGraph.First()), + new TimerFiredEvent(firedGraph.First(), firedGraph), })); } [Test] public void All_events_can_return_timer_started_event() { - var eventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity, TimeSpan.FromSeconds(3), true); + var eventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId, TimeSpan.FromSeconds(3), true); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -551,7 +565,7 @@ public void All_events_can_return_timer_started_event() [Test] public void All_events_can_return_timer_start_failed_event() { - var eventGraph = _eventGraphBuilder.TimerStartFailedGraph(_activityIdenity,"cause"); + var eventGraph = _eventGraphBuilder.TimerStartFailedGraph(_scheduleId,"cause"); var activityItem = CreateActivityItemWith(eventGraph); var allEvents = activityItem.AllEvents(true); @@ -562,7 +576,7 @@ public void All_events_can_return_timer_start_failed_event() [Test] public void Should_be_active_when_last_event_is_activity_started_event() { - var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_activityIdenity, "id"); + var startedEventGraph = _eventGraphBuilder.ActivityStartedGraph(_scheduleId, "id"); var activityItem = CreateActivityItemWith(startedEventGraph); Assert.IsTrue(activityItem.IsActive); } @@ -570,7 +584,7 @@ public void Should_be_active_when_last_event_is_activity_started_event() [Test] public void Should_be_active_when_last_event_is_reschedule_timer_started() { - var startedEventGraph = _eventGraphBuilder.TimerStartedGraph(_activityIdenity, TimeSpan.Zero, true); + var startedEventGraph = _eventGraphBuilder.TimerStartedGraph(_scheduleId, TimeSpan.Zero, true); var activityItem = CreateActivityItemWith(startedEventGraph); Assert.IsTrue(activityItem.IsActive); } @@ -578,14 +592,14 @@ public void Should_be_active_when_last_event_is_reschedule_timer_started() [Test] public void Should_not_be_active_when_no_event_is_found() { - var activityItem = CreateActivityItemWith(_eventGraphBuilder.ActivityStartedGraph(Identity.New("Different",""),"id")); + var activityItem = CreateActivityItemWith(_eventGraphBuilder.ActivityStartedGraph(Identity.New("Different","").ScheduleId(),"id")); Assert.IsFalse(activityItem.IsActive); } [Test] public void Invalid_arguments_tests() { - var activityItem = (IFluentActivityItem)new ActivityItem(_activityIdenity, null); + var activityItem = (IFluentActivityItem)new ActivityItem(_activityIdentity, null); Assert.Throws(() => activityItem.WithInput(null)); Assert.Throws(() => activityItem.OnCancelled(null)); @@ -615,7 +629,7 @@ private ActivityItem CreateActivityItemWith(IEnumerable eventGraph { var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(workflowHistoryEvents); - return new ActivityItem(_activityIdenity, _workflow.Object); + return new ActivityItem(_activityIdentity, _workflow.Object); } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Activity/ActivityScheduleTests.cs b/Guflow.Tests/Decider/Activity/ActivityScheduleTests.cs index 6578c8e..ddc368a 100644 --- a/Guflow.Tests/Decider/Activity/ActivityScheduleTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityScheduleTests.cs @@ -36,7 +36,7 @@ public void Activity_can_be_scheduled_after_lambda() var eventGraph = LambdaCompletedEventGraph(); var decision = new ActivityAfterLambdaWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } [Test] @@ -45,7 +45,7 @@ public void Activity_can_be_scheduled_after_time() var eventGraph = TimerCompletedEventGraph(); var decision = new ActivityAfterTimerWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } [Test] @@ -54,7 +54,7 @@ public void Activity_can_be_scheduled_after_activity() var eventGraph = ActivityEventGraph(); var decision = new ActivityAfterActivityWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } [Test] @@ -63,7 +63,7 @@ public void Activity_can_be_scheduled_after_child_workflow() var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new ActivityAfterChildWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } [Test] @@ -72,13 +72,13 @@ public void Activity_can_be_scheduled_after_child_workflow_using_generic_type_ap var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new ActivityAfterChildWorkflowGenericType().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()) })); } private WorkflowHistoryEvents ActivityEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ParentActivityName, ParentActivityVersion), "id", + _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ParentActivityName, ParentActivityVersion).ScheduleId(), "id", "res").ToArray()); return _eventsBuilder.Result(); } @@ -86,14 +86,14 @@ private WorkflowHistoryEvents ActivityEventGraph() private WorkflowHistoryEvents TimerCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.FromSeconds(2)).ToArray()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(2)).ToArray()); return _eventsBuilder.Result(); } private WorkflowHistoryEvents LambdaCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName), "input", "result").ToArray()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "result").ToArray()); return _eventsBuilder.Result(); } @@ -101,7 +101,7 @@ private WorkflowHistoryEvents ChildWorkflowCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion,ChildWorkflowPosName), "rid", "input", + .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion,ChildWorkflowPosName).ScheduleId(), "rid", "input", "result") .ToArray()); return _eventsBuilder.Result(); diff --git a/Guflow.Tests/Decider/Activity/ActivityScheduledEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityScheduledEventTests.cs index 5741e89..a703a9f 100644 --- a/Guflow.Tests/Decider/Activity/ActivityScheduledEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityScheduledEventTests.cs @@ -10,9 +10,9 @@ namespace Guflow.Tests.Decider [TestFixture] public class ActivityScheduledEventTests { - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; private ActivityScheduledEvent _activityScheduledEvent; private EventGraphBuilder _builder; @@ -21,7 +21,7 @@ public class ActivityScheduledEventTests public void Setup() { _builder = new EventGraphBuilder(); - var scheduledActivityEventGraph = _builder.ActivityScheduledGraph(Identity.New(_activityName, _activityVersion, _positionalName)); + var scheduledActivityEventGraph = _builder.ActivityScheduledGraph(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()); _activityScheduledEvent = new ActivityScheduledEvent(scheduledActivityEventGraph.First(),scheduledActivityEventGraph); } diff --git a/Guflow.Tests/Decider/Activity/ActivitySchedulingFailedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivitySchedulingFailedEventTests.cs index d59047f..b1b0bc8 100644 --- a/Guflow.Tests/Decider/Activity/ActivitySchedulingFailedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivitySchedulingFailedEventTests.cs @@ -10,9 +10,9 @@ namespace Guflow.Tests.Decider public class ActivitySchedulingFailedEventTests { private ActivitySchedulingFailedEvent _activitySchedulingFailedEvent; - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; private const string _cause = "detail"; private EventGraphBuilder _builder; @@ -20,7 +20,7 @@ public class ActivitySchedulingFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var schedulingFailedEventGraph = _builder.ActivitySchedulingFailedGraph(Identity.New(_activityName, _activityVersion, _positionalName),_cause); + var schedulingFailedEventGraph = _builder.ActivitySchedulingFailedGraph(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(),_cause); _activitySchedulingFailedEvent = new ActivitySchedulingFailedEvent(schedulingFailedEventGraph.First()); } @@ -55,7 +55,7 @@ private class SingleActivityWorkflow : Workflow { public SingleActivityWorkflow() { - ScheduleActivity(_activityName, _activityVersion, _positionalName); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName); } } @@ -63,7 +63,7 @@ private class WorkflowWithCustomAction : Workflow { public WorkflowWithCustomAction(WorkflowAction workflowAction) { - ScheduleActivity(_activityName, _activityVersion, _positionalName).OnSchedulingFailed(e => workflowAction); + ScheduleActivity(ActivityName, ActivityVersion, PositionalName).OnSchedulingFailed(e => workflowAction); } } } diff --git a/Guflow.Tests/Decider/Activity/ActivityStartedEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityStartedEventTests.cs index a243a40..bb602ef 100644 --- a/Guflow.Tests/Decider/Activity/ActivityStartedEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityStartedEventTests.cs @@ -10,10 +10,10 @@ namespace Guflow.Tests.Decider [TestFixture] public class ActivityStartedEventTests { - private const string _activityName = "Download"; - private const string _activityVersion = "1.0"; - private const string _positionalName = "First"; - private const string _workerId = "id"; + private const string ActivityName = "Download"; + private const string ActivityVersion = "1.0"; + private const string PositionalName = "First"; + private const string WorkerId = "id"; private ActivityStartedEvent _activityStartedEvent; private EventGraphBuilder _builder; @@ -22,13 +22,13 @@ public class ActivityStartedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var scheduledActivityEventGraph = _builder.ActivityStartedGraph(Identity.New(_activityName, _activityVersion, _positionalName),_workerId); + var scheduledActivityEventGraph = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(),WorkerId); _activityStartedEvent = new ActivityStartedEvent(scheduledActivityEventGraph.First(), scheduledActivityEventGraph); } [Test] public void Should_populate_properties_from_event_attributes() { - Assert.That(_activityStartedEvent.WorkerIdentity,Is.EqualTo(_workerId)); + Assert.That(_activityStartedEvent.WorkerIdentity,Is.EqualTo(WorkerId)); Assert.That(_activityStartedEvent.IsActive,Is.True); } diff --git a/Guflow.Tests/Decider/Activity/ActivityTimedoutEventTests.cs b/Guflow.Tests/Decider/Activity/ActivityTimedoutEventTests.cs index c6098b5..a8b4f90 100644 --- a/Guflow.Tests/Decider/Activity/ActivityTimedoutEventTests.cs +++ b/Guflow.Tests/Decider/Activity/ActivityTimedoutEventTests.cs @@ -77,7 +77,8 @@ public void Can_return_the_custom_workflow_action() private ActivityTimedoutEvent CreateActivityTimedoutEvent(string timeoutType, string details) { - var activityTimedoutEventGraph = _builder.ActivityTimedoutGraph(Identity.New(_activityName, _activityVersion, _positionalName), _identity, timeoutType, details); + var activityIdentity = Identity.New(_activityName, _activityVersion, _positionalName).ScheduleId(); + var activityTimedoutEventGraph = _builder.ActivityTimedoutGraph(activityIdentity, _identity, timeoutType, details); return new ActivityTimedoutEvent(activityTimedoutEventGraph.First(), activityTimedoutEventGraph); } diff --git a/Guflow.Tests/Decider/Activity/CancelActivityDecisionTests.cs b/Guflow.Tests/Decider/Activity/CancelActivityDecisionTests.cs index afc0be2..01c2d70 100644 --- a/Guflow.Tests/Decider/Activity/CancelActivityDecisionTests.cs +++ b/Guflow.Tests/Decider/Activity/CancelActivityDecisionTests.cs @@ -12,21 +12,21 @@ public class CancelActivityDecisionTests [Test] public void Equality_tests() { - Assert.IsTrue(new CancelActivityDecision(Identity.New("activity","1.0")).Equals(new CancelActivityDecision(Identity.New("activity","1.0")))); + Assert.IsTrue(new CancelActivityDecision(Identity.New("activity","1.0").ScheduleId()).Equals(new CancelActivityDecision(Identity.New("activity","1.0").ScheduleId()))); - Assert.IsFalse(new CancelActivityDecision(Identity.New("activity", "1.0")).Equals(new CancelActivityDecision(Identity.New("activity", "2.0")))); + Assert.IsFalse(new CancelActivityDecision(Identity.New("activity", "1.0").ScheduleId()).Equals(new CancelActivityDecision(Identity.New("activity", "2.0").ScheduleId()))); } [Test] public void Return_aws_decision_to_cancel_activity() { - var activityIdentity = Identity.New("activity", "1.0"); - var cancelActivityDecision = new CancelActivityDecision(activityIdentity); + var scheduleId = Identity.New("activity", "1.0").ScheduleId(); + var cancelActivityDecision = new CancelActivityDecision(scheduleId); Decision swfDecision = cancelActivityDecision.SwfDecision(); Assert.That(swfDecision.DecisionType,Is.EqualTo(DecisionType.RequestCancelActivityTask)); - Assert.That(swfDecision.RequestCancelActivityTaskDecisionAttributes.ActivityId,Is.EqualTo(activityIdentity.Id.ToString())); + Assert.That(swfDecision.RequestCancelActivityTaskDecisionAttributes.ActivityId,Is.EqualTo(scheduleId.ToString())); } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Activity/ScheduleActivityDecisionTests.cs b/Guflow.Tests/Decider/Activity/ScheduleActivityDecisionTests.cs index ef27e4a..1e6efe4 100644 --- a/Guflow.Tests/Decider/Activity/ScheduleActivityDecisionTests.cs +++ b/Guflow.Tests/Decider/Activity/ScheduleActivityDecisionTests.cs @@ -9,20 +9,20 @@ namespace Guflow.Tests.Decider [TestFixture] public class ScheduleActivityDecisionTests { - private Identity _activityIdentity; + private ScheduleId _scheduleId; private ScheduleActivityDecision _scheduleActivityDecision; [SetUp] public void Setup() { - _activityIdentity = Identity.New("Download", "1.0", "First"); - _scheduleActivityDecision = new ScheduleActivityDecision(_activityIdentity); + _scheduleId = Identity.New("Download", "1.0", "First").ScheduleId(); + _scheduleActivityDecision = new ScheduleActivityDecision(_scheduleId); } [Test] public void Equality_tests() { - Assert.True(new ScheduleActivityDecision(Identity.New("Download","1.0","First")).Equals(new ScheduleActivityDecision(Identity.New("Download","1.0","First")))); - Assert.False(new ScheduleActivityDecision(Identity.New("Download", "1.0", "First")).Equals(new ScheduleActivityDecision(Identity.New("Download", "2.0", "First")))); + Assert.True(new ScheduleActivityDecision(Identity.New("Download","1.0","First").ScheduleId()).Equals(new ScheduleActivityDecision(Identity.New("Download","1.0","First").ScheduleId()))); + Assert.False(new ScheduleActivityDecision(Identity.New("Download", "1.0", "First").ScheduleId()).Equals(new ScheduleActivityDecision(Identity.New("Download", "2.0", "First").ScheduleId()))); } [Test] @@ -31,7 +31,7 @@ public void Should_return_aws_decision_to_schedule_the_activity() var swfDecision = _scheduleActivityDecision.SwfDecision(); Assert.That(swfDecision.DecisionType,Is.EqualTo(DecisionType.ScheduleActivityTask)); - Assert.That(swfDecision.ScheduleActivityTaskDecisionAttributes.ActivityId,Is.EqualTo(_activityIdentity.Id.ToString())); + Assert.That(swfDecision.ScheduleActivityTaskDecisionAttributes.ActivityId,Is.EqualTo(_scheduleId.ToString())); Assert.That(swfDecision.ScheduleActivityTaskDecisionAttributes.ActivityType.Name,Is.EqualTo("Download")); Assert.That(swfDecision.ScheduleActivityTaskDecisionAttributes.ActivityType.Version, Is.EqualTo("1.0")); Assert.That(swfDecision.ScheduleActivityTaskDecisionAttributes.Control.As().PN, Is.EqualTo("First")); diff --git a/Guflow.Tests/Decider/AwsIdentityTests.cs b/Guflow.Tests/Decider/AwsIdentityTests.cs index 7558398..8b86547 100644 --- a/Guflow.Tests/Decider/AwsIdentityTests.cs +++ b/Guflow.Tests/Decider/AwsIdentityTests.cs @@ -10,20 +10,20 @@ public class AwsIdentityTests [Test] public void Equality_test() { - Assert.That(SwfIdentity.Create("name","ver","pos").Equals(SwfIdentity.Create("name","ver","pos"))); - Assert.That(SwfIdentity.Create("name", "ver", "").Equals(SwfIdentity.Create("name", "ver", ""))); - Assert.That(SwfIdentity.Raw("identity").Equals(SwfIdentity.Raw("identity"))); - Assert.That(SwfIdentity.Create("name", "ver", "pos")==SwfIdentity.Create("name", "ver", "pos")); - Assert.That(SwfIdentity.Create("name", "ver", "")==SwfIdentity.Create("name", "ver", "")); - Assert.That(SwfIdentity.Raw("identity")==SwfIdentity.Raw("identity")); + Assert.That(ScheduleId.Create("name","ver","pos").Equals(ScheduleId.Create("name","ver","pos"))); + Assert.That(ScheduleId.Create("name", "ver", "").Equals(ScheduleId.Create("name", "ver", ""))); + Assert.That(ScheduleId.Raw("identity").Equals(ScheduleId.Raw("identity"))); + Assert.That(ScheduleId.Create("name", "ver", "pos")==ScheduleId.Create("name", "ver", "pos")); + Assert.That(ScheduleId.Create("name", "ver", "")==ScheduleId.Create("name", "ver", "")); + Assert.That(ScheduleId.Raw("identity")==ScheduleId.Raw("identity")); - Assert.False(SwfIdentity.Create("name", "ver", "pos").Equals(SwfIdentity.Create("name", "ver", "pos1"))); - Assert.False(SwfIdentity.Create("name", "ver", "pos").Equals(SwfIdentity.Create("name", "ver1", "pos"))); - Assert.False(SwfIdentity.Create("name", "ver", "pos").Equals(SwfIdentity.Create("name1", "ver", "pos"))); - Assert.False(SwfIdentity.Raw("identity").Equals(SwfIdentity.Raw("identity1"))); - Assert.True(SwfIdentity.Create("name", "ver", "pos")!=SwfIdentity.Create("name", "ver", "pos1")); - Assert.True(SwfIdentity.Create("name", "ver", "pos")!=SwfIdentity.Create("name", "ver1", "pos")); - Assert.True(SwfIdentity.Create("name", "ver", "pos")!=SwfIdentity.Create("name1", "ver", "pos")); + Assert.False(ScheduleId.Create("name", "ver", "pos").Equals(ScheduleId.Create("name", "ver", "pos1"))); + Assert.False(ScheduleId.Create("name", "ver", "pos").Equals(ScheduleId.Create("name", "ver1", "pos"))); + Assert.False(ScheduleId.Create("name", "ver", "pos").Equals(ScheduleId.Create("name1", "ver", "pos"))); + Assert.False(ScheduleId.Raw("identity").Equals(ScheduleId.Raw("identity1"))); + Assert.True(ScheduleId.Create("name", "ver", "pos")!=ScheduleId.Create("name", "ver", "pos1")); + Assert.True(ScheduleId.Create("name", "ver", "pos")!=ScheduleId.Create("name", "ver1", "pos")); + Assert.True(ScheduleId.Create("name", "ver", "pos")!=ScheduleId.Create("name1", "ver", "pos")); } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Cancel/CancelRequestTests.cs b/Guflow.Tests/Decider/Cancel/CancelRequestTests.cs index b82877f..39bc06f 100644 --- a/Guflow.Tests/Decider/Cancel/CancelRequestTests.cs +++ b/Guflow.Tests/Decider/Cancel/CancelRequestTests.cs @@ -22,40 +22,55 @@ public class CancelRequestTests private const string WorkflowPosName = "pos"; private Mock _workflow; private EventGraphBuilder _eventGraph; - private HistoryEventsBuilder _historyBuilder; + private HistoryEventsBuilder _builder; [SetUp] public void Setup() { _eventGraph = new EventGraphBuilder(); _workflow = new Mock(); - _workflow.SetupGet(w => w.WorkflowHistoryEvents) - .Returns(new WorkflowHistoryEvents(new[] { new HistoryEvent() })); - _historyBuilder = new HistoryEventsBuilder(); + _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(new WorkflowHistoryEvents(new[] { new HistoryEvent() })); + _builder = new HistoryEventsBuilder(); } [Test] public void Returns_cancel_timer_decision_for_timer_item_when_it_is_active() { - SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(Identity.Timer("TimerName"), TimeSpan.FromSeconds(2))); + SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(Identity.Timer("TimerName").ScheduleId(), TimeSpan.FromSeconds(2))); var timerItem = TimerItem.New(Identity.Timer("TimerName"), _workflow.Object); var workflowAction = WorkflowAction.Cancel(timerItem); var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer("TimerName")) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer("TimerName").ScheduleId()) })); + } + + [Test] + public void Returns_cancel_timer_decision_for_timer_item_when_it_is_active_with_reset_schedule_id() + { + const string runId = "runid"; + _builder.AddWorkflowRunId(runId); + var scheduleId = Identity.Timer("TimerName").ScheduleId(runId+"Reset"); + _builder.AddProcessedEvents(_eventGraph.TimerStartedGraph(scheduleId, TimeSpan.FromSeconds(2)).ToArray()); + _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_builder.Result()); + var timerItem = TimerItem.New(Identity.Timer("TimerName"), _workflow.Object); + var workflowAction = WorkflowAction.Cancel(timerItem); + + var decisions = workflowAction.Decisions(); + + Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(scheduleId) })); } [Test] public void Returns_cancel_activity_decision_for_activity_item_when_reschedule_timer_is_not_active() { - SetupWorkflowToReturns(_eventGraph.ActivityStartedGraph(Identity.New("activityName1", "ver"), "id")); + SetupWorkflowToReturns(_eventGraph.ActivityStartedGraph(Identity.New("activityName1", "ver").ScheduleId(), "id")); var activityItem = new ActivityItem(Identity.New("activityName1", "ver"), _workflow.Object); var workflowAction = WorkflowAction.Cancel(activityItem); var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelActivityDecision(Identity.New("activityName1", "ver")) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelActivityDecision(Identity.New("activityName1", "ver").ScheduleId()) })); } [Test] @@ -66,32 +81,32 @@ public void Returns_cancel_activity_decision_for_activity_item_when_neither_acti var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelActivityDecision(Identity.New("activityName1", "ver")) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelActivityDecision(Identity.New("activityName1", "ver").ScheduleId()) })); } [Test] public void Returns_cancel_timer_decision_for_activity_item_when_reschedule_timer_is_active() { - SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(Identity.New("activityName1", "ver"), TimeSpan.FromSeconds(2), true)); + SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(Identity.New("activityName1", "ver").ScheduleId(), TimeSpan.FromSeconds(2), true)); var activityItem = new ActivityItem(Identity.New("activityName1", "ver"), _workflow.Object); var workflowAction = WorkflowAction.Cancel(activityItem); var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.New("activityName1", "ver")) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.New("activityName1", "ver").ScheduleId()) })); } [Test] public void Returns_cancel_child_workflow_decision_for_child_workflow_item_when_reschedule_timer_is_not_active() { var identity = Identity.New("workflow", "ver"); - SetupWorkflowToReturns(_eventGraph.ChildWorkflowStartedEventGraph(identity, "id", "input")); + SetupWorkflowToReturns(_eventGraph.ChildWorkflowStartedEventGraph(identity.ScheduleId(), "id", "input")); var childWorkflowItem = new ChildWorkflowItem(identity, _workflow.Object); var workflowAction = WorkflowAction.Cancel(childWorkflowItem); var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(identity.Id, "id")})); + Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(identity.ScheduleId(), "id")})); } [Test] @@ -103,20 +118,20 @@ public void Returns_cancel_child_workflow_decision_for_child_workflow_item_when_ var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(identity.Id, null) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(identity.ScheduleId(), null) })); } [Test] public void Returns_cancel_timer_decision_for_child_workflow_item_when_reschedule_timer_is_active() { var identity = Identity.New("workflow", "ver"); - SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(identity, TimeSpan.FromSeconds(2), true)); + SetupWorkflowToReturns(_eventGraph.TimerStartedGraph(identity.ScheduleId(), TimeSpan.FromSeconds(2), true)); var item = new ChildWorkflowItem(identity, _workflow.Object); var workflowAction = WorkflowAction.Cancel(item); var decisions = workflowAction.Decisions(); - Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(identity) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(identity.ScheduleId()) })); } [Test] @@ -127,7 +142,7 @@ public void Cancel_request_for_activity_can_be_returned_as_custom_action_from_wo var decisions = workflow.Decisions(events); - Assert.That(decisions, Is.EqualTo(new []{new CancelActivityDecision(Identity.New("ActivityToCancel", "1.2"))})); + Assert.That(decisions, Is.EqualTo(new []{new CancelActivityDecision(Identity.New("ActivityToCancel", "1.2").ScheduleId())})); } [Test] @@ -138,7 +153,7 @@ public void Cancel_request_for_timer_can_be_returned_as_custom_action_from_workf var decisions = workflow.Decisions(events); - Assert.That(decisions, Is.EqualTo(new []{new CancelTimerDecision(Identity.Timer(TimerName))})); + Assert.That(decisions, Is.EqualTo(new []{new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId())})); } [Test] @@ -149,20 +164,23 @@ public void Cancel_request_for_multiple_items_can_be_returned_as_workflow_action var decisions = workflow.Decisions(historyEvents); - Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { new CancelActivityDecision(Identity.New(ActivityName, ActivityVersion)), new CancelTimerDecision(Identity.Timer(TimerName)) })); + Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] + { + new CancelActivityDecision(Identity.New(ActivityName, ActivityVersion).ScheduleId()), new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()) + })); } [Test] public void By_default_cancel_request_for_timer_does_not_generate_additional_workflow_action_when_timer_is_active() { var workflow = new WorkflowToReturnCancelledTimerAction(); - _historyBuilder.AddNewEvents(TimerStartedEventGraph(TimerName)); - _historyBuilder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, + _builder.AddNewEvents(TimerStartedEventGraph(TimerName)); + _builder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, PositionalName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer(TimerName)) })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()) })); } [Test] @@ -171,15 +189,15 @@ public void During_timer_cancel_request_user_can_provide_additional_cancel_actio var additionalAction = new Mock(); additionalAction.Setup(a => a.Decisions()).Returns(new[] {new RecordMarkerWorkflowDecision("result" ,"details"), }); var workflow = new WorkflowToReturnCustomActionDuringCancel(additionalAction.Object); - _historyBuilder.AddNewEvents(TimerStartedEventGraph(TimerName)); - _historyBuilder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, + _builder.AddNewEvents(TimerStartedEventGraph(TimerName)); + _builder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, PositionalName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new CancelTimerDecision(Identity.Timer(TimerName)), + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()), new RecordMarkerWorkflowDecision("result" ,"details"), })); } @@ -190,14 +208,14 @@ public void During_timer_cancel_request_user_provided_additional_cancel_action_i var additionalAction = new Mock(); additionalAction.Setup(a => a.Decisions()).Returns(new[] { new RecordMarkerWorkflowDecision("result", "details"), }); var workflow = new WorkflowToReturnCustomActionDuringCancel(additionalAction.Object); - _historyBuilder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, + _builder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, PositionalName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new CancelTimerDecision(Identity.Timer(TimerName)), + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()), })); } @@ -205,40 +223,45 @@ public void During_timer_cancel_request_user_provided_additional_cancel_action_i public void Can_invoke_cancel_request_for_timer_in_timer_oncancel_api() { var workflow = new InvokedCancelRequestForTimerInOnCancelMethod(); - _historyBuilder.AddNewEvents(TimerStartedEventGraph(TimerName)); - _historyBuilder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, + _builder.AddNewEvents(TimerStartedEventGraph(TimerName)); + _builder.AddNewEvents(CompletedActivityEventGraph(ActivityName, ActivityVersion, PositionalName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new CancelTimerDecision(Identity.Timer(TimerName)), + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()), })); } [Test] public void Returns_cancel_request_for_child_workflow() { + const string parentRunId = "ParentRunId"; var workflow = new CancelRequestForChildWorkflow(); - _historyBuilder.AddProcessedEvents(ChildWorkflowStarted("rid")); - _historyBuilder.AddNewEvents(TimerFiredEventGraph(TimerName)); + _builder.AddProcessedEvents(ChildWorkflowStarted(parentRunId, "rid")); + _builder.AddWorkflowRunId(parentRunId); + _builder.AddNewEvents(TimerFiredEventGraph(TimerName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[]{new CancelRequestWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName).Id, "rid")})); + Assert.That(decisions, Is.EqualTo(new[]{new CancelRequestWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName).ScheduleId(parentRunId), "rid")})); } [Test] public void Returns_cancel_request_for_child_workflow_using_generic_api() { + const string parentRunId = "ParentRunId"; + var workflow = new CancelRequestForChildWorkflowUsingGenericTypeApi(); - _historyBuilder.AddProcessedEvents(ChildWorkflowStarted("rid")); - _historyBuilder.AddNewEvents(TimerFiredEventGraph(TimerName)); + _builder.AddProcessedEvents(ChildWorkflowStarted(parentRunId, "rid")); + _builder.AddWorkflowRunId(parentRunId); + _builder.AddNewEvents(TimerFiredEventGraph(TimerName)); - var decisions = workflow.Decisions(_historyBuilder.Result()); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName).Id, "rid") })); + Assert.That(decisions, Is.EqualTo(new[] { new CancelRequestWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName).ScheduleId(parentRunId), "rid") })); } [Test] @@ -257,29 +280,29 @@ public void Invalid_arugments_test() private IWorkflowHistoryEvents CreateCompletedActivityEvent(string activityName, string activityVersion, string positionalName) { - var allHistoryEvents = _eventGraph.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res"); + var allHistoryEvents = _eventGraph.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res"); return new WorkflowHistoryEvents(allHistoryEvents); } private HistoryEvent[] CompletedActivityEventGraph(string activityName, string activityVersion, string positionalName) { - return _eventGraph.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName), "id", "res").ToArray(); + return _eventGraph.ActivityCompletedGraph(Identity.New(activityName, activityVersion, positionalName).ScheduleId(), "id", "res").ToArray(); } private HistoryEvent[] TimerStartedEventGraph(string timerName) { - return _eventGraph.TimerStartedGraph(Identity.Timer(timerName), TimeSpan.FromSeconds(1)).ToArray(); + return _eventGraph.TimerStartedGraph(Identity.Timer(timerName).ScheduleId(), TimeSpan.FromSeconds(1)).ToArray(); } private HistoryEvent[] TimerFiredEventGraph(string timerName) { - return _eventGraph.TimerFiredGraph(Identity.Timer(timerName), TimeSpan.FromSeconds(1)).ToArray(); + return _eventGraph.TimerFiredGraph(Identity.Timer(timerName).ScheduleId(), TimeSpan.FromSeconds(1)).ToArray(); } - private HistoryEvent[] ChildWorkflowStarted(string runId) + private HistoryEvent[] ChildWorkflowStarted(string parentRunId, string runId) { return _eventGraph - .ChildWorkflowStartedEventGraph(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName), runId, "input").ToArray(); + .ChildWorkflowStartedEventGraph(Identity.New(WorkflowName, WorkflowVersion, WorkflowPosName).ScheduleId(parentRunId), runId, "input").ToArray(); } private class WorkflowToReturnCancelActivityAction : Workflow diff --git a/Guflow.Tests/Decider/Cancel/CancelWorkflowRequestWorkflowActionTests.cs b/Guflow.Tests/Decider/Cancel/CancelWorkflowRequestWorkflowActionTests.cs index 02c16cc..ddc7e2e 100644 --- a/Guflow.Tests/Decider/Cancel/CancelWorkflowRequestWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Cancel/CancelWorkflowRequestWorkflowActionTests.cs @@ -9,12 +9,13 @@ namespace Guflow.Tests.Decider [TestFixture] public class CancelWorkflowRequestWorkflowActionTests { - private EventGraphBuilder _builder; - + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); } @@ -29,13 +30,15 @@ public void Returns_cancel_request_workflow_decision() [Test] public void Can_be_returned_as_custom_action_from_workflow() { - var workflow = new WorkflowToReturnCancelRequest("id", "runid"); - var timerFiredEventGraph = _builder.TimerFiredGraph(Identity.Timer("timer1"), TimeSpan.FromSeconds(2)); - var timerEvent = new TimerFiredEvent(timerFiredEventGraph.First(), timerFiredEventGraph); + const string runId = "runid"; + var workflow = new WorkflowToReturnCancelRequest("id", "other workflow runid"); + var scheduleId = Identity.Timer("timer1").ScheduleId(); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(scheduleId, TimeSpan.FromSeconds(2)).ToArray()); + _builder.AddWorkflowRunId(runId); - var decisions = timerEvent.Interpret(workflow).Decisions(); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new []{new CancelRequestWorkflowDecision("id", "runid")})); + Assert.That(decisions, Is.EqualTo(new []{new CancelRequestWorkflowDecision("id", "other workflow runid") })); } private class WorkflowToReturnCancelRequest : Workflow diff --git a/Guflow.Tests/Decider/Cancel/ExternaWorkflowCancelRequestFailedEventTests.cs b/Guflow.Tests/Decider/Cancel/ExternaWorkflowCancelRequestFailedEventTests.cs index a40d2e9..3032600 100644 --- a/Guflow.Tests/Decider/Cancel/ExternaWorkflowCancelRequestFailedEventTests.cs +++ b/Guflow.Tests/Decider/Cancel/ExternaWorkflowCancelRequestFailedEventTests.cs @@ -18,7 +18,7 @@ public class ExternalWorkflowCancelRequestFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var identity = Identity.New("w", "v"); + var identity = Identity.New("w", "v").ScheduleId(); _cancelRequestFailedEvent = new ExternalWorkflowCancelRequestFailedEvent(_builder.ExternalWorkflowCancelRequestFailedEvent(identity,"rid", "cause").First()); } diff --git a/Guflow.Tests/Decider/Cancel/ExternalWorkflowCancellationRequestedEventTests.cs b/Guflow.Tests/Decider/Cancel/ExternalWorkflowCancellationRequestedEventTests.cs index ba640e7..31bb440 100644 --- a/Guflow.Tests/Decider/Cancel/ExternalWorkflowCancellationRequestedEventTests.cs +++ b/Guflow.Tests/Decider/Cancel/ExternalWorkflowCancellationRequestedEventTests.cs @@ -23,7 +23,7 @@ public void Setup() _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName); _eventGraphBuilder = new EventGraphBuilder(); var eventGraph = - _eventGraphBuilder.ChildWorkflowCancellationRequestedEventGraph(_workflowIdentity, "rid", "input").ToArray(); + _eventGraphBuilder.ChildWorkflowCancellationRequestedEventGraph(_workflowIdentity.ScheduleId(), "rid", "input").ToArray(); _event = new ExternalWorkflowCancellationRequestedEvent(eventGraph.First()); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkStartedEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkStartedEventTests.cs index 1713926..7ad9244 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkStartedEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkStartedEventTests.cs @@ -17,13 +17,12 @@ public class ChildWorkStartedEventTests private const string WorkflowName = "workflow"; private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; - private Identity _workflowIdentity; [SetUp] public void Setup() { _eventGraphBuilder = new EventGraphBuilder(); - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName); - var eventGraph = _eventGraphBuilder.ChildWorkflowStartedEventGraph(_workflowIdentity, "runid", "input"); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleId(); + var eventGraph = _eventGraphBuilder.ChildWorkflowStartedEventGraph(scheduleId, "runid", "input"); _completedEvent = new ChildWorkflowStartedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelRequestFailedEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelRequestFailedEventTests.cs index 734f509..d80dd94 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelRequestFailedEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelRequestFailedEventTests.cs @@ -21,7 +21,7 @@ public void Setup() { _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(ParentWorkflowRunId); - var identity = Identity.New(WorkflowName, Version).ScheduleIdentity(ParentWorkflowRunId); + var identity = Identity.New(WorkflowName, Version).ScheduleId(ParentWorkflowRunId); var eventGraph = _eventGraphBuilder.ExternalWorkflowCancelRequestFailedEvent(identity, "rid", "cause").ToArray(); _builder.AddNewEvents(eventGraph); _cancelRequestFailedEvent = new ExternalWorkflowCancelRequestFailedEvent(eventGraph.First()); diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelledEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelledEventTests.cs index d3d7f54..cce3e55 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelledEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCancelledEventTests.cs @@ -16,18 +16,18 @@ public class ChildWorkflowCancelledEventTests private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; private const string ParentWorkflowRunId = "pId"; - private Identity _workflowIdentity; + private ScheduleId _scheduleId; [SetUp] public void Setup() { - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName) - .ScheduleIdentity(ParentWorkflowRunId); + _scheduleId = Identity.New(WorkflowName, WorkflowVersion, PositionalName) + .ScheduleId(ParentWorkflowRunId); _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder(); _builder.AddWorkflowRunId(ParentWorkflowRunId); var eventGraph = - _eventGraphBuilder.ChildWorkflowCancelledEventGraph(_workflowIdentity, "rid", "input", "details").ToArray(); + _eventGraphBuilder.ChildWorkflowCancelledEventGraph(_scheduleId, "rid", "input", "details").ToArray(); _builder.AddNewEvents(eventGraph); _event = new ChildWorkflowCancelledEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCompletedEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCompletedEventTests.cs index e6fe827..fd671dc 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCompletedEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowCompletedEventTests.cs @@ -20,7 +20,7 @@ public class ChildWorkflowCompletedEventTests private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; private const string ParentWorkflowRunId = "Pid"; - private Identity _workflowIdentity; + private ScheduleId _workflowIdentity; [SetUp] public void Setup() { @@ -28,7 +28,7 @@ public void Setup() _builder = new HistoryEventsBuilder(); _builder.AddWorkflowRunId(ParentWorkflowRunId); - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleIdentity(ParentWorkflowRunId); + _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleId(ParentWorkflowRunId); var eventGraph = _eventGraphBuilder.ChildWorkflowCompletedGraph(_workflowIdentity, "runid", "input", "result").ToArray(); _builder.AddNewEvents(eventGraph); _event = new ChildWorkflowCompletedEvent(eventGraph.First() , eventGraph); @@ -56,7 +56,7 @@ public void By_default_schedule_children() { var decisions = new ChildWorkflow().Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new []{new ScheduleTimerDecision(Identity.Timer("TimerName"), TimeSpan.Zero)})); + Assert.That(decisions, Is.EqualTo(new []{new ScheduleTimerDecision(Identity.Timer("TimerName").ScheduleId(), TimeSpan.Zero)})); } [Test] diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowFailedEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowFailedEventTests.cs index de97a3d..4d5ff59 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowFailedEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowFailedEventTests.cs @@ -18,13 +18,13 @@ public class ChildWorkflowFailedEventTests private const string PositionalName = "Pos"; private const string ParentWorkflowRunId = "Pid"; - private Identity _workflowIdentity; + private ScheduleId _workflowIdentity; [SetUp] public void Setup() { _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName) - .ScheduleIdentity(ParentWorkflowRunId); + .ScheduleId(ParentWorkflowRunId); _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(ParentWorkflowRunId); diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemExtensionTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemExtensionTests.cs index b3c396e..5284c1d 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemExtensionTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemExtensionTests.cs @@ -14,11 +14,13 @@ public class ChildWorkflowItemExtensionTests private Mock _childWorkflowItem; private EventGraphBuilder _builder; private Identity _identity; + private ScheduleId _scheduleId; [SetUp] public void Setup() { _builder = new EventGraphBuilder(); _identity = Identity.New("name", "ver", "pos"); + _scheduleId = _identity.ScheduleId(); _childWorkflowItem = new Mock(); } @@ -152,28 +154,28 @@ public void Null_argument_tests() private ChildWorkflowCompletedEvent CompletedEvent(string result) { - var graph = _builder.ChildWorkflowCompletedGraph(_identity, "runid", "input", result); + var graph = _builder.ChildWorkflowCompletedGraph(_scheduleId, "runid", "input", result); return new ChildWorkflowCompletedEvent(graph.First(), graph); } private ChildWorkflowFailedEvent FailedEvent(string reason, string details) { - var graph = _builder.ChildWorkflowFailedEventGraph(_identity, "runid", "input", reason, details); + var graph = _builder.ChildWorkflowFailedEventGraph(_scheduleId, "runid", "input", reason, details); return new ChildWorkflowFailedEvent(graph.First(), graph); } private ChildWorkflowTimedoutEvent TimedoutEvent(string timeoutType) { - var graph = _builder.ChildWorkflowTimedoutEventGraph(_identity, "runid", "input", timeoutType); + var graph = _builder.ChildWorkflowTimedoutEventGraph(_scheduleId, "runid", "input", timeoutType); return new ChildWorkflowTimedoutEvent(graph.First(), graph); } private ChildWorkflowTerminatedEvent TerminatedEvent() { - var graph = _builder.ChildWorkflowTerminatedEventGraph(_identity, "runid", "input"); + var graph = _builder.ChildWorkflowTerminatedEventGraph(_scheduleId, "runid", "input"); return new ChildWorkflowTerminatedEvent(graph.First(), graph); } private ChildWorkflowCancelledEvent CancelledEvent(string details) { - var graph = _builder.ChildWorkflowCancelledEventGraph(_identity, "runid", "input", details); + var graph = _builder.ChildWorkflowCancelledEventGraph(_scheduleId, "runid", "input", details); return new ChildWorkflowCancelledEvent(graph.First(), graph); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemTests.cs index 94b1e2f..cd75236 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowItemTests.cs @@ -18,7 +18,7 @@ public class ChildWorkflowItemTests private HistoryEventsBuilder _builder; private Mock _workflow; private Identity _identity; - private Identity _scheduleIdentity; + private ScheduleId _scheduleIdentity; private const string WorkflowName = "Workflow"; private const string Version = "1.0"; private const string PositionalName = "Pos"; @@ -27,7 +27,7 @@ public class ChildWorkflowItemTests public void Setup() { _identity = Identity.New(WorkflowName, Version, PositionalName); - _scheduleIdentity = _identity.ScheduleIdentity(WorkflowRunId); + _scheduleIdentity = _identity.ScheduleId(WorkflowRunId); _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(WorkflowRunId); _builder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedGraph("input").ToArray()); @@ -82,7 +82,7 @@ public void Schedule_the_child_workflow() var attr = swfDecision.StartChildWorkflowExecutionDecisionAttributes; Assert.That(attr.WorkflowType.Name, Is.EqualTo(WorkflowName)); Assert.That(attr.WorkflowType.Version, Is.EqualTo(Version)); - Assert.That(attr.WorkflowId , Is.EqualTo(_scheduleIdentity.Id.ToString())); + Assert.That(attr.WorkflowId , Is.EqualTo(_scheduleIdentity.ToString())); Assert.That(attr.Control.As().PN , Is.EqualTo(_identity.PositionalName)); Assert.That(attr.ChildPolicy.Value, Is.EqualTo("child")); Assert.That(attr.ExecutionStartToCloseTimeout, Is.EqualTo("3")); @@ -103,7 +103,7 @@ public void Schedule_the_child_workflow_without_providing_workflow_description() var attr = swfDecision.StartChildWorkflowExecutionDecisionAttributes; Assert.That(attr.WorkflowType.Name, Is.EqualTo(WorkflowName)); Assert.That(attr.WorkflowType.Version, Is.EqualTo(Version)); - Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.Id.ToString())); + Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.ToString())); Assert.That(attr.Control.As().PN, Is.EqualTo(_identity.PositionalName)); Assert.That(attr.ChildPolicy, Is.Null); Assert.That(attr.ExecutionStartToCloseTimeout, Is.Null); @@ -140,7 +140,7 @@ public void Can_override_scheduling_properties_when_workflow_description_is_prov var attr = swfDecision.StartChildWorkflowExecutionDecisionAttributes; Assert.That(attr.WorkflowType.Name, Is.EqualTo(WorkflowName)); Assert.That(attr.WorkflowType.Version, Is.EqualTo(Version)); - Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.Id.ToString())); + Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.ToString())); Assert.That(attr.Control.As().PN, Is.EqualTo(_identity.PositionalName)); Assert.That(attr.ChildPolicy.Value, Is.EqualTo("newchild")); Assert.That(attr.ExecutionStartToCloseTimeout, Is.EqualTo("4")); @@ -167,7 +167,7 @@ public void Can_override_scheduling_properties_when_workflow_description_is_not_ var attr = swfDecision.StartChildWorkflowExecutionDecisionAttributes; Assert.That(attr.WorkflowType.Name, Is.EqualTo(WorkflowName)); Assert.That(attr.WorkflowType.Version, Is.EqualTo(Version)); - Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.Id.ToString())); + Assert.That(attr.WorkflowId, Is.EqualTo(_scheduleIdentity.ToString())); Assert.That(attr.Control.As().PN, Is.EqualTo(_identity.PositionalName)); Assert.That(attr.ChildPolicy.Value, Is.EqualTo("newchild")); Assert.That(attr.ExecutionStartToCloseTimeout, Is.EqualTo("4")); @@ -460,6 +460,20 @@ public void Last_event_returns_child_workflow_started_event_when_its_cancellatio } + [Test] + public void Last_event_filters_out_child_workflow_scheduling_failed_event() + { + var started = _eventGraphBuilder.ChildWorkflowStartedEventGraph(_scheduleIdentity, "runid", "input"); + var startFailed = _eventGraphBuilder.ChildWorkflowStartFailedEventGraph(_scheduleIdentity,"input", "cause").ToArray(); + + var childWorkflow = ChildWorkflow(startFailed.Concat(started)); + + var lastEvent = childWorkflow.LastEvent(); + + Assert.That(lastEvent, Is.EqualTo(new ChildWorkflowStartedEvent(started.First(), started))); + } + + [Test] public void Reschedule_decision_is_timer_schedule_decision_for_child_workflow_item() { diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowScheduleTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowScheduleTests.cs index 3514ae3..095d035 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowScheduleTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowScheduleTests.cs @@ -1,199 +1,199 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. - -using System; -using System.Linq; -using Guflow.Decider; -using Guflow.Worker; -using NUnit.Framework; - +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. + +using System; +using System.Linq; +using Guflow.Decider; +using Guflow.Worker; +using NUnit.Framework; + namespace Guflow.Tests.Decider { [TestFixture] public class ChildWorkflowScheduleTests - { - private const string ActivityName = "Activity1"; - private const string ActivityVersion = "1.0"; - private const string TimerName = "Timer1"; - - private const string LambdaName = "LambdaName"; - private const string ParentWorkflowName = "Pname"; - private const string ParentWorkflowVersion = "1.0"; - - private const string ChildWorkflowName = "Name"; - private const string ChildWorkflowVersion = "1.0"; - private const string ParentWorkflowRunId = "runid"; - private EventGraphBuilder _eventGraphBuilder; - private HistoryEventsBuilder _eventsBuilder; - private Identity _identity; - [SetUp] - public void Setup() - { - _eventGraphBuilder = new EventGraphBuilder(); - _eventsBuilder = new HistoryEventsBuilder().AddWorkflowRunId(ParentWorkflowRunId); - _identity = Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleIdentity(ParentWorkflowRunId); + { + private const string ActivityName = "Activity1"; + private const string ActivityVersion = "1.0"; + private const string TimerName = "Timer1"; + + private const string LambdaName = "LambdaName"; + private const string ParentWorkflowName = "Pname"; + private const string ParentWorkflowVersion = "1.0"; + + private const string ChildWorkflowName = "Name"; + private const string ChildWorkflowVersion = "1.0"; + private const string ParentWorkflowRunId = "runid"; + private EventGraphBuilder _eventGraphBuilder; + private HistoryEventsBuilder _eventsBuilder; + private ScheduleId _scheduleId; + [SetUp] + public void Setup() + { + _eventGraphBuilder = new EventGraphBuilder(); + _eventsBuilder = new HistoryEventsBuilder().AddWorkflowRunId(ParentWorkflowRunId); + _scheduleId = Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleId(ParentWorkflowRunId); } [Test] public void Child_workflow_can_be_scheduled_after_lambda() - { - var eventGraph = LambdaCompletedEventGraph(); - var decision = new ChildWorkflowAfterLambdaWorkflow().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); + { + var eventGraph = LambdaCompletedEventGraph(); + var decision = new ChildWorkflowAfterLambdaWorkflow().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); } [Test] public void Child_workflow_can_be_scheduled_after_timer() - { - var eventGraph = TimerCompletedEventGraph(); - var decision = new ChildWorkflowAfterTimerWorkflow().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); - } - - [Test] - public void Child_workflow_can_be_scheduled_after_child_workflow() - { - var eventGraph = ParentWorkflowCompletedEventGraph(); - var decision = new ChildWorkflowAfterChildWorkflow().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); - } - - [Test] - public void Child_workflow_can_be_scheduled_after_activity() - { - var eventGraph = ActivityEventGraph(); - var decision = new ChildWorkflowAfterActivity().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); - } - - - [Test] - public void Child_workflow_can_be_scheduled_after_activity_using_generic_api() - { - var eventGraph = ActivityEventGraph(); - var decision = new ChildWorkflowAfterActivityUsingGenericApi().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); - } - - [Test] - public void Child_workflow_can_be_scheduled_after_child_workflow_using_generic_type_api() - { - var eventGraph = ParentWorkflowCompletedEventGraph(); - var decision = new ChildWorkflowAfterChildWorkflowGenericType().Decisions(eventGraph); - - Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_identity, "input") })); - } - - private WorkflowHistoryEvents ActivityEventGraph() - { - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion), "id","res").ToArray()); - return _eventsBuilder.Result(); - } - - private WorkflowHistoryEvents TimerCompletedEventGraph() - { - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.FromSeconds(2)).ToArray()); - return _eventsBuilder.Result(); - } - - private WorkflowHistoryEvents LambdaCompletedEventGraph() - { - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName), "input", "result").ToArray()); - return _eventsBuilder.Result(); - } - private WorkflowHistoryEvents ParentWorkflowCompletedEventGraph() - { - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ChildWorkflowCompletedGraph(Identity.New(ParentWorkflowName, ParentWorkflowVersion).ScheduleIdentity(ParentWorkflowRunId), "rid", "input", - "result") - .ToArray()); - return _eventsBuilder.Result(); - - } - private class ChildWorkflowAfterLambdaWorkflow : Workflow - { - public ChildWorkflowAfterLambdaWorkflow() - { - ScheduleLambda(LambdaName); - ScheduleChildWorkflow().AfterLambda(LambdaName); - } - } - private class ChildWorkflowAfterTimerWorkflow : Workflow - { - public ChildWorkflowAfterTimerWorkflow() - { - ScheduleTimer(TimerName); - ScheduleChildWorkflow().AfterTimer(TimerName); - } - } - private class ChildWorkflowAfterChildWorkflow : Workflow - { - public ChildWorkflowAfterChildWorkflow() - { - ScheduleChildWorkflow(ParentWorkflowName, ParentWorkflowVersion); - ScheduleChildWorkflow() - .AfterChildWorkflow(ParentWorkflowName, ParentWorkflowVersion); - } - } - - private class ChildWorkflowAfterActivity : Workflow - { - public ChildWorkflowAfterActivity() - { - ScheduleActivity(ActivityName, ActivityVersion); - ScheduleChildWorkflow().AfterActivity(ActivityName, ActivityVersion); - } - } - - private class ChildWorkflowAfterActivityUsingGenericApi : Workflow - { - public ChildWorkflowAfterActivityUsingGenericApi() - { - ScheduleActivity(); - ScheduleChildWorkflow().AfterActivity(); - } - } - - [ActivityDescription(ActivityVersion, Name = ActivityName)] - private class TestActivity : Activity - { - - } - - private class ChildWorkflowAfterChildWorkflowGenericType : Workflow - { - public ChildWorkflowAfterChildWorkflowGenericType() - { - ScheduleChildWorkflow(); - ScheduleChildWorkflow() - .AfterChildWorkflow(); - } - } - - [WorkflowDescription(ChildWorkflowVersion, Name = ChildWorkflowName)] - private class ChildWorkflow : Workflow - { - public ChildWorkflow() - { - - } - } - - [WorkflowDescription(ParentWorkflowVersion, Name = ParentWorkflowName)] - private class ParentWorkflow : Workflow - { - public ParentWorkflow() - { - - } + { + var eventGraph = TimerCompletedEventGraph(); + var decision = new ChildWorkflowAfterTimerWorkflow().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); + } + + [Test] + public void Child_workflow_can_be_scheduled_after_child_workflow() + { + var eventGraph = ParentWorkflowCompletedEventGraph(); + var decision = new ChildWorkflowAfterChildWorkflow().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); + } + + [Test] + public void Child_workflow_can_be_scheduled_after_activity() + { + var eventGraph = ActivityEventGraph(); + var decision = new ChildWorkflowAfterActivity().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); + } + + + [Test] + public void Child_workflow_can_be_scheduled_after_activity_using_generic_api() + { + var eventGraph = ActivityEventGraph(); + var decision = new ChildWorkflowAfterActivityUsingGenericApi().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); + } + + [Test] + public void Child_workflow_can_be_scheduled_after_child_workflow_using_generic_type_api() + { + var eventGraph = ParentWorkflowCompletedEventGraph(); + var decision = new ChildWorkflowAfterChildWorkflowGenericType().Decisions(eventGraph); + + Assert.That(decision, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(_scheduleId, "input") })); + } + + private WorkflowHistoryEvents ActivityEventGraph() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id","res").ToArray()); + return _eventsBuilder.Result(); + } + + private WorkflowHistoryEvents TimerCompletedEventGraph() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(2)).ToArray()); + return _eventsBuilder.Result(); + } + + private WorkflowHistoryEvents LambdaCompletedEventGraph() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "result").ToArray()); + return _eventsBuilder.Result(); + } + private WorkflowHistoryEvents ParentWorkflowCompletedEventGraph() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder + .ChildWorkflowCompletedGraph(Identity.New(ParentWorkflowName, ParentWorkflowVersion).ScheduleId(ParentWorkflowRunId), "rid", "input", + "result") + .ToArray()); + return _eventsBuilder.Result(); + + } + private class ChildWorkflowAfterLambdaWorkflow : Workflow + { + public ChildWorkflowAfterLambdaWorkflow() + { + ScheduleLambda(LambdaName); + ScheduleChildWorkflow().AfterLambda(LambdaName); + } + } + private class ChildWorkflowAfterTimerWorkflow : Workflow + { + public ChildWorkflowAfterTimerWorkflow() + { + ScheduleTimer(TimerName); + ScheduleChildWorkflow().AfterTimer(TimerName); + } + } + private class ChildWorkflowAfterChildWorkflow : Workflow + { + public ChildWorkflowAfterChildWorkflow() + { + ScheduleChildWorkflow(ParentWorkflowName, ParentWorkflowVersion); + ScheduleChildWorkflow() + .AfterChildWorkflow(ParentWorkflowName, ParentWorkflowVersion); + } + } + + private class ChildWorkflowAfterActivity : Workflow + { + public ChildWorkflowAfterActivity() + { + ScheduleActivity(ActivityName, ActivityVersion); + ScheduleChildWorkflow().AfterActivity(ActivityName, ActivityVersion); + } + } + + private class ChildWorkflowAfterActivityUsingGenericApi : Workflow + { + public ChildWorkflowAfterActivityUsingGenericApi() + { + ScheduleActivity(); + ScheduleChildWorkflow().AfterActivity(); + } + } + + [ActivityDescription(ActivityVersion, Name = ActivityName)] + private class TestActivity : Activity + { + + } + + private class ChildWorkflowAfterChildWorkflowGenericType : Workflow + { + public ChildWorkflowAfterChildWorkflowGenericType() + { + ScheduleChildWorkflow(); + ScheduleChildWorkflow() + .AfterChildWorkflow(); + } + } + + [WorkflowDescription(ChildWorkflowVersion, Name = ChildWorkflowName)] + private class ChildWorkflow : Workflow + { + public ChildWorkflow() + { + + } + } + + [WorkflowDescription(ParentWorkflowVersion, Name = ParentWorkflowName)] + private class ParentWorkflow : Workflow + { + public ParentWorkflow() + { + + } } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowStartFailedTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowStartFailedTests.cs index 35e9ee4..c8825ae 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowStartFailedTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowStartFailedTests.cs @@ -16,15 +16,14 @@ public class ChildWorkflowStartFailedTests private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; private const string ParentWorkflowRunId = "ParentId"; - private Identity _workflowIdentity; [SetUp] public void Setup() { - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleIdentity(ParentWorkflowRunId); + var workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleId(ParentWorkflowRunId); _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(ParentWorkflowRunId); - var eventGraph = _eventGraphBuilder.ChildWorkflowStartFailedEventGraph(_workflowIdentity, "input", "cause").ToArray(); + var eventGraph = _eventGraphBuilder.ChildWorkflowStartFailedEventGraph(workflowIdentity, "input", "cause").ToArray(); _builder.AddNewEvents(eventGraph); _event = new ChildWorkflowStartFailedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTerminatedEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTerminatedEventTests.cs index c6e7a07..70076a8 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTerminatedEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTerminatedEventTests.cs @@ -17,14 +17,14 @@ public class ChildWorkflowTerminatedEventTests private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; private const string WorkflowRunId = "runid"; - private Identity _workflowIdentity; + [SetUp] public void Setup() { _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(WorkflowRunId); - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleIdentity(WorkflowRunId); - var eventGraph = _eventGraphBuilder.ChildWorkflowTerminatedEventGraph(_workflowIdentity, "runid", "input").ToArray(); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleId(WorkflowRunId); + var eventGraph = _eventGraphBuilder.ChildWorkflowTerminatedEventGraph(scheduleId, "runid", "input").ToArray(); _builder.AddNewEvents(eventGraph); _event = new ChildWorkflowTerminatedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTimedoutEventTests.cs b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTimedoutEventTests.cs index 4504afd..55c0d03 100644 --- a/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTimedoutEventTests.cs +++ b/Guflow.Tests/Decider/ChildWorkflow/ChildWorkflowTimedoutEventTests.cs @@ -16,14 +16,13 @@ public class ChildWorkflowTimedoutEventTests private const string WorkflowVersion = "1.0"; private const string PositionalName = "Pos"; private const string WorkflowRunId = "runid"; - private Identity _workflowIdentity; [SetUp] public void Setup() { _eventGraphBuilder = new EventGraphBuilder(); _builder = new HistoryEventsBuilder().AddWorkflowRunId(WorkflowRunId); - _workflowIdentity = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleIdentity(WorkflowRunId); - var eventGraph = _eventGraphBuilder.ChildWorkflowTimedoutEventGraph(_workflowIdentity, "runid", "input", "timeoutType").ToArray(); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion, PositionalName).ScheduleId(WorkflowRunId); + var eventGraph = _eventGraphBuilder.ChildWorkflowTimedoutEventGraph(scheduleId, "runid", "input", "timeoutType").ToArray(); _builder.AddNewEvents(eventGraph); _event = new ChildWorkflowTimedoutEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/DeflowAlgorithmTests.cs b/Guflow.Tests/Decider/DeflowAlgorithmTests.cs index 787faf2..9c97c98 100644 --- a/Guflow.Tests/Decider/DeflowAlgorithmTests.cs +++ b/Guflow.Tests/Decider/DeflowAlgorithmTests.cs @@ -75,7 +75,7 @@ public void Schedule_a_child_item_when_all_of_its_parent_branches_are_not_active var decisions = new TestWorkflow().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()) })); } [Test] @@ -102,7 +102,7 @@ public void Schedule_a_child_item_when_all_its_parent_branches_are_not_active_be var decisions = new TestWorkflow().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()) })); } [Test] @@ -131,7 +131,7 @@ public void Schedule_the_child_item_when_one_of_its_immediate_parents_last_actio var decisions = new WorkflowHasImmediateParentWithIgnoreActionToKeepBranchInactive() .Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()) })); } [Test] @@ -157,7 +157,7 @@ public void Schedule_the_child_item_when_one_of_the_not_immediate_parents_last_a var decisions = new WorkflowHasStartingItemInBranchWithIgnoreActionToKeepBranchInactive().Decisions( _eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()) })); } [Test] @@ -190,8 +190,8 @@ public void Jumping_down_in_branch_after_the_joint_item_triggers_scheduling_of_j Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), - new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version)) + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), + new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version).ScheduleId()) })); } @@ -207,7 +207,7 @@ public void Does_not_trigger_scheduling_of_joint_item_when_jumping_without_trigg Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version)) + new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version).ScheduleId()) })); } @@ -223,7 +223,7 @@ public void Jumping_before_joint_item_does_not_trigger_scheduling_of_joint_item( Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChooseSeatActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChooseSeatActivity, Version).ScheduleId()), })); } @@ -239,7 +239,7 @@ public void Jumping_on_to_joint_item_does_not_trigger_duplicate_scheduling_of_jo Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), })); } @@ -254,7 +254,7 @@ public void Jump_down_after_joint_item_does_not_trigger_scheduling_of_joint_item Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version)), + new ScheduleActivityDecision(Identity.New(SendEmailActivity, Version).ScheduleId()), })); } @@ -270,7 +270,7 @@ public void By_default_trigger_first_joint_item_when_scheduling_condition_is_eva Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), })); } @@ -286,7 +286,7 @@ public void Manually_trigger_first_joint_item_when_scheduling_condition_is_evalu Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), })); } @@ -318,7 +318,7 @@ public void By_default_trigger_first_joint_item_when_scheduling_condition_is_eva Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), })); } @@ -334,7 +334,7 @@ public void Manually_trigger_first_joint_item_when_scheduling_condition_is_evalu Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)), + new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()), })); } @@ -385,7 +385,7 @@ public void Schedule_first_joint_item_when_the_branch_is_made_inactive_by_ignore var decisions = new WorkflowWithBranchBecomingInActiveByIgnoreAction().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version)) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New(ChargeCustomerActivity, Version).ScheduleId()) })); } [Test] @@ -424,7 +424,7 @@ public void Schedule_a_lambda_child_item_when_all_of_its_parent_branches_are_not var decisions = new LambdaWorkflow().Decisions(_eventsBuilder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda), "input") })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda).ScheduleId(), "input") })); } [Test] @@ -438,8 +438,8 @@ public void Schedule_first_joint_lambda_when_jumping_down_the_branch() Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda), "input"), - new ScheduleLambdaDecision(Identity.Lambda(SendEmailLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda).ScheduleId(), "input"), + new ScheduleLambdaDecision(Identity.Lambda(SendEmailLambda).ScheduleId(), "input"), })); } @@ -456,7 +456,7 @@ public void Schedule_the_first_join_lambda_when_schedule_condition_is_evalauated Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda).ScheduleId(), "input"), })); } @@ -470,7 +470,7 @@ public void Return_empty_decision_when_schedule_condition_is_evalauated_to_false Assert.That(decisions, Is.EquivalentTo(new[] { - new ScheduleLambdaDecision(Identity.Lambda(BookHotelLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(BookHotelLambda).ScheduleId(), "input"), })); } @@ -503,8 +503,8 @@ public void Schedule_the_first_joint_item_when_jumping_down_to_child_workflow() Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda), "input"), - new ScheduleChildWorkflowDecision(Identity.New(InvoiceCustomerWorkflow, Version),"input"), + new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda).ScheduleId(), "input"), + new ScheduleChildWorkflowDecision(Identity.New(InvoiceCustomerWorkflow, Version).ScheduleId(),"input"), })); } @@ -520,7 +520,7 @@ public void Trigger_the_scheduling_of_first_joint_item_when_child_workflow_when_ Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(ChargeCustomerLambda).ScheduleId(), "input"), })); } @@ -535,7 +535,7 @@ public void Does_not_trigger_the_scheduling_of_first_joint_item_when_child_workf Assert.That(decisions, Is.EquivalentTo(new WorkflowDecision[] { - new ScheduleLambdaDecision(Identity.Lambda(BookHotelLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(BookHotelLambda).ScheduleId(), "input"), })); } @@ -568,7 +568,7 @@ public void Does_not_schedule_joint_item_when_one_of_the_branch_remains_active_b Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] { - new ScheduleLambdaDecision(Identity.Lambda(BookFlightLambda), "input"), + new ScheduleLambdaDecision(Identity.Lambda(BookFlightLambda).ScheduleId(), "input"), })); } @@ -584,7 +584,7 @@ public void Does_not_schedule_joint_item_when_one_of_the_branch_remains_active_b Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] { - new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.Zero), + new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.Zero), })); } @@ -600,7 +600,7 @@ public void Does_not_schedule_joint_item_when_one_of_the_branch_remains_active_b Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] { - new ScheduleChildWorkflowDecision(Identity.New(BookFlightWorkflow, Version), "input"), + new ScheduleChildWorkflowDecision(Identity.New(BookFlightWorkflow, Version).ScheduleId(), "input"), })); } @@ -616,35 +616,35 @@ public void Does_not_schedule_joint_item_when_one_of_the_branch_remains_active_b Assert.That(decisions, Is.EqualTo(new [] { - new ScheduleActivityDecision(Identity.New(BookFlightActivity, Version)), + new ScheduleActivityDecision(Identity.New(BookFlightActivity, Version).ScheduleId()), })); } private HistoryEvent[] ActivityCompletedGraph(string activityName) { - return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, Version), "id", "result").ToArray(); + return _eventGraphBuilder.ActivityCompletedGraph(Identity.New(activityName, Version).ScheduleId(), "id", "result").ToArray(); } private HistoryEvent[] ActivityStartedGraph(string activityName) { - return _eventGraphBuilder.ActivityStartedGraph(Identity.New(activityName, Version), "id").ToArray(); + return _eventGraphBuilder.ActivityStartedGraph(Identity.New(activityName, Version).ScheduleId(), "id").ToArray(); } private HistoryEvent[] LambdaCompletedGraph(string lambdaName) { - return _eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(lambdaName), "id", "result").ToArray(); + return _eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(lambdaName).ScheduleId(), "id", "result").ToArray(); } private HistoryEvent[] LambdaStartedGraph(string lambdaName) { - return _eventGraphBuilder.LambdaStartedEventGraph(Identity.Lambda(lambdaName), "id").ToArray(); + return _eventGraphBuilder.LambdaStartedEventGraph(Identity.Lambda(lambdaName).ScheduleId(), "id").ToArray(); } private HistoryEvent[] TimerStartedGraph(Identity identity, bool isARescheduleTimer) { - return _eventGraphBuilder.TimerStartedGraph(identity, TimeSpan.Zero, isARescheduleTimer).ToArray(); + return _eventGraphBuilder.TimerStartedGraph(identity.ScheduleId(), TimeSpan.Zero, isARescheduleTimer).ToArray(); } private HistoryEvent[] ChildWorkflowCompletedGraph(string name, string version) { - return _eventGraphBuilder.ChildWorkflowCompletedGraph(Identity.New(name, version), "id","input" ,"result").ToArray(); + return _eventGraphBuilder.ChildWorkflowCompletedGraph(Identity.New(name, version).ScheduleId(), "id","input" ,"result").ToArray(); } [WorkflowDescription("1.0")] diff --git a/Guflow.Tests/Decider/EventGraphBuilder.cs b/Guflow.Tests/Decider/EventGraphBuilder.cs index 59249d1..07f944f 100644 --- a/Guflow.Tests/Decider/EventGraphBuilder.cs +++ b/Guflow.Tests/Decider/EventGraphBuilder.cs @@ -14,7 +14,7 @@ namespace Guflow.Tests.Decider internal class EventGraphBuilder { private long _currentEventId = 0; - public IEnumerable ActivityCompletedGraph(Identity activityIdentity, string workerIdentity, string result, string input = "") + public IEnumerable ActivityCompletedGraph(ScheduleId activityIdentity, string workerIdentity, string result, string input = "") { var historyEvents = new List(); var eventIds = EventIds.CompletedIds(ref _currentEventId); @@ -48,14 +48,14 @@ public IEnumerable ActivityCompletedGraph(Identity activityIdentit { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id, + ActivityId = activityIdentity, Input = input } }); return historyEvents; } - public IEnumerable ActivityFailedGraph(Identity activityIdentity, string identity, string reason, string detail) + public IEnumerable ActivityFailedGraph(ScheduleId activityIdentity, string identity, string reason, string detail) { var historyEvents = new List(); var eventIds = EventIds.FailedIds(ref _currentEventId); @@ -91,13 +91,13 @@ public IEnumerable ActivityFailedGraph(Identity activityIdentity, { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; } - public IEnumerable ActivityTimedoutGraph(Identity activityIdentity, string identity, string timeoutType, string detail) + public IEnumerable ActivityTimedoutGraph(ScheduleId activityIdentity, string identity, string timeoutType, string detail) { var historyEvents = new List(); var eventIds = EventIds.TimedoutIds(ref _currentEventId); @@ -133,13 +133,13 @@ public IEnumerable ActivityTimedoutGraph(Identity activityIdentity { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; } - public IEnumerable ActivityCancelledGraph(Identity activityIdentity, string identity, string detail) + public IEnumerable ActivityCancelledGraph(ScheduleId activityIdentity, string identity, string detail) { var historyEvents = new List(); var eventIds = EventIds.CancelledIds(ref _currentEventId); @@ -162,7 +162,7 @@ public IEnumerable ActivityCancelledGraph(Identity activityIdentit EventId = eventIds.EventId(EventIds.CancelRequested), ActivityTaskCancelRequestedEventAttributes = new ActivityTaskCancelRequestedEventAttributes() { - ActivityId = activityIdentity.Id, + ActivityId = activityIdentity } }); @@ -185,13 +185,13 @@ public IEnumerable ActivityCancelledGraph(Identity activityIdentit { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; } - public IEnumerable TimerFiredGraph(Identity timerId, TimeSpan startToFireTimeout, bool isARescheduleTimer = false) + public IEnumerable TimerFiredGraph(ScheduleId timerId, TimeSpan startToFireTimeout, bool isARescheduleTimer = false) { var historyEvents = new List(); var eventIds = EventIds.TimerFiredIds(ref _currentEventId); @@ -203,7 +203,7 @@ public IEnumerable TimerFiredGraph(Identity timerId, TimeSpan star TimerFiredEventAttributes = new TimerFiredEventAttributes() { StartedEventId = eventIds.EventId(EventIds.Started), - TimerId = timerId.Id + TimerId = timerId }, }); @@ -213,7 +213,7 @@ public IEnumerable TimerFiredGraph(Identity timerId, TimeSpan star EventId = eventIds.EventId(EventIds.Started), TimerStartedEventAttributes = new TimerStartedEventAttributes() { - TimerId = timerId.Id, + TimerId = timerId, StartToFireTimeout = ((long)startToFireTimeout.TotalSeconds).ToString(), Control = (new TimerScheduleData() { TimerName = timerId.Name, IsARescheduleTimer = isARescheduleTimer }).ToJson() } @@ -221,7 +221,7 @@ public IEnumerable TimerFiredGraph(Identity timerId, TimeSpan star return historyEvents; } - public IEnumerable TimerCancelledGraph(Identity timerId, TimeSpan startToFireTimeout, bool isARescheduleTimer = false) + public IEnumerable TimerCancelledGraph(ScheduleId timerId, TimeSpan startToFireTimeout, bool isARescheduleTimer = false) { var historyEvents = new List(); var eventIds = EventIds.TimerCancelledIds(ref _currentEventId); @@ -233,7 +233,7 @@ public IEnumerable TimerCancelledGraph(Identity timerId, TimeSpan TimerCanceledEventAttributes = new TimerCanceledEventAttributes() { StartedEventId = eventIds.EventId(EventIds.Started), - TimerId = timerId.Id, + TimerId = timerId, }, }); @@ -243,7 +243,7 @@ public IEnumerable TimerCancelledGraph(Identity timerId, TimeSpan EventId = eventIds.EventId(EventIds.Started), TimerStartedEventAttributes = new TimerStartedEventAttributes() { - TimerId = timerId.Id, + TimerId = timerId, StartToFireTimeout = ((long)startToFireTimeout.TotalSeconds).ToString(), Control = (new TimerScheduleData() { TimerName = timerId.Name, IsARescheduleTimer = isARescheduleTimer }).ToJson() } @@ -252,7 +252,7 @@ public IEnumerable TimerCancelledGraph(Identity timerId, TimeSpan return historyEvents; } - public IEnumerable TimerStartFailedGraph(Identity timerId, string cause) + public IEnumerable TimerStartFailedGraph(ScheduleId timerId, string cause) { var historyEvents = new List(); var eventIds = EventIds.TimerStartFailedIds(ref _currentEventId); @@ -263,7 +263,7 @@ public IEnumerable TimerStartFailedGraph(Identity timerId, string EventId = eventIds.EventId(EventIds.Failed), StartTimerFailedEventAttributes = new StartTimerFailedEventAttributes() { - TimerId = timerId.Id, + TimerId = timerId, Cause = cause }, }); @@ -297,7 +297,7 @@ public HistoryEvent WorkflowStartedEvent(object input = null) } }; } - public IEnumerable ActivityCancellationFailedGraph(Identity activityId, string cause) + public IEnumerable ActivityCancellationFailedGraph(ScheduleId activityId, string cause) { var historyEvents = new List(); var eventIds = EventIds.CompletedIds(ref _currentEventId); @@ -309,7 +309,7 @@ public IEnumerable ActivityCancellationFailedGraph(Identity activi EventId = eventIds.EventId(EventIds.Completion), RequestCancelActivityTaskFailedEventAttributes = new RequestCancelActivityTaskFailedEventAttributes() { - ActivityId = activityId.Id, + ActivityId = activityId, Cause = cause } }); @@ -332,16 +332,16 @@ public IEnumerable ActivityCancellationFailedGraph(Identity activi ActivityTaskScheduledEventAttributes = new ActivityTaskScheduledEventAttributes() { ActivityType = new ActivityType() { Name = activityId.Name, Version = activityId.Version }, - ActivityId = activityId.Id, + ActivityId = activityId, Control = (new ScheduleData() { PN = activityId.PositionalName }).ToJson(), } }); return historyEvents; } - public IEnumerable TimerCancellationFailedGraph(Identity timerId, string cause) + public IEnumerable TimerCancellationFailedGraph(ScheduleId timerId, string cause) { var historyEvents = new List(); - var eventIds = EventIds.CancellationFailedIds(ref _currentEventId); + var eventIds = EventIds.TimerCancellationFailedIds(ref _currentEventId); historyEvents.Add(new HistoryEvent() { @@ -349,26 +349,14 @@ public IEnumerable TimerCancellationFailedGraph(Identity timerId, EventId = eventIds.EventId(EventIds.Failed), CancelTimerFailedEventAttributes = new CancelTimerFailedEventAttributes() { - TimerId = timerId.Id, + TimerId = timerId, Cause = cause } }); - - historyEvents.Add(new HistoryEvent() - { - EventType = EventType.TimerStarted, - EventId = eventIds.EventId(EventIds.Started), - TimerStartedEventAttributes = new TimerStartedEventAttributes() - { - TimerId = timerId.Id, - StartToFireTimeout = ((long)20).ToString(), - Control = (new TimerScheduleData() { TimerName = timerId.Name, IsARescheduleTimer = false }).ToJson() - } - }); return historyEvents; } - public IEnumerable TimerStartedGraph(Identity identity, TimeSpan fireAfter, bool isARescheduleTimer = false) + public IEnumerable TimerStartedGraph(ScheduleId identity, TimeSpan fireAfter, bool isARescheduleTimer = false) { var historyEvents = new List(); var eventIds = EventIds.TimerStartedIds(ref _currentEventId); @@ -379,7 +367,7 @@ public IEnumerable TimerStartedGraph(Identity identity, TimeSpan f EventId = eventIds.EventId(EventIds.Started), TimerStartedEventAttributes = new TimerStartedEventAttributes() { - TimerId = identity.Id, + TimerId = identity, StartToFireTimeout = ((long)fireAfter.TotalSeconds).ToString(), Control = (new TimerScheduleData() { TimerName = identity.Name, IsARescheduleTimer = isARescheduleTimer }).ToJson() } @@ -388,7 +376,7 @@ public IEnumerable TimerStartedGraph(Identity identity, TimeSpan f return historyEvents; } - public IEnumerable ActivitySchedulingFailedGraph(Identity activityIdentity, string cause) + public IEnumerable ActivitySchedulingFailedGraph(ScheduleId activityIdentity, string cause) { var historyEvents = new List(); var eventIds = EventIds.SchedulingFailedIds(ref _currentEventId); @@ -399,7 +387,7 @@ public IEnumerable ActivitySchedulingFailedGraph(Identity activity EventId = eventIds.EventId(EventIds.Failed), ScheduleActivityTaskFailedEventAttributes = new ScheduleActivityTaskFailedEventAttributes() { - ActivityId = activityIdentity.Id, + ActivityId = activityIdentity, ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Cause = cause } @@ -408,7 +396,7 @@ public IEnumerable ActivitySchedulingFailedGraph(Identity activity return historyEvents; } - public IEnumerable ActivityScheduledGraph(Identity activityIdentity) + public IEnumerable ActivityScheduledGraph(ScheduleId activityIdentity) { var historyEvents = new List(); var eventIds = EventIds.ScheduledIds(ref _currentEventId); @@ -421,14 +409,14 @@ public IEnumerable ActivityScheduledGraph(Identity activityIdentit { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; } - public IEnumerable ActivityStartedGraph(Identity activityIdentity, string identity) + public IEnumerable ActivityStartedGraph(ScheduleId activityIdentity, string identity) { var historyEvents = new List(); var eventIds = EventIds.StartedIds(ref _currentEventId); @@ -452,13 +440,13 @@ public IEnumerable ActivityStartedGraph(Identity activityIdentity, { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; } - public IEnumerable ActivityCancelRequestedGraph(Identity activityIdentity, string identity) + public IEnumerable ActivityCancelRequestedGraph(ScheduleId activityIdentity, string identity) { var historyEvents = new List(); var eventIds = EventIds.ActivityCancelRequestedIds(ref _currentEventId); @@ -469,7 +457,7 @@ public IEnumerable ActivityCancelRequestedGraph(Identity activityI EventId = eventIds.EventId(EventIds.CancelRequested), ActivityTaskCancelRequestedEventAttributes = new ActivityTaskCancelRequestedEventAttributes() { - ActivityId = activityIdentity.Id, + ActivityId = activityIdentity, } }); @@ -492,7 +480,7 @@ public IEnumerable ActivityCancelRequestedGraph(Identity activityI { ActivityType = new ActivityType() { Name = activityIdentity.Name, Version = activityIdentity.Version }, Control = (new ScheduleData() { PN = activityIdentity.PositionalName }).ToJson(), - ActivityId = activityIdentity.Id + ActivityId = activityIdentity } }); return historyEvents; @@ -634,7 +622,7 @@ public HistoryEvent WorkflowFailureFailedEvent(string cause) } }; } - public IEnumerable ExternalWorkflowCancelRequestFailedEvent(Identity identity, string runid, string cause) + public IEnumerable ExternalWorkflowCancelRequestFailedEvent(ScheduleId id, string runid, string cause) { var events = new List(); var eventIds = EventIds.WorkflowCancelRequestFailedIds(ref _currentEventId); @@ -644,7 +632,7 @@ public IEnumerable ExternalWorkflowCancelRequestFailedEvent(Identi EventType = EventType.RequestCancelExternalWorkflowExecutionFailed, RequestCancelExternalWorkflowExecutionFailedEventAttributes = new RequestCancelExternalWorkflowExecutionFailedEventAttributes() { - WorkflowId = identity.Id, + WorkflowId = id, RunId = runid, Cause = cause, InitiatedEventId = eventIds.EventId(EventIds.CancelInitiated) @@ -657,7 +645,7 @@ public IEnumerable ExternalWorkflowCancelRequestFailedEvent(Identi EventType = EventType.RequestCancelExternalWorkflowExecutionInitiated, RequestCancelExternalWorkflowExecutionInitiatedEventAttributes = new RequestCancelExternalWorkflowExecutionInitiatedEventAttributes() { - WorkflowId = identity.Id, + WorkflowId = id, RunId = runid, } }); @@ -678,7 +666,7 @@ public HistoryEvent WorkflowCancellationFailedEvent(string cause) }; } - public IEnumerable LambdaCompletedEventGraph(Identity identity, object input, object result, TimeSpan? startToClose = null) + public IEnumerable LambdaCompletedEventGraph(ScheduleId identity, object input, object result, TimeSpan? startToClose = null) { var historyEvents = new List(); var eventIds = EventIds.CompletedIds(ref _currentEventId); @@ -712,7 +700,7 @@ public IEnumerable LambdaCompletedEventGraph(Identity identity, ob LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), StartToCloseTimeout = startToClose.Seconds() @@ -722,7 +710,7 @@ public IEnumerable LambdaCompletedEventGraph(Identity identity, ob return historyEvents; } - public IEnumerable LambdaFailedEventGraph(Identity identity, object input, string reason, string details, TimeSpan? timeout = null) + public IEnumerable LambdaFailedEventGraph(ScheduleId identity, object input, string reason, string details, TimeSpan? timeout = null) { var historyEvents = new List(); var eventIds = EventIds.FailedIds(ref _currentEventId); @@ -757,7 +745,7 @@ public IEnumerable LambdaFailedEventGraph(Identity identity, objec LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), StartToCloseTimeout = timeout.Seconds() @@ -767,7 +755,7 @@ public IEnumerable LambdaFailedEventGraph(Identity identity, objec return historyEvents; } - public IEnumerable LamdbaTimedoutEventGraph(Identity identity, object input, string timedoutType, TimeSpan? timeout = null) + public IEnumerable LamdbaTimedoutEventGraph(ScheduleId identity, object input, string timedoutType, TimeSpan? timeout = null) { var historyEvents = new List(); var eventIds = EventIds.TimedoutIds(ref _currentEventId); @@ -801,7 +789,7 @@ public IEnumerable LamdbaTimedoutEventGraph(Identity identity, obj LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), StartToCloseTimeout = timeout.Seconds() @@ -811,7 +799,7 @@ public IEnumerable LamdbaTimedoutEventGraph(Identity identity, obj return historyEvents; } - public HistoryEvent LambdaSchedulingFailedEventGraph(Identity identity, string reason) + public HistoryEvent LambdaSchedulingFailedEventGraph(ScheduleId identity, string reason) { var eventIds = EventIds.SchedulingFailedIds(ref _currentEventId); return new HistoryEvent() @@ -820,14 +808,14 @@ public HistoryEvent LambdaSchedulingFailedEventGraph(Identity identity, string r EventType = EventType.ScheduleLambdaFunctionFailed, ScheduleLambdaFunctionFailedEventAttributes = new ScheduleLambdaFunctionFailedEventAttributes { - Id = identity.Id, + Id = identity, Name = identity.Name, Cause = reason } }; } - public IEnumerable LambdaStartFailedEventGraph(Identity identity, string input, string cause, string message, TimeSpan? timeout = null) + public IEnumerable LambdaStartFailedEventGraph(ScheduleId identity, string input, string cause, string message, TimeSpan? timeout = null) { var historyEvents = new List(); var eventIds = EventIds.LambdaStartFailedIds(ref _currentEventId); @@ -850,7 +838,7 @@ public IEnumerable LambdaStartFailedEventGraph(Identity identity, LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), StartToCloseTimeout = timeout.Seconds() @@ -860,7 +848,7 @@ public IEnumerable LambdaStartFailedEventGraph(Identity identity, return historyEvents; } - public HistoryEvent LambdaScheduledEventGraph(Identity identity, object input, TimeSpan? timeout = null) + public HistoryEvent LambdaScheduledEventGraph(ScheduleId identity, object input, TimeSpan? timeout = null) { var eventIds = EventIds.ScheduledIds(ref _currentEventId); return new HistoryEvent() @@ -869,7 +857,7 @@ public HistoryEvent LambdaScheduledEventGraph(Identity identity, object input, T EventType = EventType.LambdaFunctionScheduled, LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes { - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), @@ -878,7 +866,7 @@ public HistoryEvent LambdaScheduledEventGraph(Identity identity, object input, T }; } - public IEnumerable LambdaStartedEventGraph(Identity identity, object input, TimeSpan? timeout = null) + public IEnumerable LambdaStartedEventGraph(ScheduleId identity, object input, TimeSpan? timeout = null) { var historyEvents = new List(); var eventIds = EventIds.StartedIds(ref _currentEventId); @@ -899,7 +887,7 @@ public IEnumerable LambdaStartedEventGraph(Identity identity, obje LambdaFunctionScheduledEventAttributes = new LambdaFunctionScheduledEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - Id = identity.Id, + Id = identity, Name = identity.Name, Input = input.ToAwsString(), StartToCloseTimeout = timeout.Seconds() @@ -910,11 +898,11 @@ public IEnumerable LambdaStartedEventGraph(Identity identity, obje } - public IEnumerable ChildWorkflowCompletedGraph(Identity identity, string runId, object input, object result) + public IEnumerable ChildWorkflowCompletedGraph(ScheduleId identity, string runId, object input, object result) { var historyEvents = new List(); var eventIds = EventIds.CompletedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -950,7 +938,7 @@ public IEnumerable ChildWorkflowCompletedGraph(Identity identity, StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -966,11 +954,11 @@ public IEnumerable ChildWorkflowCompletedGraph(Identity identity, } - public IEnumerable ChildWorkflowFailedEventGraph(Identity identity, string runId, object input, string reason, object details) + public IEnumerable ChildWorkflowFailedEventGraph(ScheduleId identity, string runId, object input, string reason, object details) { var historyEvents = new List(); var eventIds = EventIds.FailedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -1007,7 +995,7 @@ public IEnumerable ChildWorkflowFailedEventGraph(Identity identity StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1022,11 +1010,11 @@ public IEnumerable ChildWorkflowFailedEventGraph(Identity identity return historyEvents; } - public IEnumerable ChildWorkflowCancelledEventGraph(Identity identity, string runId, object input, object details) + public IEnumerable ChildWorkflowCancelledEventGraph(ScheduleId identity, string runId, object input, object details) { var historyEvents = new List(); var eventIds = EventIds.ChildWorkflowCancelledIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -1084,7 +1072,7 @@ public IEnumerable ChildWorkflowCancelledEventGraph(Identity ident StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1099,11 +1087,11 @@ public IEnumerable ChildWorkflowCancelledEventGraph(Identity ident return historyEvents; } - public IEnumerable ChildWorkflowStartedEventGraph(Identity identity, string runId, object input) + public IEnumerable ChildWorkflowStartedEventGraph(ScheduleId identity, string runId, object input) { var historyEvents = new List(); var eventIds = EventIds.StartedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -1125,7 +1113,7 @@ public IEnumerable ChildWorkflowStartedEventGraph(Identity identit StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1141,11 +1129,11 @@ public IEnumerable ChildWorkflowStartedEventGraph(Identity identit } - public IEnumerable ChildWorkflowTerminatedEventGraph(Identity identity, string runId, object input) + public IEnumerable ChildWorkflowTerminatedEventGraph(ScheduleId identity, string runId, object input) { var historyEvents = new List(); var eventIds = EventIds.CompletedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -1180,7 +1168,7 @@ public IEnumerable ChildWorkflowTerminatedEventGraph(Identity iden StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1195,11 +1183,11 @@ public IEnumerable ChildWorkflowTerminatedEventGraph(Identity iden return historyEvents; } - public IEnumerable ChildWorkflowTimedoutEventGraph(Identity identity, string runId, object input, string timedoutType) + public IEnumerable ChildWorkflowTimedoutEventGraph(ScheduleId identity, string runId, object input, string timedoutType) { var historyEvents = new List(); var eventIds = EventIds.TimedoutIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() { @@ -1235,7 +1223,7 @@ public IEnumerable ChildWorkflowTimedoutEventGraph(Identity identi StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1250,7 +1238,7 @@ public IEnumerable ChildWorkflowTimedoutEventGraph(Identity identi return historyEvents; } - public IEnumerable ChildWorkflowStartFailedEventGraph(Identity identity, object input, string cause) + public IEnumerable ChildWorkflowStartFailedEventGraph(ScheduleId identity, object input, string cause) { var historyEvents = new List(); var eventIds = EventIds.ChildWorkflowStartFailed(ref _currentEventId); @@ -1274,7 +1262,7 @@ public IEnumerable ChildWorkflowStartFailedEventGraph(Identity ide StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1289,11 +1277,11 @@ public IEnumerable ChildWorkflowStartFailedEventGraph(Identity ide return historyEvents; } - public IEnumerable ChildWorkflowCancellationRequestedEventGraph(Identity identity, string runId, string input) + public IEnumerable ChildWorkflowCancellationRequestedEventGraph(ScheduleId identity, string runId, string input) { var historyEvents = new List(); var eventIds = EventIds.WorkflowCancelRequestedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() @@ -1338,7 +1326,7 @@ public IEnumerable ChildWorkflowCancellationRequestedEventGraph(Id StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = input.ToAwsString(), LambdaRole = "lambda_role", @@ -1353,11 +1341,11 @@ public IEnumerable ChildWorkflowCancellationRequestedEventGraph(Id return historyEvents; } - public IEnumerable ChildWorkflowCancelRequestFailedEventGraph(Identity identity, string runId, string cause) + public IEnumerable ChildWorkflowCancelRequestFailedEventGraph(ScheduleId identity, string runId, string cause) { var historyEvents = new List(); var eventIds = EventIds.ChildWorkflowCancelRequestFailedIds(ref _currentEventId); - var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity.Id }; + var workflowExecution = new WorkflowExecution() { RunId = runId, WorkflowId = identity }; var workflowType = new WorkflowType() { Name = identity.Name, Version = identity.Version }; historyEvents.Add(new HistoryEvent() @@ -1404,7 +1392,7 @@ public IEnumerable ChildWorkflowCancelRequestFailedEventGraph(Iden StartChildWorkflowExecutionInitiatedEventAttributes = new StartChildWorkflowExecutionInitiatedEventAttributes() { Control = (new ScheduleData() { PN = identity.PositionalName }).ToJson(), - WorkflowId = identity.Id, + WorkflowId = identity, WorkflowType = workflowType, Input = "input", LambdaRole = "lambda_role", @@ -1556,14 +1544,13 @@ public static EventIds LambdaStartFailedIds(ref long eventId) return new EventIds(ids); } - public static EventIds CancellationFailedIds(ref long eventId) + public static EventIds TimerCancellationFailedIds(ref long eventId) { - const long totalEvents = 2; + const long totalEvents = 1; eventId += totalEvents; var ids = new Dictionary() { {Failed, eventId}, - {Started, eventId-1}, }; return new EventIds(ids); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaCompletedEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaCompletedEventTests.cs index afc6755..c6a0cb0 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaCompletedEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaCompletedEventTests.cs @@ -1,6 +1,7 @@ //Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root folder for license information. using System; +using System.Collections.Generic; using System.Linq; using Amazon.SimpleWorkflow.Model; using Guflow.Decider; @@ -11,15 +12,19 @@ namespace Guflow.Tests.Decider [TestFixture] public class LambdaCompletedEventTests { - private EventGraphBuilder _builder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; private LambdaCompletedEvent _event; - + private IEnumerable _eventGraph; + private const string LambdaName = "lambda_name"; + private const string PositionalName = "pos_name"; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaCompletedEventGraph(Identity.Lambda("lambda_name", "pos_name"), "input", "result", TimeSpan.FromSeconds(10)); - _event = new LambdaCompletedEvent(eventGraph.First(), eventGraph); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _eventGraph = _graphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName, PositionalName).ScheduleId(), "input", "result", TimeSpan.FromSeconds(10)); + _event = new LambdaCompletedEvent(_eventGraph.First(), _eventGraph); } [Test] @@ -33,16 +38,19 @@ public void Properties_are_populated_from_history_event() [Test] public void Throws_exception_when_lambda_scheduled_event_not_found() { - var eventGraph = _builder.LambdaCompletedEventGraph(Identity.Lambda("lambda_name"), "input", "result", TimeSpan.FromSeconds(10)); + var eventGraph = _graphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "result", TimeSpan.FromSeconds(10)); Assert.Throws(()=>_event = new LambdaCompletedEvent(eventGraph.First(), Enumerable.Empty())); } [Test] public void Schedule_children() { - var decisions = _event.Interpret(new WorkflowWithLambda()).Decisions(); + const string runId = "runid"; + _builder.AddWorkflowRunId(runId); + _builder.AddNewEvents(_eventGraph.ToArray()); + var decisions = new WorkflowWithLambda().Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer("timer_name"), TimeSpan.Zero) })); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer("timer_name").ScheduleId(), TimeSpan.Zero) })); } [Test] @@ -57,9 +65,9 @@ private class WorkflowWithLambda : Workflow { public WorkflowWithLambda() { - ScheduleLambda("lambda_name", "pos_name"); + ScheduleLambda(LambdaName, PositionalName); - ScheduleTimer("timer_name").AfterLambda("lambda_name", "pos_name"); + ScheduleTimer("timer_name").AfterLambda(LambdaName, PositionalName); } } @@ -67,9 +75,9 @@ private class WorkflowWithCustomAction : Workflow { public WorkflowWithCustomAction(WorkflowAction action) { - ScheduleLambda("lambda_name", "pos_name").OnCompletion(e=>action); + ScheduleLambda(LambdaName, PositionalName).OnCompletion(e=>action); - ScheduleTimer("timer_name").AfterLambda("lambda_name", "pos_name"); + ScheduleTimer("timer_name").AfterLambda(LambdaName, PositionalName); } } } diff --git a/Guflow.Tests/Decider/Lambda/LambdaFailedEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaFailedEventTests.cs index f7cdc8b..dd8a65c 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaFailedEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaFailedEventTests.cs @@ -17,7 +17,7 @@ public class LambdaFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("lambda_name"), "input", "reason", "details"); + var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "input", "reason", "details"); _event = new LambdaFailedEvent(eventGraph.First(), eventGraph); } @@ -50,7 +50,7 @@ public void Can_return_custom_action() [Test] public void Throws_exception_when_lamdba_is_not_found_for_failed_event() { - var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("differnt_name"), "input", "reason", "details"); + var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("differnt_name").ScheduleId(), "input", "reason", "details"); var @event = new LambdaFailedEvent(eventGraph.First(), eventGraph); Assert.Throws(()=> @event.Interpret(new WorkflowWithLambda())); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaItemExtensionTests.cs b/Guflow.Tests/Decider/Lambda/LambdaItemExtensionTests.cs index 376f8ed..2e7fd5a 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaItemExtensionTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaItemExtensionTests.cs @@ -131,18 +131,18 @@ public void Null_argument_tests() private LambdaCompletedEvent CompletedEvent(string result) { - var graph = _builder.LambdaCompletedEventGraph(Identity.Lambda("lambda"), "input", result); + var graph = _builder.LambdaCompletedEventGraph(Identity.Lambda("lambda").ScheduleId(), "input", result); return new LambdaCompletedEvent(graph.First(), graph); } private LambdaFailedEvent FailedEvent(string reason, string details) { - var graph = _builder.LambdaFailedEventGraph(Identity.Lambda("lambda"), "input", reason,details); + var graph = _builder.LambdaFailedEventGraph(Identity.Lambda("lambda").ScheduleId(), "input", reason,details); return new LambdaFailedEvent(graph.First(), graph); } private LambdaTimedoutEvent TimedoutEvent(string timeoutType) { - var graph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("lambda"), "input", timeoutType); + var graph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("lambda").ScheduleId(), "input", timeoutType); return new LambdaTimedoutEvent(graph.First(), graph); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaItemTests.cs b/Guflow.Tests/Decider/Lambda/LambdaItemTests.cs index 7b90f3d..ed5f4a2 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaItemTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaItemTests.cs @@ -16,6 +16,7 @@ public class LambdaItemTests private EventGraphBuilder _builder; private Mock _workflow; private Identity _lambdaIdentity; + private ScheduleId _scheduleId; private const string LambdaName = "lambda"; [SetUp] public void Setup() @@ -25,6 +26,7 @@ public void Setup() _workflow.SetupGet(w => w.WorkflowHistoryEvents) .Returns(new WorkflowHistoryEvents(_builder.WorkflowStartedGraph())); _lambdaIdentity = Identity.Lambda(LambdaName); + _scheduleId = _lambdaIdentity.ScheduleId(); } [Test] public void By_default_lambda_function_is_scheduled_with_workflow_input() @@ -139,14 +141,14 @@ public void Reschedule_decision_is_a_timer_decision_for_lambda_item() { var lambdaItem = new LambdaItem(_lambdaIdentity, _workflow.Object); var decision = lambdaItem.RescheduleDecisions(TimeSpan.FromSeconds(10)); - Assert.That(decision, Is.EqualTo(new []{new ScheduleTimerDecision(_lambdaIdentity, TimeSpan.FromSeconds(10), true)})); + Assert.That(decision, Is.EqualTo(new []{new ScheduleTimerDecision(_lambdaIdentity.ScheduleId(), TimeSpan.FromSeconds(10), true)})); } [Test] public void All_events_can_return_lamdba_completed_event() { var eventGraph = - _builder.LambdaCompletedEventGraph(_lambdaIdentity, "input", "result", TimeSpan.FromSeconds(2)); + _builder.LambdaCompletedEventGraph(_scheduleId, "input", "result", TimeSpan.FromSeconds(2)); var lamdbaItem = CreateLambdaItem(eventGraph); var allEvents = lamdbaItem.AllEvents(true); @@ -158,7 +160,7 @@ public void All_events_can_return_lamdba_completed_event() public void All_events_can_return_lamdba_failed_event() { var eventGraph = - _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); + _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); var lamdbaItem = CreateLambdaItem(eventGraph); var allEvents = lamdbaItem.AllEvents(true); @@ -169,7 +171,7 @@ public void All_events_can_return_lamdba_failed_event() [Test] public void All_events_can_return_lamdba_timedout_event() { - var eventGraph = _builder.LamdbaTimedoutEventGraph(_lambdaIdentity, "input", "reason"); + var eventGraph = _builder.LamdbaTimedoutEventGraph(_scheduleId, "input", "reason"); var lamdbaItem = CreateLambdaItem(eventGraph); var allEvents = lamdbaItem.AllEvents(true); @@ -180,7 +182,7 @@ public void All_events_can_return_lamdba_timedout_event() [Test] public void All_events_can_return_lamdba_started_event() { - var eventGraph = _builder.LambdaStartedEventGraph(_lambdaIdentity, "input"); + var eventGraph = _builder.LambdaStartedEventGraph(_scheduleId, "input"); var lamdbaItem = CreateLambdaItem(eventGraph); var allEvents = lamdbaItem.AllEvents(true); @@ -191,7 +193,7 @@ public void All_events_can_return_lamdba_started_event() [Test] public void All_events_can_return_lamdba_start_failed_event() { - var eventGraph = _builder.LambdaStartFailedEventGraph(_lambdaIdentity, "input", "reason", "msg"); + var eventGraph = _builder.LambdaStartFailedEventGraph(_scheduleId, "input", "reason", "msg"); var lamdbaItem = CreateLambdaItem(eventGraph); var allEvents = lamdbaItem.AllEvents(true); @@ -202,7 +204,7 @@ public void All_events_can_return_lamdba_start_failed_event() [Test] public void All_events_can_return_lamdba_scheduled_event() { - var eventGraph = _builder.LambdaScheduledEventGraph(_lambdaIdentity, "input"); + var eventGraph = _builder.LambdaScheduledEventGraph(_scheduleId, "input"); var lamdbaItem = CreateLambdaItem(new[]{eventGraph}); var allEvents = lamdbaItem.AllEvents(true); @@ -213,7 +215,7 @@ public void All_events_can_return_lamdba_scheduled_event() [Test] public void All_events_can_return_lamdba_scheduling_failed_event() { - var eventGraph = _builder.LambdaSchedulingFailedEventGraph(_lambdaIdentity, "reason"); + var eventGraph = _builder.LambdaSchedulingFailedEventGraph(_scheduleId, "reason"); var lamdbaItem = CreateLambdaItem(new[] { eventGraph }); var allEvents = lamdbaItem.AllEvents(true); @@ -224,8 +226,8 @@ public void All_events_can_return_lamdba_scheduling_failed_event() [Test] public void All_events_does_not_return_events_for_other_lambda_item() { - var eventGraph = _builder.LambdaCompletedEventGraph(_lambdaIdentity, "input", "result", TimeSpan.FromSeconds(1)); - var otherLambdaEvent = _builder.LambdaCompletedEventGraph(Identity.Lambda("other"), "input", "result", TimeSpan.FromSeconds(1)); + var eventGraph = _builder.LambdaCompletedEventGraph(_scheduleId, "input", "result", TimeSpan.FromSeconds(1)); + var otherLambdaEvent = _builder.LambdaCompletedEventGraph(Identity.Lambda("other").ScheduleId(), "input", "result", TimeSpan.FromSeconds(1)); var lamdbaItem = CreateLambdaItem(eventGraph.Concat(otherLambdaEvent)); var allEvents = lamdbaItem.AllEvents(true); @@ -236,8 +238,8 @@ public void All_events_does_not_return_events_for_other_lambda_item() [Test] public void All_events_can_return_multiple_independent_events_for_same_lambda_event() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var startedEventGraph = _builder.LambdaStartedEventGraph(_lambdaIdentity, "input"); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var startedEventGraph = _builder.LambdaStartedEventGraph(_scheduleId, "input"); var allEvents = startedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -253,8 +255,8 @@ public void All_events_can_return_multiple_independent_events_for_same_lambda_ev [Test] public void All_events_can_return_reschedule_timer_events() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity, TimeSpan.FromSeconds(1), true); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity.ScheduleId(), TimeSpan.FromSeconds(1), true); var allEvents = startedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -270,8 +272,8 @@ public void All_events_can_return_reschedule_timer_events() [Test] public void All_events_by_default_filters_out_reschedule_timer_events() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity, TimeSpan.FromSeconds(1), true); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity.ScheduleId(), TimeSpan.FromSeconds(1), true); var allEvents = startedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -286,8 +288,8 @@ public void All_events_by_default_filters_out_reschedule_timer_events() [Test] public void Last_event_returns_latest_event_of_lambda_item() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var completedEventGraph = _builder.LambdaCompletedEventGraph(_lambdaIdentity, "input", "result"); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var completedEventGraph = _builder.LambdaCompletedEventGraph(_scheduleId, "input", "result"); var allEvents = completedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -299,8 +301,8 @@ public void Last_event_returns_latest_event_of_lambda_item() [Test] public void Last_event_can_return_event_for_rescheduled_timer() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity, TimeSpan.FromSeconds(1), true); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity.ScheduleId(), TimeSpan.FromSeconds(1), true); var allEvents = startedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -312,8 +314,8 @@ public void Last_event_can_return_event_for_rescheduled_timer() [Test] public void Last_event_by_default_filters_out_rescheduled_timer() { - var failedEventGraph = _builder.LambdaFailedEventGraph(_lambdaIdentity, "input", "reason", "details"); - var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity, TimeSpan.FromSeconds(1), true); + var failedEventGraph = _builder.LambdaFailedEventGraph(_scheduleId, "input", "reason", "details"); + var startedEventGraph = _builder.TimerStartedGraph(_lambdaIdentity.ScheduleId(), TimeSpan.FromSeconds(1), true); var allEvents = startedEventGraph.Concat(failedEventGraph); var lamdbaItem = CreateLambdaItem(allEvents); @@ -322,10 +324,22 @@ public void Last_event_by_default_filters_out_rescheduled_timer() Assert.That(lastEvent, Is.EqualTo(new LambdaFailedEvent(failedEventGraph.First(), failedEventGraph))); } + [Test] + public void Last_event_filters_outs_lambda_scheduling_failed_event() + { + var started = _builder.LambdaStartedEventGraph(_scheduleId, "input", TimeSpan.FromSeconds(1)); + var failed = new[]{_builder.LambdaSchedulingFailedEventGraph(_scheduleId, "reason")}; + var lamdbaItem = CreateLambdaItem(failed.Concat(started)); + + var lastEvent = lamdbaItem.LastEvent(); + + Assert.That(lastEvent, Is.EqualTo(new LambdaStartedEvent(started.First(), started))); + } + [Test] public void Last_event_is_cached() { - var eventGraph = _builder.LambdaCompletedEventGraph(_lambdaIdentity, "input", "result"); + var eventGraph = _builder.LambdaCompletedEventGraph(_scheduleId, "input", "result"); var lamdbaItem = CreateLambdaItem(eventGraph); Assert.IsTrue(ReferenceEquals(lamdbaItem.LastEvent(true), lamdbaItem.LastEvent(true))); diff --git a/Guflow.Tests/Decider/Lambda/LambdaScheduleTests.cs b/Guflow.Tests/Decider/Lambda/LambdaScheduleTests.cs index e379ce7..c57e15b 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaScheduleTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaScheduleTests.cs @@ -36,7 +36,7 @@ public void Lambda_can_be_scheduled_after_activity() var eventGraph = ActivityEventGraph(); var decision = new LambdaAfterActivityWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new []{new ScheduleLambdaDecision(Identity.Lambda(LambdaName),"input")})); + Assert.That(decision, Is.EqualTo(new []{new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input")})); } [Test] @@ -45,7 +45,7 @@ public void Lambda_can_be_scheduled_after_timer() var eventGraph = TimerCompletedEventGraph(); var decision = new LambdaAfterTimerWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] @@ -54,7 +54,7 @@ public void Lambda_can_be_scheduled_after_lambda() var eventGraph = LambdaCompletedEventGraph(); var decision = new LambdaAfterLambdaWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } @@ -64,7 +64,7 @@ public void Lambda_can_be_scheduled_after_child_workflow() var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new LambdaAfterChildWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] @@ -73,13 +73,13 @@ public void Lambda_can_be_scheduled_after_child_workflow_using_generic_type_api( var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new LambdaAfterChildWorkflowUsingGenericApi().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } private WorkflowHistoryEvents ActivityEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents( _eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion), "id", + _eventsBuilder.AddNewEvents( _eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "res").ToArray()); return _eventsBuilder.Result(); } @@ -87,14 +87,14 @@ private WorkflowHistoryEvents ActivityEventGraph() private WorkflowHistoryEvents TimerCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.FromSeconds(2)).ToArray()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(2)).ToArray()); return _eventsBuilder.Result(); } private WorkflowHistoryEvents LambdaCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(ParentLambdaName),"input", "result").ToArray()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(ParentLambdaName).ScheduleId(),"input", "result").ToArray()); return _eventsBuilder.Result(); } @@ -103,7 +103,7 @@ private WorkflowHistoryEvents ChildWorkflowCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion), "rid", "input", + .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleId(), "rid", "input", "result") .ToArray()); return _eventsBuilder.Result(); diff --git a/Guflow.Tests/Decider/Lambda/LambdaScheduledEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaScheduledEventTests.cs index 23b5871..9cf9fcf 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaScheduledEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaScheduledEventTests.cs @@ -17,7 +17,7 @@ public class LambdaScheduledEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaScheduledEventGraph(Identity.Lambda("lambda_name"), "input", TimeSpan.FromSeconds(10)); + var eventGraph = _builder.LambdaScheduledEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "input", TimeSpan.FromSeconds(10)); _event = new LambdaScheduledEvent(eventGraph); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaSchedulingFailedEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaSchedulingFailedEventTests.cs index e3ae048..e31d0e6 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaSchedulingFailedEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaSchedulingFailedEventTests.cs @@ -15,7 +15,7 @@ public class LambdaSchedulingFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaSchedulingFailedEventGraph(Identity.Lambda("lambda_name"), "reason"); + var eventGraph = _builder.LambdaSchedulingFailedEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "reason"); _event = new LambdaSchedulingFailedEvent(eventGraph); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaStartFailedEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaStartFailedEventTests.cs index b0a8d19..c2db715 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaStartFailedEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaStartFailedEventTests.cs @@ -17,7 +17,7 @@ public class LambdaStartFailedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaStartFailedEventGraph(Identity.Lambda("lambda_name"), "input", "reason", "message", TimeSpan.FromSeconds(10)); + var eventGraph = _builder.LambdaStartFailedEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "input", "reason", "message", TimeSpan.FromSeconds(10)); _event = new LambdaStartFailedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaStartedEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaStartedEventTests.cs index 868745b..38a9654 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaStartedEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaStartedEventTests.cs @@ -18,7 +18,7 @@ public class LambdaStartedEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LambdaStartedEventGraph(Identity.Lambda("lambda_name"), "input", TimeSpan.FromSeconds(10)); + var eventGraph = _builder.LambdaStartedEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "input", TimeSpan.FromSeconds(10)); _event = new LambdaStartedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/Lambda/LambdaTimedoutEventTests.cs b/Guflow.Tests/Decider/Lambda/LambdaTimedoutEventTests.cs index b10b2ce..f48d555 100644 --- a/Guflow.Tests/Decider/Lambda/LambdaTimedoutEventTests.cs +++ b/Guflow.Tests/Decider/Lambda/LambdaTimedoutEventTests.cs @@ -16,7 +16,7 @@ public class LambdaTimedoutEventTests public void Setup() { _builder = new EventGraphBuilder(); - var eventGraph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("lambda_name"), "input", "reason"); + var eventGraph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("lambda_name").ScheduleId(), "input", "reason"); _event = new LambdaTimedoutEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/Lambda/ScheduleLambdaDecisionTests.cs b/Guflow.Tests/Decider/Lambda/ScheduleLambdaDecisionTests.cs index 7283b4c..39204ce 100644 --- a/Guflow.Tests/Decider/Lambda/ScheduleLambdaDecisionTests.cs +++ b/Guflow.Tests/Decider/Lambda/ScheduleLambdaDecisionTests.cs @@ -13,16 +13,16 @@ public class ScheduleLambdaDecisionTests [Test] public void Equality() { - Assert.IsTrue(new ScheduleLambdaDecision(Identity.Lambda("lambda"), "input1").Equals(new ScheduleLambdaDecision(Identity.Lambda("lambda"), "input2"))); + Assert.IsTrue(new ScheduleLambdaDecision(Identity.Lambda("lambda").ScheduleId(), "input1").Equals(new ScheduleLambdaDecision(Identity.Lambda("lambda").ScheduleId(), "input2"))); - Assert.IsFalse(new ScheduleLambdaDecision(Identity.Lambda("lambda1"), "input").Equals(new ScheduleLambdaDecision(Identity.Lambda("lambda"), "input"))); - Assert.IsFalse(new ScheduleLambdaDecision(Identity.Lambda("lambda1"), "input").Equals(null)); + Assert.IsFalse(new ScheduleLambdaDecision(Identity.Lambda("lambda1").ScheduleId(), "input").Equals(new ScheduleLambdaDecision(Identity.Lambda("lambda").ScheduleId(), "input"))); + Assert.IsFalse(new ScheduleLambdaDecision(Identity.Lambda("lambda1").ScheduleId(), "input").Equals(null)); } [Test] public void Return_swf_decision_to_schedule_lambda() { - var identity = Identity.Lambda("lambda", "pos_name"); + var identity = Identity.Lambda("lambda", "pos_name").ScheduleId(); var decision = new ScheduleLambdaDecision(identity, "input", TimeSpan.FromSeconds(2)); var awsDecision = decision.SwfDecision(); @@ -31,14 +31,14 @@ public void Return_swf_decision_to_schedule_lambda() Assert.That(attr.Name, Is.EqualTo("lambda")); Assert.That(attr.Input, Is.EqualTo("\"input\"")); Assert.That(attr.StartToCloseTimeout, Is.EqualTo("2")); - Assert.That(attr.Id, Is.EqualTo(identity.Id.ToString())); + Assert.That(attr.Id, Is.EqualTo(identity.ToString())); Assert.That(attr.Control.As().PN, Is.EqualTo("pos_name")); } [Test] public void Return_swf_decision_without_input_and_timeout() { - var identity = Identity.Lambda("lambda"); + var identity = Identity.Lambda("lambda").ScheduleId(); var decision = new ScheduleLambdaDecision(identity, null, null); var awsDecision = decision.SwfDecision(); @@ -47,7 +47,7 @@ public void Return_swf_decision_without_input_and_timeout() Assert.That(attr.Name, Is.EqualTo("lambda")); Assert.That(attr.Input, Is.Null); Assert.That(attr.StartToCloseTimeout, Is.Null); - Assert.That(attr.Id, Is.EqualTo(identity.Id.ToString())); + Assert.That(attr.Id, Is.EqualTo(identity.ToString())); } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Signal/SignalTests.cs b/Guflow.Tests/Decider/Signal/SignalTests.cs index ea4cb52..c25d26a 100644 --- a/Guflow.Tests/Decider/Signal/SignalTests.cs +++ b/Guflow.Tests/Decider/Signal/SignalTests.cs @@ -55,42 +55,42 @@ public void Replying_to_a_signal_returns_signal_workflow_workflow() public void Signal_for_child_workflow() { var workflow = new SignalChildWorkflow(); - var identity = Identity.New(WorkflowName,WorkflowVersion).ScheduleIdentity(ParentWorkflowRunId); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion).ScheduleId(ParentWorkflowRunId); - _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(identity,"runid","input").ToArray()); - _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName),TimeSpan.Zero).ToArray()); + _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(scheduleId,"runid","input").ToArray()); + _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(),TimeSpan.Zero).ToArray()); var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, identity.Id, "runid") })); + Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, scheduleId, "runid") })); } [Test] public void Signal_for_child_workflow_using_generic_type_api() { var workflow = new SignalChildWorkflowUsingGenericTypeApi(); - var identity = Identity.New(WorkflowName, WorkflowVersion).ScheduleIdentity(ParentWorkflowRunId); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion).ScheduleId(ParentWorkflowRunId); - _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(identity, "runid", "input").ToArray()); - _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.Zero).ToArray()); + _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(scheduleId, "runid", "input").ToArray()); + _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.Zero).ToArray()); var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, identity.Id, "runid") })); + Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, scheduleId, "runid") })); } [Test] public void Signal_for_child_workflow_using_child_workflow_query_api() { var workflow = new SignalChildWorkflowUsingQueryApi(); - var identity = Identity.New(WorkflowName, WorkflowVersion).ScheduleIdentity(ParentWorkflowRunId); + var scheduleId = Identity.New(WorkflowName, WorkflowVersion).ScheduleId(ParentWorkflowRunId); - _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(identity, "runid", "input").ToArray()); - _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.Zero).ToArray()); + _builder.AddProcessedEvents(_eventGraphBuilder.ChildWorkflowStartedEventGraph(scheduleId, "runid", "input").ToArray()); + _builder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.Zero).ToArray()); var decisions = workflow.Decisions(_builder.Result()); - Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, identity.Id, "runid") })); + Assert.That(decisions, Is.EqualTo(new[] { new SignalWorkflowDecision(SignalName, SignalInput, scheduleId, "runid") })); } private class SignalChildWorkflow : Workflow diff --git a/Guflow.Tests/Decider/Signal/SignalWorkflowActionTests.cs b/Guflow.Tests/Decider/Signal/SignalWorkflowActionTests.cs index 3602e6d..48e1041 100644 --- a/Guflow.Tests/Decider/Signal/SignalWorkflowActionTests.cs +++ b/Guflow.Tests/Decider/Signal/SignalWorkflowActionTests.cs @@ -9,21 +9,22 @@ namespace Guflow.Tests.Decider [TestFixture] public class SignalWorkflowActionTests { - private EventGraphBuilder _builder; - + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); } [Test] public void Can_be_returned_as_custom_action_from_workflow() { var workflow = new WorkflowToReturnSignal("name","input","id","runid"); - var timerFiredEventGraph= _builder.TimerFiredGraph(Identity.Timer("timer1"), TimeSpan.FromSeconds(2)); - var timerEvent = new TimerFiredEvent(timerFiredEventGraph.First(),timerFiredEventGraph); + var timerFiredEventGraph= _graphBuilder.TimerFiredGraph(Identity.Timer("timer1").ScheduleId(), TimeSpan.FromSeconds(2)); + _builder.AddNewEvents(timerFiredEventGraph.ToArray()); - var decisions = timerEvent.Interpret(workflow).Decisions(); + var decisions = workflow.Decisions(_builder.Result()); Assert.That(decisions,Is.EqualTo(new []{new SignalWorkflowDecision("name","input","id","runid")})); } diff --git a/Guflow.Tests/Decider/Timer/CancelTimerDecisionTests.cs b/Guflow.Tests/Decider/Timer/CancelTimerDecisionTests.cs index 731672c..66df9ce 100644 --- a/Guflow.Tests/Decider/Timer/CancelTimerDecisionTests.cs +++ b/Guflow.Tests/Decider/Timer/CancelTimerDecisionTests.cs @@ -12,21 +12,21 @@ public class CancelTimerDecisionTests [Test] public void Equality_tests() { - Assert.IsTrue(new CancelTimerDecision(Identity.Timer("timer")).Equals(new CancelTimerDecision(Identity.Timer("timer")))); + Assert.IsTrue(new CancelTimerDecision(Identity.Timer("timer").ScheduleId()).Equals(new CancelTimerDecision(Identity.Timer("timer").ScheduleId()))); - Assert.IsFalse(new CancelTimerDecision(Identity.Timer("timer")).Equals(new CancelTimerDecision(Identity.Timer("timer1")))); + Assert.IsFalse(new CancelTimerDecision(Identity.Timer("timer").ScheduleId()).Equals(new CancelTimerDecision(Identity.Timer("timer1").ScheduleId()))); } [Test] public void Should_return_aws_decision_to_cancel_timer() { - var timerIdentity = Identity.Timer("timer"); - var cancelTimerDecision = new CancelTimerDecision(timerIdentity); + var scheduleId = Identity.Timer("timer").ScheduleId(); + var cancelTimerDecision = new CancelTimerDecision(scheduleId); Decision swfDecision = cancelTimerDecision.SwfDecision(); Assert.That(swfDecision.DecisionType,Is.EqualTo(DecisionType.CancelTimer)); - Assert.That(swfDecision.CancelTimerDecisionAttributes.TimerId,Is.EqualTo(timerIdentity.Id.ToString())); + Assert.That(swfDecision.CancelTimerDecisionAttributes.TimerId,Is.EqualTo(scheduleId.ToString())); } } } \ No newline at end of file diff --git a/Guflow.Tests/Decider/Timer/ScheduleTimerDecisionTests.cs b/Guflow.Tests/Decider/Timer/ScheduleTimerDecisionTests.cs index fee8071..e371943 100644 --- a/Guflow.Tests/Decider/Timer/ScheduleTimerDecisionTests.cs +++ b/Guflow.Tests/Decider/Timer/ScheduleTimerDecisionTests.cs @@ -12,23 +12,23 @@ public class ScheduleTimerDecisionTests [Test] public void Equality_tests() { - Assert.IsTrue(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), true))); + Assert.IsTrue(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), true))); - Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), false))); - Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(3), true))); - Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer1"), TimeSpan.FromSeconds(2), true))); + Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), false))); + Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(3), true))); + Assert.IsFalse(new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2), true).Equals(new ScheduleTimerDecision(Identity.Timer("timer1").ScheduleId(), TimeSpan.FromSeconds(2), true))); } [Test] public void Should_return_aws_decision_to_schedule_timer() { - var timerIdentity = Identity.Timer("timer"); - var scheduleTimerDecision = new ScheduleTimerDecision(timerIdentity, TimeSpan.FromSeconds(2),true); + var scheduleId = Identity.Timer("timer").ScheduleId(); + var scheduleTimerDecision = new ScheduleTimerDecision(scheduleId, TimeSpan.FromSeconds(2),true); var swfDecision = scheduleTimerDecision.SwfDecision(); Assert.That(swfDecision.DecisionType,Is.EqualTo(DecisionType.StartTimer)); - Assert.That(swfDecision.StartTimerDecisionAttributes.TimerId,Is.EqualTo(timerIdentity.Id.ToString())); + Assert.That(swfDecision.StartTimerDecisionAttributes.TimerId,Is.EqualTo(scheduleId.ToString())); Assert.That(swfDecision.StartTimerDecisionAttributes.StartToFireTimeout,Is.EqualTo("2")); Assert.That(swfDecision.StartTimerDecisionAttributes.Control.As().IsARescheduleTimer, Is.EqualTo(true)); Assert.That(swfDecision.StartTimerDecisionAttributes.Control.As().TimerName, Is.EqualTo("timer")); @@ -38,7 +38,7 @@ public void Should_return_aws_decision_to_schedule_timer() public void Should_round_up_time_to_fire_duration() { - var scheduleTimerDecision = new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2.6), true); + var scheduleTimerDecision = new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2.6), true); var swfDecision = scheduleTimerDecision.SwfDecision(); @@ -50,7 +50,7 @@ public void Should_round_up_time_to_fire_duration() public void By_default_it_is_not_reschedulable_timer() { - var scheduleTimerDecision = new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2.6)); + var scheduleTimerDecision = new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2.6)); var swfDecision = scheduleTimerDecision.SwfDecision(); diff --git a/Guflow.Tests/Decider/Timer/TimerCancellationFailedEventTests.cs b/Guflow.Tests/Decider/Timer/TimerCancellationFailedEventTests.cs index 67ca988..24a349f 100644 --- a/Guflow.Tests/Decider/Timer/TimerCancellationFailedEventTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerCancellationFailedEventTests.cs @@ -19,12 +19,17 @@ public class TimerCancellationFailedEventTests private const string LambdaName = "Lambda"; private const string WorkflowName = "Workflow"; private const string WorkflowVersion = "1.0"; - private EventGraphBuilder _builder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; + private Identity _id; + [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); - _timerCancellationFailedEvent = CreateTimerCancellationFailedEvent(Identity.Timer(TimerName), Cause); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _id = Identity.Timer(TimerName); + _timerCancellationFailedEvent = CreateTimerCancellationFailedEvent(_id, Cause); } [Test] @@ -43,7 +48,8 @@ public void Throws_exception_when_timer_is_not_found() [Test] public void By_default_return_workflow_failed_action() { - var decisions = _timerCancellationFailedEvent.Interpret(new TestWorkflow()).Decisions(); + _builder.AddNewEvents(_graphBuilder.TimerCancellationFailedGraph(_id.ScheduleId(), Cause).ToArray()); + var decisions = new TestWorkflow().Decisions(_builder.Result()); Assert.That(decisions, Is.EqualTo(new []{new FailWorkflowDecision("TIMER_CANCELLATION_FAILED",Cause)})); } @@ -71,7 +77,7 @@ public void Fail_workflow_for_child_workflow_reschedule_timer() { const string workflowRunid = "rid"; var builder = new HistoryEventsBuilder().AddWorkflowRunId(workflowRunid); - builder.AddNewEvents(TimerCancellationFailedEventGrpah(Identity.New(WorkflowName, WorkflowVersion).ScheduleIdentity(workflowRunid), Cause)); + builder.AddNewEvents(TimerCancellationFailedEventGrpah(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(workflowRunid), Cause)); var decisions = new WorkflowWithChildWorkflow().Decisions(builder.Result()); @@ -81,20 +87,20 @@ public void Fail_workflow_for_child_workflow_reschedule_timer() [Test] public void Can_return_custom_workflow_action_from_workflow() { - var customAction = new Mock().Object; - var workflowAction = _timerCancellationFailedEvent.Interpret(new WorkflowWithCustomAction(customAction)); + _builder.AddNewEvents(_graphBuilder.TimerCancellationFailedGraph(_id.ScheduleId(), Cause).ToArray()); + var decisions = new WorkflowWithCustomAction("result").Decisions(_builder.Result()); - Assert.That(workflowAction, Is.EqualTo(customAction)); + Assert.That(decisions, Is.EqualTo(new []{new CompleteWorkflowDecision("result")})); } - private TimerCancellationFailedEvent CreateTimerCancellationFailedEvent(Identity identity, string cause) + private TimerCancellationFailedEvent CreateTimerCancellationFailedEvent(Identity id, string cause) { - var timerCancellationFailedEventGraph = _builder.TimerCancellationFailedGraph(identity, Cause); + var timerCancellationFailedEventGraph = _graphBuilder.TimerCancellationFailedGraph(id.ScheduleId(), Cause); return new TimerCancellationFailedEvent(timerCancellationFailedEventGraph.First()); } - private HistoryEvent[] TimerCancellationFailedEventGrpah(Identity identity, string cause) + private HistoryEvent[] TimerCancellationFailedEventGrpah(ScheduleId identity, string cause) { - return _builder.TimerCancellationFailedGraph(identity, Cause).ToArray(); + return _graphBuilder.TimerCancellationFailedGraph(identity, Cause).ToArray(); } private class TestWorkflow : Workflow { @@ -105,9 +111,9 @@ public TestWorkflow() } private class WorkflowWithCustomAction : Workflow { - public WorkflowWithCustomAction(WorkflowAction workflowAction) + public WorkflowWithCustomAction(string result) { - ScheduleTimer(TimerName).OnCancellationFailed(c => workflowAction); + ScheduleTimer(TimerName).OnCancellationFailed(c => CompleteWorkflow(result)); } } private class WorkflowWithActivity : Workflow diff --git a/Guflow.Tests/Decider/Timer/TimerCancelledEventTests.cs b/Guflow.Tests/Decider/Timer/TimerCancelledEventTests.cs index c43e2bf..2214783 100644 --- a/Guflow.Tests/Decider/Timer/TimerCancelledEventTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerCancelledEventTests.cs @@ -26,7 +26,7 @@ public void Should_not_be_active() } private TimerCancelledEvent CreateTimerCancelledEvent(Identity identity, TimeSpan fireAfter) { - var timerCancelledEventGraph = _builder.TimerCancelledGraph(identity, fireAfter); + var timerCancelledEventGraph = _builder.TimerCancelledGraph(identity.ScheduleId(), fireAfter); return new TimerCancelledEvent(timerCancelledEventGraph.First(),timerCancelledEventGraph); } } diff --git a/Guflow.Tests/Decider/Timer/TimerFiredEventTests.cs b/Guflow.Tests/Decider/Timer/TimerFiredEventTests.cs index aad7354..1ff3b73 100644 --- a/Guflow.Tests/Decider/Timer/TimerFiredEventTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerFiredEventTests.cs @@ -20,14 +20,19 @@ public class TimerFiredEventTests private const string WorkflowName = "Workflow"; private const string WorkflowVersion = "1.0"; private readonly TimeSpan _fireAfter = TimeSpan.FromSeconds(20); - private EventGraphBuilder _eventGraphBuilder; - private HistoryEventsBuilder _eventsBuilder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; + private Identity _identity; + [SetUp] public void Setup() { - _eventGraphBuilder = new EventGraphBuilder(); - _eventsBuilder = new HistoryEventsBuilder(); - _timerFiredEvent = CreateTimerFiredEvent(Identity.Timer(TimerName), _fireAfter); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent("input")); + _identity = Identity.Timer(TimerName); + + _timerFiredEvent = CreateTimerFiredEvent(_identity, _fireAfter); } [Test] @@ -46,76 +51,91 @@ public void Throws_exception_when_fired_timer_is_not_found_in_workflow() [Test] public void Throws_exception_when_timer_start_event_is_missing() { - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(Identity.Timer(TimerName), _fireAfter); + var timerFiredEventGraph = _graphBuilder.TimerFiredGraph(_identity.ScheduleId(), _fireAfter); Assert.Throws(()=> new TimerFiredEvent(timerFiredEventGraph.First(), timerFiredEventGraph.Where(h=>h.EventType!=EventType.TimerStarted))); } [Test] - public void By_default_return_continue_workflow_action() + public void By_default_schedule_children() + { + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(_identity.ScheduleId(), TimeSpan.Zero).ToArray()); + var workflow = new WorkflowWithTimer(); + + var decisions = workflow.Decisions(_builder.Result()); + + Assert.That(decisions,Is.EqualTo(new []{new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input")})); + } + + [Test] + public void Schedule_children_when_reset_timer_is_fired() { + const string runId = "runid"; + _builder.AddWorkflowRunId(runId); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(_identity.ScheduleId(runId+"Reset"), TimeSpan.Zero).ToArray()); var workflow = new WorkflowWithTimer(); - var workflowAction = _timerFiredEvent.Interpret(workflow); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(workflowAction,Is.EqualTo(WorkflowAction.ContinueWorkflow(TimerItem.New(Identity.Timer(TimerName),null)))); + Assert.That(decisions, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] public void Workflow_can_return_custom_action() { - var workflowAction = new Mock().Object; - var workflow = new WorkflowWithCustomAction(workflowAction); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(_identity.ScheduleId(), TimeSpan.Zero).ToArray()); + + var workflow = new WorkflowWithCompleteAction("result"); - var actualAction = _timerFiredEvent.Interpret(workflow); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(actualAction,Is.EqualTo(workflowAction)); + Assert.That(decisions,Is.EqualTo(new[]{new CompleteWorkflowDecision("result")})); } [Test] public void Returns_schedule_activity_decision_if_timer_is_fired_to_reschedule_an_activity_item() { var workflow = new SingleActivityWorkflow(); - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.New(ActivityName, ActivityVersion, PositionalName), _fireAfter, true).ToArray()); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent()); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId(), _fireAfter, true).ToArray()); - var workflowAction = workflow.Decisions(_eventsBuilder.Result()); + var workflowAction = workflow.Decisions(_builder.Result()); - Assert.That(workflowAction, Is.EqualTo(new []{new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName)) })); + Assert.That(workflowAction, Is.EqualTo(new []{new ScheduleActivityDecision(Identity.New(ActivityName, ActivityVersion, PositionalName).ScheduleId()) })); } [Test] public void Returns_schedule_timer_decision_if_timer_is_fired_to_reschedule_a_timer_item() { var workflow = new WorkflowWithTimer(); - var rescheduleTimer = CreateRescheduleTimerFiredEvent(Identity.Timer(TimerName), _fireAfter); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(_identity.ScheduleId(), _fireAfter, true).ToArray()); - var workflowAction = rescheduleTimer.Interpret(workflow).Decisions(); + var workflowAction = workflow.Decisions(_builder.Result()); - Assert.That(workflowAction, Is.EqualTo(new []{new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.Zero) })); + Assert.That(workflowAction, Is.EqualTo(new []{new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.Zero) })); } [Test] public void Returns_schedule_lambda_decision_if_timer_is_fired_to_reschedule_an_lambda_item() { var workflow = new SingleLambdaWorkflow(); - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.Lambda(LambdaName), _fireAfter, true).ToArray()); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent()); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(Identity.Lambda(LambdaName).ScheduleId(), _fireAfter, true).ToArray()); - var workflowAction = workflow.Decisions(_eventsBuilder.Result()); + var workflowAction = workflow.Decisions(_builder.Result()); - Assert.That(workflowAction, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName), "input") })); + Assert.That(workflowAction, Is.EqualTo(new[] { new ScheduleLambdaDecision(Identity.Lambda(LambdaName).ScheduleId(), "input") })); } [Test] public void Returns_schedule_child_workflow_decision_if_timer_is_fired_to_reschedule_a_child_workflow_item() { var workflow = new ChildWorkflow(); - _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.TimerFiredGraph(Identity.New(WorkflowName,WorkflowVersion), _fireAfter, true).ToArray()); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent()); + _builder.AddNewEvents(_graphBuilder.TimerFiredGraph(Identity.New(WorkflowName,WorkflowVersion).ScheduleId(), _fireAfter, true).ToArray()); - var workflowAction = workflow.Decisions(_eventsBuilder.Result()); + var workflowAction = workflow.Decisions(_builder.Result()); - Assert.That(workflowAction, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion), "input") })); + Assert.That(workflowAction, Is.EqualTo(new[] { new ScheduleChildWorkflowDecision(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "input") })); } [Test] @@ -129,13 +149,13 @@ public void Throws_exception_when_rescheduled_item_is_not_found_in_workflow() private TimerFiredEvent CreateTimerFiredEvent(Identity identity, TimeSpan fireAfter) { - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(identity, fireAfter); + var timerFiredEventGraph = _graphBuilder.TimerFiredGraph(identity.ScheduleId(), fireAfter); return new TimerFiredEvent(timerFiredEventGraph.First(), timerFiredEventGraph); } private TimerFiredEvent CreateRescheduleTimerFiredEvent(Identity identity, TimeSpan fireAfter) { - var timerFiredEventGraph = _eventGraphBuilder.TimerFiredGraph(identity, fireAfter, true); + var timerFiredEventGraph = _graphBuilder.TimerFiredGraph(identity.ScheduleId(), fireAfter, true); return new TimerFiredEvent(timerFiredEventGraph.First(), timerFiredEventGraph); } @@ -148,13 +168,14 @@ private class WorkflowWithTimer : Workflow public WorkflowWithTimer() { ScheduleTimer(TimerName); + ScheduleLambda(LambdaName).AfterTimer(TimerName); } } - private class WorkflowWithCustomAction : Workflow + private class WorkflowWithCompleteAction : Workflow { - public WorkflowWithCustomAction(WorkflowAction workflowAction) + public WorkflowWithCompleteAction(string result) { - ScheduleTimer(TimerName).OnFired(e => workflowAction); + ScheduleTimer(TimerName).OnFired(e => CompleteWorkflow(result)); } } private class SingleActivityWorkflow : Workflow diff --git a/Guflow.Tests/Decider/Timer/TimerItemTests.cs b/Guflow.Tests/Decider/Timer/TimerItemTests.cs index cc10473..f2645b1 100644 --- a/Guflow.Tests/Decider/Timer/TimerItemTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerItemTests.cs @@ -13,54 +13,70 @@ namespace Guflow.Tests.Decider public class TimerItemTests { private readonly Identity _timerIdentity = Identity.Timer("timerName"); - private EventGraphBuilder _builder; - + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; + private Mock _workflow; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _builder.AddProcessedEvents(_graphBuilder.WorkflowStartedEvent()); + _workflow = new Mock(); + _workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(_builder.Result()); } [Test] public void By_default_schedule_timer_to_fire_immediately() { - var timerItem = TimerItem.New(_timerIdentity,null); + var timerItem = TimerItem.New(_timerIdentity, _workflow.Object); var decision = timerItem.ScheduleDecisions(); - Assert.That(decision,Is.EqualTo(new []{new ScheduleTimerDecision(_timerIdentity,new TimeSpan())})); + Assert.That(decision,Is.EqualTo(new []{new ScheduleTimerDecision(_timerIdentity.ScheduleId(), new TimeSpan())})); } [Test] public void Can_be_configured_to_schedule_timer_to_fire_after_timeout() { - var timerItem = TimerItem.New(_timerIdentity, null); + var timerItem = TimerItem.New(_timerIdentity, _workflow.Object); timerItem.FireAfter(TimeSpan.FromSeconds(3)); var decision = timerItem.ScheduleDecisions(); - Assert.That(decision, Is.EqualTo(new []{new ScheduleTimerDecision(_timerIdentity, TimeSpan.FromSeconds(3))})); + Assert.That(decision, Is.EqualTo(new []{new ScheduleTimerDecision(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(3))})); } [Test] public void Can_be_configured_to_schedule_timer_to_fire_after_timeout_using_lambda() { - var timerItem = TimerItem.New(_timerIdentity, null); + var timerItem = TimerItem.New(_timerIdentity, _workflow.Object); timerItem.FireAfter(_=>TimeSpan.FromSeconds(4)); var decision = timerItem.ScheduleDecisions(); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(_timerIdentity, TimeSpan.FromSeconds(4)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(4)) })); } [Test] public void Fire_after_lambda_handler_override_the_fire_after_timeout() { - var timerItem = TimerItem.New(_timerIdentity, null); + var timerItem = TimerItem.New(_timerIdentity, _workflow.Object); timerItem.FireAfter(_ => TimeSpan.FromSeconds(3)).FireAfter(TimeSpan.FromSeconds(4)); var decision = timerItem.ScheduleDecisions(); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(_timerIdentity, TimeSpan.FromSeconds(3)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(3)) })); } + //[Test] + //public void Schedule_the_timer_with_schedule_id_of_last_event_when_it_already_scheduled() + //{ + // _builder.AddProcessedEvents(_graphBuilder.a) + // var timerItem = TimerItem.New(_timerIdentity, null); + + // var decision = timerItem.ScheduleDecisions(); + + // Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(_timerIdentity.ScheduleId(), new TimeSpan()) })); + //} + [Test] public void Return_empty_when_when_condition_is_evaluated_to_false() { @@ -75,7 +91,7 @@ public void Return_empty_when_when_condition_is_evaluated_to_false() [Test] public void Last_event_can_be_timer_started_event() { - var eventGraph = _builder.TimerStartedGraph(_timerIdentity, TimeSpan.FromSeconds(2)); + var eventGraph = _graphBuilder.TimerStartedGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(2)); var timerItem = CreateTimerItemFor(eventGraph); var latestEvent = timerItem.LastEvent(true); @@ -86,7 +102,7 @@ public void Last_event_can_be_timer_started_event() [Test] public void Last_event_is_cached() { - var eventGraph = _builder.TimerStartedGraph(_timerIdentity, TimeSpan.FromSeconds(2)); + var eventGraph = _graphBuilder.TimerStartedGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(2)); var timerItem = CreateTimerItemFor(eventGraph); var latestEvent = timerItem.LastEvent(true); @@ -97,7 +113,7 @@ public void Last_event_is_cached() [Test] public void Last_event_can_be_timer_fired_event() { - var eventGraph =_builder.TimerFiredGraph(_timerIdentity, TimeSpan.FromSeconds(2)); + var eventGraph =_graphBuilder.TimerFiredGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(2)); var timerItem = CreateTimerItemFor(eventGraph); var latestEvent = timerItem.LastEvent(true); @@ -106,20 +122,21 @@ public void Last_event_can_be_timer_fired_event() } [Test] - public void Last_event_can_be_timer_start_failed_event() + public void Last_event_filter_out_timer_start_failed_event() { - var eventGraph =_builder.TimerStartFailedGraph(_timerIdentity, "cause"); - var timerItem = CreateTimerItemFor(eventGraph); + var started = _graphBuilder.TimerStartedGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(1)); + var failed =_graphBuilder.TimerStartFailedGraph(_timerIdentity.ScheduleId(), "cause"); + var timerItem = CreateTimerItemFor(failed.Concat(started)); var latestEvent = timerItem.LastEvent(true); - Assert.That(latestEvent, Is.EqualTo(new TimerStartFailedEvent(eventGraph.First()))); + Assert.That(latestEvent, Is.EqualTo(new TimerStartedEvent(started.First(), started))); } [Test] public void Last_event_can_be_timer_cancelled_event() { - var eventGraph = _builder.TimerCancelledGraph(_timerIdentity, TimeSpan.FromSeconds(2)); + var eventGraph = _graphBuilder.TimerCancelledGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(2)); var timerItem = CreateTimerItemFor(eventGraph); var latestEvent = timerItem.LastEvent(true); @@ -128,35 +145,37 @@ public void Last_event_can_be_timer_cancelled_event() } [Test] - public void Last_event_can_be_timer_cancellation_failed_event() + public void Last_event_filters_out_timer_cancellation_failed_event() { - var eventGraph=_builder.TimerCancellationFailedGraph(_timerIdentity, "cause"); - var timerItem = CreateTimerItemFor(eventGraph); + var started = _graphBuilder.TimerStartedGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(1)); + var failed =_graphBuilder.TimerCancellationFailedGraph(_timerIdentity.ScheduleId(), "cause"); + var timerItem = CreateTimerItemFor(failed.Concat(started)); var latestEvent = timerItem.LastEvent(true); - Assert.That(latestEvent, Is.EqualTo(new TimerCancellationFailedEvent(eventGraph.First()))); + Assert.That(latestEvent, Is.EqualTo(new TimerStartedEvent(started.First(), started))); } [Test] public void All_events_can_be_timer_cancellation_failed_event_and_timer_started_event() { - var eventGraph = _builder.TimerCancellationFailedGraph(_timerIdentity, "cause").ToArray(); - var timerItem = CreateTimerItemFor(eventGraph); + var started = _graphBuilder.TimerStartedGraph(_timerIdentity.ScheduleId(), TimeSpan.Zero).ToArray(); + var failed = _graphBuilder.TimerCancellationFailedGraph(_timerIdentity.ScheduleId(), "cause").ToArray(); + var timerItem = CreateTimerItemFor(failed.Concat(started)); var allEvents = timerItem.AllEvents(true); Assert.That(allEvents, Is.EqualTo(new WorkflowItemEvent[] { - new TimerCancellationFailedEvent(eventGraph.First()), - new TimerStartedEvent(eventGraph.Skip(1).First(), eventGraph) + new TimerCancellationFailedEvent(failed.First()), + new TimerStartedEvent(started.First(), started) })); } [Test] public void All_events_can_return_timer_fired_events() { - var eventGraph = _builder.TimerFiredGraph(_timerIdentity, TimeSpan.FromSeconds(2)); + var eventGraph = _graphBuilder.TimerFiredGraph(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(2)); var timerItem = CreateTimerItemFor(eventGraph); var latestEvent = timerItem.AllEvents(true); diff --git a/Guflow.Tests/Decider/Timer/TimerItemsExtensionTests.cs b/Guflow.Tests/Decider/Timer/TimerItemsExtensionTests.cs index 4118450..54c1e73 100644 --- a/Guflow.Tests/Decider/Timer/TimerItemsExtensionTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerItemsExtensionTests.cs @@ -39,7 +39,7 @@ public void Invalid_argument_tests() [Test] public void IsFired_when_last_event_is_fired() { - var completedGraph = _eventGraphBuilder.TimerFiredGraph(Identity.Timer(Timer1), TimeSpan.Zero); + var completedGraph = _eventGraphBuilder.TimerFiredGraph(Identity.Timer(Timer1).ScheduleId(), TimeSpan.Zero); var timer = CreateTimerItemFor(completedGraph); Assert.IsTrue(timer.IsFired()); @@ -47,7 +47,7 @@ public void IsFired_when_last_event_is_fired() [Test] public void IsFired_when_last_event_is_started() { - var completedGraph = _eventGraphBuilder.TimerStartedGraph(Identity.Timer(Timer1), TimeSpan.Zero); + var completedGraph = _eventGraphBuilder.TimerStartedGraph(Identity.Timer(Timer1).ScheduleId(), TimeSpan.Zero); var timer = CreateTimerItemFor(completedGraph); Assert.IsFalse(timer.IsFired()); @@ -56,7 +56,7 @@ public void IsFired_when_last_event_is_started() [Test] public void IsCancelled_when_last_event_is_cancelled() { - var completedGraph = _eventGraphBuilder.TimerCancelledGraph(Identity.Timer(Timer1), TimeSpan.Zero); + var completedGraph = _eventGraphBuilder.TimerCancelledGraph(Identity.Timer(Timer1).ScheduleId(), TimeSpan.Zero); var timer = CreateTimerItemFor(completedGraph); Assert.IsTrue(timer.IsCancelled()); @@ -64,7 +64,7 @@ public void IsCancelled_when_last_event_is_cancelled() [Test] public void IsCancelled_when_last_event_is_started() { - var completedGraph = _eventGraphBuilder.TimerStartedGraph(Identity.Timer(Timer1), TimeSpan.Zero); + var completedGraph = _eventGraphBuilder.TimerStartedGraph(Identity.Timer(Timer1).ScheduleId(), TimeSpan.Zero); var timer = CreateTimerItemFor(completedGraph); Assert.IsFalse(timer.IsCancelled()); diff --git a/Guflow.Tests/Decider/Timer/TimerRescheduleTests.cs b/Guflow.Tests/Decider/Timer/TimerRescheduleTests.cs new file mode 100644 index 0000000..0d4a2ee --- /dev/null +++ b/Guflow.Tests/Decider/Timer/TimerRescheduleTests.cs @@ -0,0 +1,143 @@ +// /Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root folder for license information. + +using System; +using System.Linq; +using Guflow.Decider; +using NUnit.Framework; + +namespace Guflow.Tests.Decider +{ + [TestFixture] + public class TimerRescheduleTests + { + private const string TimerName = "Timer1"; + private const string LambdaName = "LambdaName"; + private const string ParentWorkflowRunId = "runid"; + private EventGraphBuilder _eventGraphBuilder; + private HistoryEventsBuilder _eventsBuilder; + [SetUp] + public void Setup() + { + _eventGraphBuilder = new EventGraphBuilder(); + _eventsBuilder = new HistoryEventsBuilder(); + } + + [Test] + public void Current_timer_is_cancelled_and_is_scheduled_with_new_scheduled_id_on_reset() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder + .TimerStartedGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromMinutes(4)).ToArray()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + var decisions = new TimerResetWorkflow().Decisions(_eventsBuilder.Result()); + + Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] + { + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()), + new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId+"Reset"), TimeSpan.FromMinutes(4)) + })); + } + + [Test] + public void Current_timer_is_cancelled_and_is_scheduled_with_new_scheduled_id_and_timeout_on_reschedule() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder + .TimerStartedGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromMinutes(4)).ToArray()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + var decisions = new TimerRescheduleWorkflow().Decisions(_eventsBuilder.Result()); + + Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] + { + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId()), + new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId+"Reset"), TimeSpan.FromMinutes(10)) + })); + } + + [Test] + public void Current_timer_is_cancelled_and_is_scheduled_with_flipped_scheduled_id_on_reset() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder + .TimerStartedGraph(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId + "Reset"), TimeSpan.FromMinutes(4)).ToArray()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + var decisions = new TimerResetWorkflow().Decisions(_eventsBuilder.Result()); + + Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] + { + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId + "Reset")), + new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromMinutes(4)) + })); + } + + [Test] + public void Current_timer_is_cancelled_and_is_scheduled_with_flipped_scheduled_id_and_timeout_on_reschedule() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder + .TimerStartedGraph(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId + "Reset"), TimeSpan.FromMinutes(4)).ToArray()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + var decisions = new TimerRescheduleWorkflow().Decisions(_eventsBuilder.Result()); + + Assert.That(decisions, Is.EqualTo(new WorkflowDecision[] + { + new CancelTimerDecision(Identity.Timer(TimerName).ScheduleId(ParentWorkflowRunId+"Reset")), + new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromMinutes(10)) + })); + } + + [Test] + public void Reset_throws_exception_when_timer_is_not_active() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + Assert.Throws(()=> new TimerResetWorkflow().Decisions(_eventsBuilder.Result())); + } + + [Test] + public void Resechedule_throws_exception_when_timer_is_not_active() + { + _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + _eventsBuilder.AddWorkflowRunId(ParentWorkflowRunId); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.WorkflowSignaledEvent("ChangeTimer", "")); + + Assert.Throws(() => new TimerRescheduleWorkflow().Decisions(_eventsBuilder.Result())); + } + + private class TimerResetWorkflow : Workflow + { + public TimerResetWorkflow() + { + ScheduleTimer(TimerName).FireAfter(TimeSpan.FromMinutes(2)); + + ScheduleLambda(LambdaName).AfterTimer(TimerName); + } + + [SignalEvent] + public WorkflowAction ChangeTimer() => Timer(TimerName).Reset(); + } + + private class TimerRescheduleWorkflow : Workflow + { + public TimerRescheduleWorkflow() + { + ScheduleTimer(TimerName).FireAfter(TimeSpan.FromMinutes(2)); + + ScheduleLambda(LambdaName).AfterTimer(TimerName); + } + + [SignalEvent] + public WorkflowAction ChangeTimer() => Timer(TimerName).Reschedule(TimeSpan.FromMinutes(10)); + } + } +} \ No newline at end of file diff --git a/Guflow.Tests/Decider/Timer/TimerScheduleTests.cs b/Guflow.Tests/Decider/Timer/TimerScheduleTests.cs index 7ef1657..5340403 100644 --- a/Guflow.Tests/Decider/Timer/TimerScheduleTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerScheduleTests.cs @@ -35,7 +35,7 @@ public void Timer_can_be_scheduled_after_activity() var eventGraph = ActivityEventGraph(); var decision = new TimerAfterActivityWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(0)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(0)) })); } [Test] @@ -44,7 +44,7 @@ public void Timer_can_be_scheduled_after_timer() var eventGraph = TimerCompletedEventGraph(); var decision = new TimerAfterTimerWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(0)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(0)) })); } [Test] @@ -53,7 +53,7 @@ public void Timer_can_be_scheduled_after_lambda() var eventGraph = LambdaCompletedEventGraph(); var decision = new TimerAfterLambdaWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(0)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(0)) })); } @@ -63,7 +63,7 @@ public void Timer_can_be_scheduled_after_child_workflow() var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new TimerAfterChildWorkflow().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(0)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(0)) })); } @@ -73,13 +73,13 @@ public void Timer_can_be_scheduled_after_child_workflow_using_generic_type_api() var eventGraph = ChildWorkflowCompletedEventGraph(); var decision = new TimerAfterChildWorkflowUsingGenericApi().Decisions(eventGraph); - Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName), TimeSpan.FromSeconds(0)) })); + Assert.That(decision, Is.EqualTo(new[] { new ScheduleTimerDecision(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(0)) })); } private WorkflowHistoryEvents ActivityEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion), "id", + _eventsBuilder.AddNewEvents(_eventGraphBuilder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "res").ToArray()); return _eventsBuilder.Result(); } @@ -88,7 +88,7 @@ private WorkflowHistoryEvents TimerCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .TimerFiredGraph(Identity.Timer(ParentTimerName), TimeSpan.FromSeconds(2)) + .TimerFiredGraph(Identity.Timer(ParentTimerName).ScheduleId(), TimeSpan.FromSeconds(2)) .ToArray()); return _eventsBuilder.Result(); } @@ -96,7 +96,7 @@ private WorkflowHistoryEvents TimerCompletedEventGraph() private WorkflowHistoryEvents LambdaCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); - _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName), "input", "result").ToArray()); + _eventsBuilder.AddNewEvents(_eventGraphBuilder.LambdaCompletedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input", "result").ToArray()); return _eventsBuilder.Result(); } @@ -104,7 +104,7 @@ private WorkflowHistoryEvents ChildWorkflowCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion), "rid", "input", + .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion).ScheduleId(), "rid", "input", "result") .ToArray()); return _eventsBuilder.Result(); diff --git a/Guflow.Tests/Decider/Timer/TimerStartFailedEventTests.cs b/Guflow.Tests/Decider/Timer/TimerStartFailedEventTests.cs index 0d60b80..a9e02e2 100644 --- a/Guflow.Tests/Decider/Timer/TimerStartFailedEventTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerStartFailedEventTests.cs @@ -19,14 +19,17 @@ public class TimerStartFailedEventTests private const string WorkflowName = "Workflow"; private const string WorkflowVersion = "1.0"; - private EventGraphBuilder _builder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; + private Identity _identity; [SetUp] public void Setup() { - _builder = new EventGraphBuilder(); - - _timerStartFailedEvent = CreateTimerStartFailedEvent(Identity.Timer(TimerName), TimerFailureCause); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); + _identity = Identity.Timer(TimerName); + _timerStartFailedEvent = CreateTimerStartFailedEvent(_identity, TimerFailureCause); } [Test] @@ -40,8 +43,8 @@ public void Should_populate_the_properties_from_history_event_attributes() public void By_default_returns_fail_workflow_decision() { var workflow = new WorkflowWithTimer(); - - var decisions = _timerStartFailedEvent.Interpret(workflow).Decisions(); + _builder.AddNewEvents(_graphBuilder.TimerStartFailedGraph(_identity.ScheduleId(), TimerFailureCause).ToArray()); + var decisions = workflow.Decisions(_builder.Result()); Assert.That(decisions, Is.EqualTo(new []{new FailWorkflowDecision("TIMER_START_FAILED", TimerFailureCause)})); } @@ -49,12 +52,12 @@ public void By_default_returns_fail_workflow_decision() [Test] public void Can_return_the_custom_action() { - var workflowAction = new Mock(); - var workflow = new WorkflowWithCustomAction(workflowAction.Object); + _builder.AddNewEvents(_graphBuilder.TimerStartFailedGraph(_identity.ScheduleId(), "cause").ToArray()); + var workflow = new WorkflowWithCustomAction("result"); - var action = _timerStartFailedEvent.Interpret(workflow); + var decisions = workflow.Decisions(_builder.Result()); - Assert.That(action,Is.EqualTo(workflowAction.Object)); + Assert.That(decisions,Is.EqualTo(new []{new CompleteWorkflowDecision("result")})); } [Test] @@ -83,7 +86,7 @@ public void Fail_workflow_for_lambda_reshedule_timer() public void Fail_workflow_for_child_workflow_reshedule_timer() { const string workflowRunid = "rid"; - var identity = Identity.New(WorkflowName, WorkflowVersion).ScheduleIdentity(workflowRunid); + var identity = Identity.New(WorkflowName, WorkflowVersion).ScheduleId(workflowRunid); var builder = new HistoryEventsBuilder().AddWorkflowRunId(workflowRunid); builder.AddNewEvents(TimerStartFailedEventGraph(identity, TimerFailureCause)); @@ -93,13 +96,13 @@ public void Fail_workflow_for_child_workflow_reshedule_timer() } private TimerStartFailedEvent CreateTimerStartFailedEvent(Identity timerIdentity, string cause) { - var timerFailedEventGraph = _builder.TimerStartFailedGraph(timerIdentity, cause); + var timerFailedEventGraph = _graphBuilder.TimerStartFailedGraph(timerIdentity.ScheduleId(), cause); return new TimerStartFailedEvent(timerFailedEventGraph.First()); } - private HistoryEvent[] TimerStartFailedEventGraph(Identity timerIdentity, string cause) + private HistoryEvent[] TimerStartFailedEventGraph(ScheduleId timerIdentity, string cause) { - return _builder.TimerStartFailedGraph(timerIdentity, cause).ToArray(); + return _graphBuilder.TimerStartFailedGraph(timerIdentity, cause).ToArray(); } private class WorkflowWithActivity : Workflow @@ -134,9 +137,9 @@ public WorkflowWithChildWorkflow() } private class WorkflowWithCustomAction : Workflow { - public WorkflowWithCustomAction(WorkflowAction workflowAction) + public WorkflowWithCustomAction(string result) { - ScheduleTimer(TimerName).OnStartFailed(e => workflowAction); + ScheduleTimer(TimerName).OnStartFailed(e => CompleteWorkflow(result)); } } } diff --git a/Guflow.Tests/Decider/Timer/TimerStartedEventTests.cs b/Guflow.Tests/Decider/Timer/TimerStartedEventTests.cs index 570fb17..7b915ff 100644 --- a/Guflow.Tests/Decider/Timer/TimerStartedEventTests.cs +++ b/Guflow.Tests/Decider/Timer/TimerStartedEventTests.cs @@ -36,7 +36,7 @@ public void Can_not_be_interpreted() private TimerStartedEvent CreateTimerStartedEvent(Identity identity, TimeSpan fireAfter) { - var timerFiredEventGraph = _builder.TimerStartedGraph(identity, fireAfter); + var timerFiredEventGraph = _builder.TimerStartedGraph(identity.ScheduleId(), fireAfter); return new TimerStartedEvent(timerFiredEventGraph.First(), timerFiredEventGraph); } } diff --git a/Guflow.Tests/Decider/WorkflowActionItemTests.cs b/Guflow.Tests/Decider/WorkflowActionItemTests.cs index d529a83..bf137ba 100644 --- a/Guflow.Tests/Decider/WorkflowActionItemTests.cs +++ b/Guflow.Tests/Decider/WorkflowActionItemTests.cs @@ -60,8 +60,9 @@ public void Invalid_arguments() private WorkflowHistoryEvents ChildWorkflowCompletedEventGraph() { _eventsBuilder.AddProcessedEvents(_eventGraphBuilder.WorkflowStartedEvent()); + var scheduleId = Identity.New(ChildWorkflowName, ChildWorkflowVersion, ChildWorkflowPosName).ScheduleId(); _eventsBuilder.AddNewEvents(_eventGraphBuilder - .ChildWorkflowCompletedGraph(Identity.New(ChildWorkflowName, ChildWorkflowVersion, ChildWorkflowPosName), "rid", "input", + .ChildWorkflowCompletedGraph(scheduleId, "rid", "input", "result") .ToArray()); return _eventsBuilder.Result(); diff --git a/Guflow.Tests/Decider/WorkflowHistoryEventsTests.cs b/Guflow.Tests/Decider/WorkflowHistoryEventsTests.cs index a8eb3b2..52edf96 100644 --- a/Guflow.Tests/Decider/WorkflowHistoryEventsTests.cs +++ b/Guflow.Tests/Decider/WorkflowHistoryEventsTests.cs @@ -178,7 +178,7 @@ public void Workflow_restart_failed_event_is_interpreted() [Test] public void External_workflow_cancel_request_failed_event_is_interpreted() { - var eventGraph = _builder.ExternalWorkflowCancelRequestFailedEvent(Identity.New("w","v"),"rid","cause"); + var eventGraph = _builder.ExternalWorkflowCancelRequestFailedEvent(Identity.New("w","v").ScheduleId(),"rid","cause"); var events = new WorkflowHistoryEvents(eventGraph ); var newEvents = events.NewEvents(); @@ -198,7 +198,7 @@ public void Workflow_cancellation_failed_event_is_interpreted() [Test] public void Lambda_function_completed_event_is_interpreted() { - var eventGraph = _builder.LambdaCompletedEventGraph(Identity.Lambda("l"), "input", "result").ToArray(); + var eventGraph = _builder.LambdaCompletedEventGraph(Identity.Lambda("l").ScheduleId(), "input", "result").ToArray(); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -208,7 +208,7 @@ public void Lambda_function_completed_event_is_interpreted() [Test] public void Lambda_function_failed_event_is_interpreted() { - var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("l"), "input", "reason", "details").ToArray(); + var eventGraph = _builder.LambdaFailedEventGraph(Identity.Lambda("l").ScheduleId(), "input", "reason", "details").ToArray(); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -218,7 +218,7 @@ public void Lambda_function_failed_event_is_interpreted() [Test] public void Lambda_function_timedout_event_is_interpreted() { - var eventGraph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("l"), "input", "reason").ToArray(); + var eventGraph = _builder.LamdbaTimedoutEventGraph(Identity.Lambda("l").ScheduleId(), "input", "reason").ToArray(); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -228,7 +228,7 @@ public void Lambda_function_timedout_event_is_interpreted() [Test] public void Lambda_function_scheduling_failed_event_is_interpreted() { - var eventGraph = new []{_builder.LambdaSchedulingFailedEventGraph(Identity.Lambda("l"), "reason")}; + var eventGraph = new []{_builder.LambdaSchedulingFailedEventGraph(Identity.Lambda("l").ScheduleId(), "reason")}; var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -238,7 +238,7 @@ public void Lambda_function_scheduling_failed_event_is_interpreted() [Test] public void Lambda_function_start_failed_event_is_interpreted() { - var eventGraph = _builder.LambdaStartFailedEventGraph(Identity.Lambda("l"), "input", "reason", "details"); + var eventGraph = _builder.LambdaStartFailedEventGraph(Identity.Lambda("l").ScheduleId(), "input", "reason", "details"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -248,7 +248,7 @@ public void Lambda_function_start_failed_event_is_interpreted() [Test] public void Child_workflow_completed_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowCompletedGraph(_childWorkflow, "rid","i","result"); + var eventGraph = _builder.ChildWorkflowCompletedGraph(_childWorkflow.ScheduleId(), "rid","i","result"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -258,7 +258,7 @@ public void Child_workflow_completed_event_is_interpreted() [Test] public void Child_workflow_failed_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowFailedEventGraph(_childWorkflow, "rid", "i", "reason", "details"); + var eventGraph = _builder.ChildWorkflowFailedEventGraph(_childWorkflow.ScheduleId(), "rid", "i", "reason", "details"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -268,7 +268,7 @@ public void Child_workflow_failed_event_is_interpreted() [Test] public void Child_workflow_cancelled_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowCancelledEventGraph(_childWorkflow, "rid", "i", "details"); + var eventGraph = _builder.ChildWorkflowCancelledEventGraph(_childWorkflow.ScheduleId(), "rid", "i", "details"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -278,7 +278,7 @@ public void Child_workflow_cancelled_event_is_interpreted() [Test] public void Child_workflow_timedout_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowTimedoutEventGraph(_childWorkflow, "rid", "i", "details"); + var eventGraph = _builder.ChildWorkflowTimedoutEventGraph(_childWorkflow.ScheduleId(), "rid", "i", "details"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -288,7 +288,7 @@ public void Child_workflow_timedout_event_is_interpreted() [Test] public void Child_workflow_terminated_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowTerminatedEventGraph(_childWorkflow, "rid", "i"); + var eventGraph = _builder.ChildWorkflowTerminatedEventGraph(_childWorkflow.ScheduleId(), "rid", "i"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -298,7 +298,7 @@ public void Child_workflow_terminated_event_is_interpreted() [Test] public void Child_workflow_start_failed_event_is_interpreted() { - var eventGraph = _builder.ChildWorkflowStartFailedEventGraph(_childWorkflow, "rid", "i"); + var eventGraph = _builder.ChildWorkflowStartFailedEventGraph(_childWorkflow.ScheduleId(), "rid", "i"); var events = new WorkflowHistoryEvents(eventGraph); var newEvents = events.NewEvents(); @@ -319,7 +319,7 @@ public void Non_interpretable_events_are_filtered_out() [Test] public void Should_be_active_when_activity_is_just_started() { - var activityStartedEventGraph = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion), "id"); + var activityStartedEventGraph = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id"); var workflowHistoryEvents = new WorkflowHistoryEvents(activityStartedEventGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -328,7 +328,7 @@ public void Should_be_active_when_activity_is_just_started() [Test] public void Should_be_active_when_activity_is_just_scheduled() { - var activityScheduledEventGraph = _builder.ActivityScheduledGraph(Identity.New(ActivityName, ActivityVersion)); + var activityScheduledEventGraph = _builder.ActivityScheduledGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId()); var workflowHistoryEvents = new WorkflowHistoryEvents(activityScheduledEventGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -337,7 +337,7 @@ public void Should_be_active_when_activity_is_just_scheduled() [Test] public void Should_be_active_when_activity_cancellation_is_in_progress() { - var activityCancelRequestedGraph = _builder.ActivityCancelRequestedGraph(Identity.New(ActivityName, ActivityVersion),"id"); + var activityCancelRequestedGraph = _builder.ActivityCancelRequestedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id"); var workflowHistoryEvents = new WorkflowHistoryEvents(activityCancelRequestedGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -347,7 +347,7 @@ public void Should_be_active_when_activity_cancellation_is_in_progress() [Test] public void Should_not_be_active_when_activity_is_cancelled() { - var cancelledGraph = _builder.ActivityCancelledGraph(Identity.New(ActivityName, ActivityVersion), "id", "details"); + var cancelledGraph = _builder.ActivityCancelledGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "details"); var workflowHistoryEvents = new WorkflowHistoryEvents(cancelledGraph); Assert.IsFalse(workflowHistoryEvents.HasActiveEvent()); @@ -356,7 +356,7 @@ public void Should_not_be_active_when_activity_is_cancelled() [Test] public void Should_not_be_active_when_activity_is_completed() { - var activityCompletedEventGraph =_builder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion), "id", "res"); + var activityCompletedEventGraph =_builder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "res"); var workflowHistoryEvents = new WorkflowHistoryEvents(activityCompletedEventGraph); Assert.IsFalse(workflowHistoryEvents.HasActiveEvent()); @@ -365,8 +365,8 @@ public void Should_not_be_active_when_activity_is_completed() [Test] public void Should_be_active_when_activity_is_just_started_after_failure() { - var eventGraph = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion), "id") - .Concat(_builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion), "id", "res","detail")); + var eventGraph = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id") + .Concat(_builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "res","detail")); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -375,8 +375,8 @@ public void Should_be_active_when_activity_is_just_started_after_failure() [Test] public void Should_be_active_when_activity_is_started_but_its_cancel_request_failed() { - var eventGraph = _builder.ActivityCancellationFailedGraph(Identity.New(ActivityName, ActivityVersion), "reason") - .Concat(_builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion), "id", "res", "detail")); + var eventGraph = _builder.ActivityCancellationFailedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "reason") + .Concat(_builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "res", "detail")); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -385,7 +385,7 @@ public void Should_be_active_when_activity_is_started_but_its_cancel_request_fai [Test] public void Should_not_be_active_when_child_workflow_is_cancelled() { - var eventGraph = _builder.ChildWorkflowCancelledEventGraph(Identity.New(WorkflowName, WorkflowVersion), + var eventGraph = _builder.ChildWorkflowCancelledEventGraph(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "rid", "input", "detail"); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); @@ -396,7 +396,7 @@ public void Should_not_be_active_when_child_workflow_is_cancelled() [Test] public void Should_be_active_when_child_workflow_is_started_and_its_cancellation_is_requested() { - var eventGraph = _builder.ChildWorkflowCancellationRequestedEventGraph(Identity.New(WorkflowName, WorkflowVersion), + var eventGraph = _builder.ChildWorkflowCancellationRequestedEventGraph(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "rid", "input"); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); @@ -408,8 +408,8 @@ public void Should_be_active_when_child_workflow_is_started_and_its_cancellation public void Should_be_active_when_child_workflow_is_started_and_its_cancel_request_is_failed() { var startedGraph = - _builder.ChildWorkflowStartedEventGraph(Identity.New(WorkflowName, WorkflowVersion), "rid", "input"); - var cancelFailedGraph = _builder.ExternalWorkflowCancelRequestFailedEvent(Identity.New(WorkflowName, WorkflowVersion), + _builder.ChildWorkflowStartedEventGraph(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "rid", "input"); + var cancelFailedGraph = _builder.ExternalWorkflowCancelRequestFailedEvent(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "rid", "input"); var workflowHistoryEvents = new WorkflowHistoryEvents(cancelFailedGraph.Concat(startedGraph)); @@ -420,7 +420,7 @@ public void Should_be_active_when_child_workflow_is_started_and_its_cancel_reque [Test] public void Should_not_be_active_when_child_workflow_is_completed() { - var eventGraph = _builder.ChildWorkflowCompletedGraph(Identity.New(WorkflowName, WorkflowVersion), + var eventGraph = _builder.ChildWorkflowCompletedGraph(Identity.New(WorkflowName, WorkflowVersion).ScheduleId(), "rid", "input", "detail"); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); @@ -431,7 +431,7 @@ public void Should_not_be_active_when_child_workflow_is_completed() [Test] public void Should_be_active_when_lambda_is_started() { - var eventGraph = _builder.LambdaStartedEventGraph(Identity.Lambda(LambdaName), "input"); + var eventGraph = _builder.LambdaStartedEventGraph(Identity.Lambda(LambdaName).ScheduleId(), "input"); var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph); @@ -441,7 +441,7 @@ public void Should_be_active_when_lambda_is_started() [Test] public void Should_be_active_when_timer_is_started() { - var timerStartedEventGraph = _builder.TimerStartedGraph(Identity.Timer("id"),TimeSpan.FromSeconds(2)); + var timerStartedEventGraph = _builder.TimerStartedGraph(Identity.Timer("id").ScheduleId(), TimeSpan.FromSeconds(2)); var workflowHistoryEvents = new WorkflowHistoryEvents(timerStartedEventGraph); Assert.IsTrue(workflowHistoryEvents.HasActiveEvent()); @@ -450,7 +450,7 @@ public void Should_be_active_when_timer_is_started() [Test] public void Should_not_be_active_when_timer_is_fired() { - var timerStartedEventGraph = _builder.TimerFiredGraph(Identity.Timer("id"), TimeSpan.FromSeconds(2)); + var timerStartedEventGraph = _builder.TimerFiredGraph(Identity.Timer("id").ScheduleId(), TimeSpan.FromSeconds(2)); var workflowHistoryEvents = new WorkflowHistoryEvents(timerStartedEventGraph); Assert.IsFalse(workflowHistoryEvents.HasActiveEvent()); @@ -502,7 +502,7 @@ public void Can_return_all_cancellation_request() [Test] public void Latest_event_id() { - var events = _builder.TimerFiredGraph(Identity.Timer("id"), TimeSpan.FromSeconds(2)); + var events = _builder.TimerFiredGraph(Identity.Timer("id").ScheduleId(), TimeSpan.FromSeconds(2)); var workflowHistoryEvents = new WorkflowHistoryEvents(events); Assert.That(workflowHistoryEvents.LatestEventId, Is.EqualTo(events.First().EventId)); @@ -510,23 +510,23 @@ public void Latest_event_id() private HistoryEvent[] ActivityCompletedEventGraph() { - return _builder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion), "id", "result").ToArray(); + return _builder.ActivityCompletedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "result").ToArray(); } private HistoryEvent [] ActivityFailedEventGraph() { - return _builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion), "id", "reason","detail").ToArray(); + return _builder.ActivityFailedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "reason","detail").ToArray(); } private HistoryEvent [] ActivityTimedoutEventGraph() { - return _builder.ActivityTimedoutGraph(Identity.New(ActivityName, ActivityVersion), "id", "reason", "detail").ToArray(); + return _builder.ActivityTimedoutGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "reason", "detail").ToArray(); } private HistoryEvent [] ActivityCancelledEventGraph() { - return _builder.ActivityCancelledGraph(Identity.New(ActivityName, ActivityVersion), "id", "detail").ToArray(); + return _builder.ActivityCancelledGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id", "detail").ToArray(); } private HistoryEvent [] ActivityCancellationFailedEventGraph() { - return _builder.ActivityCancellationFailedGraph(Identity.New(ActivityName, ActivityVersion), "detail").ToArray(); + return _builder.ActivityCancellationFailedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "detail").ToArray(); } private HistoryEvent [] WorkflowStartedEventGraph() { @@ -534,19 +534,19 @@ private HistoryEvent[] ActivityCompletedEventGraph() } private HistoryEvent [] TimerFiredEventGraph() { - return _builder.TimerFiredGraph(Identity.Timer(TimerName), TimeSpan.FromSeconds(4)).ToArray(); + return _builder.TimerFiredGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(4)).ToArray(); } private HistoryEvent [] TimerStartFailedEventGraph() { - return _builder.TimerStartFailedGraph(Identity.Timer(TimerName), "cause").ToArray(); + return _builder.TimerStartFailedGraph(Identity.Timer(TimerName).ScheduleId(), "cause").ToArray(); } private HistoryEvent [] TimerCancelledEventGraph() { - return _builder.TimerCancelledGraph(Identity.Timer(TimerName),TimeSpan.FromSeconds(4)).ToArray(); + return _builder.TimerCancelledGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(4)).ToArray(); } private HistoryEvent [] TimerCancellationFailedEventGraph() { - return _builder.TimerCancellationFailedGraph(Identity.Timer(TimerName), "cause").ToArray(); + return _builder.TimerCancellationFailedGraph(Identity.Timer(TimerName).ScheduleId(), "cause").ToArray(); } private HistoryEvent WorkflowSignaledEventGraph() { @@ -559,10 +559,10 @@ private HistoryEvent WorkflowCancellationRequestedEventGraph() private HistoryEvent [] NotInterpretingEventGraph() { var nonInterpretEvent = new[] {new HistoryEvent() {EventType = EventType.DecisionTaskCompleted}}; - var activityStarted = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion), "id"); - var activityScheduled = _builder.ActivityScheduledGraph(Identity.New(ActivityName, ActivityVersion)); - var timerStarted = _builder.TimerStartedGraph(Identity.Timer(TimerName), TimeSpan.FromSeconds(1)); - var childWorfklowStarted = _builder.ChildWorkflowStartedEventGraph(_childWorkflow, "rid", "input"); + var activityStarted = _builder.ActivityStartedGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId(), "id"); + var activityScheduled = _builder.ActivityScheduledGraph(Identity.New(ActivityName, ActivityVersion).ScheduleId()); + var timerStarted = _builder.TimerStartedGraph(Identity.Timer(TimerName).ScheduleId(), TimeSpan.FromSeconds(1)); + var childWorfklowStarted = _builder.ChildWorkflowStartedEventGraph(_childWorkflow.ScheduleId(), "rid", "input"); return timerStarted.Concat(activityScheduled) .Concat(activityStarted).Concat(nonInterpretEvent).Concat(childWorfklowStarted).ToArray(); } diff --git a/Guflow.Tests/Decider/WorkflowItemExtensionsTests.cs b/Guflow.Tests/Decider/WorkflowItemExtensionsTests.cs index 7321f0f..39f682a 100644 --- a/Guflow.Tests/Decider/WorkflowItemExtensionsTests.cs +++ b/Guflow.Tests/Decider/WorkflowItemExtensionsTests.cs @@ -157,14 +157,14 @@ public void Find_a_specific_parent_child_workflow_by_generic_type_api() private ActivityCompletedEvent CreateCompletedEvent() { - var eventGraph = _builder.ActivityCompletedGraph(Identity.New("name", "1.0"), "id", + var eventGraph = _builder.ActivityCompletedGraph(Identity.New("name", "1.0").ScheduleId(), "id", "result"); return new ActivityCompletedEvent(eventGraph.First(), eventGraph); } private ActivityFailedEvent CreateFailedEvent() { - var eventGraph = _builder.ActivityFailedGraph(Identity.New("name", "1.0"), "id","reason", "detail"); + var eventGraph = _builder.ActivityFailedGraph(Identity.New("name", "1.0").ScheduleId(), "id","reason", "detail"); return new ActivityFailedEvent(eventGraph.First(), eventGraph); } diff --git a/Guflow.Tests/Decider/WorkflowTests.cs b/Guflow.Tests/Decider/WorkflowTests.cs index aa4746c..46de31a 100644 --- a/Guflow.Tests/Decider/WorkflowTests.cs +++ b/Guflow.Tests/Decider/WorkflowTests.cs @@ -12,13 +12,15 @@ namespace Guflow.Tests.Decider public class WorkflowTests { private Mock _workflowEvents; - private EventGraphBuilder _eventGraphBuilder; + private EventGraphBuilder _graphBuilder; + private HistoryEventsBuilder _builder; private Workflow _workflow; [SetUp] public void Setup() { - _eventGraphBuilder = new EventGraphBuilder(); + _graphBuilder = new EventGraphBuilder(); + _builder = new HistoryEventsBuilder(); _workflowEvents = new Mock(); _workflow = new StubWorkflow(); } @@ -46,7 +48,7 @@ public void Throws_exception_when_scheduling_activity_depends_on_itself() public void Get_activity_by_its_event() { var identity = Identity.New("Activity1", "1.0"); - var eventGraph = _eventGraphBuilder.ActivityCompletedGraph(identity, "id", "result"); + var eventGraph = _graphBuilder.ActivityCompletedGraph(identity.ScheduleId(), "id", "result"); var activityCompletedEvent = new ActivityCompletedEvent(eventGraph.First(), eventGraph); var workflow = new TestWorkflow(); @@ -59,20 +61,22 @@ public void Get_activity_by_its_event() public void Get_timer_by_its_event() { var identity = Identity.Timer("Timer1"); - var eventGraph = _eventGraphBuilder.TimerFiredGraph(identity, TimeSpan.FromSeconds(2)); - var activityCompletedEvent = new TimerFiredEvent(eventGraph.First(), eventGraph); + var eventGraph = _graphBuilder.TimerFiredGraph(identity.ScheduleId(), TimeSpan.FromSeconds(2)); + _builder.AddNewEvents(eventGraph.ToArray()); + var workflow = new TestWorkflow(); + workflow.Decisions(_builder.Result()); - var activity = workflow.GetTimerOf(activityCompletedEvent); + var timer = workflow.TimerItem; - Assert.That(activity, Is.EqualTo(TimerItem.New(identity, workflow))); + Assert.That(workflow.TimerItem.Name, Is.EqualTo("Timer1")); } [Test] public void Get_lambda_item_form_its_event() { var identity = Identity.Lambda("Lambda"); - var eventGraph = _eventGraphBuilder.LambdaCompletedEventGraph(identity, "id", "result"); + var eventGraph = _graphBuilder.LambdaCompletedEventGraph(identity.ScheduleId(), "id", "result"); var @event = new LambdaCompletedEvent(eventGraph.First(), eventGraph); var workflow = new TestWorkflow(); @@ -100,12 +104,12 @@ public void Returns_complete_workflow_decision_when_only_propose_to_complete_wor public void Filters_out_propose_to_complete_workflow_decision_when_it_is_generated_along_with_other_decisions() { var decisions = new WorkflowDecision[]{new CompleteWorkflowDecision("complete", true), - new ScheduleActivityDecision(Identity.New("something","1.0"))}; + new ScheduleActivityDecision(Identity.New("something","1.0").ScheduleId())}; _workflowEvents.Setup(w => w.NewEvents()).Returns(Events(decisions)); var workflowDecisions = _workflow.Decisions(_workflowEvents.Object); - Assert.That(workflowDecisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New("something", "1.0")) })); + Assert.That(workflowDecisions, Is.EqualTo(new[] { new ScheduleActivityDecision(Identity.New("something", "1.0").ScheduleId()) })); } [Test] @@ -299,11 +303,12 @@ private IEnumerable AllNonCompletingDecisions() { return new WorkflowDecision[] { - new ScheduleActivityDecision(Identity.New("id", "1.0")), - new ScheduleTimerDecision(Identity.Timer("timer"), TimeSpan.FromSeconds(2)), - new CancelActivityDecision(Identity.New("newid", "1.0")), - new CancelTimerDecision(Identity.Timer("first")), - new ScheduleLambdaDecision(Identity.Lambda("name"),"input" ), + new ScheduleActivityDecision(Identity.New("id", "1.0").ScheduleId()), + new ScheduleTimerDecision(Identity.Timer("timer").ScheduleId(), TimeSpan.FromSeconds(2)), + new CancelActivityDecision(Identity.New("newid", "1.0").ScheduleId()), + new CancelTimerDecision(Identity.Timer("first").ScheduleId()), + new ScheduleLambdaDecision(Identity.Lambda("name").ScheduleId(),"input" ), + new ScheduleChildWorkflowDecision(Identity.New("w","v").ScheduleId(), "input"), }; } @@ -411,7 +416,11 @@ private class TestWorkflow : Workflow { public TestWorkflow() { - ScheduleTimer("Timer1"); + ScheduleTimer("Timer1").OnFired(e => + { + TimerItem = Timer(e); + return Ignore; + }); ScheduleActivity("Activity1", "1.0"); ScheduleLambda("Lambda"); ScheduleChildWorkflow("Workflow", "1.0"); @@ -434,6 +443,8 @@ public IChildWorkflowItem GetChildWorkflow(WorkflowItemEvent @event) { return ChildWorkflow(@event); } + + public ITimerItem TimerItem; } private class WithNullActivityName : Workflow diff --git a/Guflow/Decider/Action/WorkflowAction.cs b/Guflow/Decider/Action/WorkflowAction.cs index 4f6d715..74aac1e 100644 --- a/Guflow/Decider/Action/WorkflowAction.cs +++ b/Guflow/Decider/Action/WorkflowAction.cs @@ -128,5 +128,7 @@ internal static RestartWorkflowAction RestartWorkflow(IWorkflowHistoryEvents wor workflowStartedEvent.TagList.ToList().ForEach(tag=>restartWorkflowAction.AddTag(tag)); return restartWorkflowAction; } + internal static RestartWorkflowAction RestartWorkflowWithDefaultProperties() + => new RestartWorkflowAction(); } } \ No newline at end of file diff --git a/Guflow/Decider/Activity/ActivityCancelRequestedEvent.cs b/Guflow/Decider/Activity/ActivityCancelRequestedEvent.cs index bf5bb2c..62a5ded 100644 --- a/Guflow/Decider/Activity/ActivityCancelRequestedEvent.cs +++ b/Guflow/Decider/Activity/ActivityCancelRequestedEvent.cs @@ -12,7 +12,7 @@ public class ActivityCancelRequestedEvent : WorkflowItemEvent internal ActivityCancelRequestedEvent(HistoryEvent activityCancelRequestedEvent) : base(activityCancelRequestedEvent.EventId) { - SwfIdentity = SwfIdentity.Raw(activityCancelRequestedEvent.ActivityTaskCancelRequestedEventAttributes.ActivityId); + ScheduleId = ScheduleId.Raw(activityCancelRequestedEvent.ActivityTaskCancelRequestedEventAttributes.ActivityId); } } } \ No newline at end of file diff --git a/Guflow/Decider/Activity/ActivityCancellationFailedEvent.cs b/Guflow/Decider/Activity/ActivityCancellationFailedEvent.cs index 3b9da78..e3ef85c 100644 --- a/Guflow/Decider/Activity/ActivityCancellationFailedEvent.cs +++ b/Guflow/Decider/Activity/ActivityCancellationFailedEvent.cs @@ -13,7 +13,7 @@ public class ActivityCancellationFailedEvent : WorkflowItemEvent internal ActivityCancellationFailedEvent(HistoryEvent activityCancellationFailedEvent) : base(activityCancellationFailedEvent.EventId) { _eventAttributes = activityCancellationFailedEvent.RequestCancelActivityTaskFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(_eventAttributes.ActivityId); + ScheduleId = ScheduleId.Raw(_eventAttributes.ActivityId); } /// /// Returns cause, why activity cancellation request has failed. diff --git a/Guflow/Decider/Activity/ActivityEvent.cs b/Guflow/Decider/Activity/ActivityEvent.cs index 57079f7..f1c7429 100644 --- a/Guflow/Decider/Activity/ActivityEvent.cs +++ b/Guflow/Decider/Activity/ActivityEvent.cs @@ -1,83 +1,83 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using Amazon.SimpleWorkflow.Model; - -namespace Guflow.Decider -{ +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. +using System.Collections.Generic; +using System.Linq; +using Amazon.SimpleWorkflow.Model; + +namespace Guflow.Decider +{ /// /// Base class for activity events. - /// - public abstract class ActivityEvent : WorkflowItemEvent - { - private string _activityName; - private string _activityVersion; - private string _activityPositionalName; - private long _startedEventId; - private long _scheduledEventId; + /// + public abstract class ActivityEvent : WorkflowItemEvent + { + private string _activityName; + private string _activityVersion; + private string _activityPositionalName; + private long _startedEventId; + private long _scheduledEventId; /// /// Returns the worker polling identity. - /// - public string WorkerIdentity { get; private set; } - + /// + public string WorkerIdentity { get; private set; } + /// /// Returns the input activity was scheduled with. - /// - public string Input { get; private set; } - protected ActivityEvent(long eventId) - : base(eventId) - { - } + /// + public string Input { get; private set; } + protected ActivityEvent(long eventId) + : base(eventId) + { + } /// /// For internal use only. /// /// /// - /// - protected void PopulateActivityFrom(IEnumerable allHistoryEvents, long startedEventId, long scheduledEventId) - { - bool foundActivityScheduledEvent=false; - _startedEventId = startedEventId; - _scheduledEventId = scheduledEventId; - foreach (var historyEvent in allHistoryEvents) - { - if (historyEvent.IsActivityStartedEvent(startedEventId)) - { - WorkerIdentity = historyEvent.ActivityTaskStartedEventAttributes.Identity; - } - else if (historyEvent.IsActivityScheduledEvent(scheduledEventId)) - { - var attr = historyEvent.ActivityTaskScheduledEventAttributes; - _activityName = attr.ActivityType.Name; - _activityVersion = attr.ActivityType.Version; - _activityPositionalName = attr.Control.As().PN; - SwfIdentity = SwfIdentity.Raw(attr.ActivityId); - Input = attr.Input; - foundActivityScheduledEvent = true; - } - } - if (!foundActivityScheduledEvent) - throw new IncompleteEventGraphException(string.Format("Can not found activity scheduled event id {0}.", scheduledEventId)); - } - - public override string ToString() - { - return $"{GetType().Name} for activity name {_activityName}, version {_activityVersion} and positional name {_activityPositionalName}"; - } - - internal override bool InChainOf(IEnumerable workflowItemEvents) - { - foreach (var itemEvent in workflowItemEvents.OfType()) - { - if (IsInChainOf(itemEvent)) - return true; - } - return false; - } - private bool IsInChainOf(ActivityEvent otherActivityEvent) - { - return _startedEventId == otherActivityEvent._startedEventId || - _scheduledEventId == otherActivityEvent._scheduledEventId; - } - } + /// + protected void PopulateActivityFrom(IEnumerable allHistoryEvents, long startedEventId, long scheduledEventId) + { + bool foundActivityScheduledEvent=false; + _startedEventId = startedEventId; + _scheduledEventId = scheduledEventId; + foreach (var historyEvent in allHistoryEvents) + { + if (historyEvent.IsActivityStartedEvent(startedEventId)) + { + WorkerIdentity = historyEvent.ActivityTaskStartedEventAttributes.Identity; + } + else if (historyEvent.IsActivityScheduledEvent(scheduledEventId)) + { + var attr = historyEvent.ActivityTaskScheduledEventAttributes; + _activityName = attr.ActivityType.Name; + _activityVersion = attr.ActivityType.Version; + _activityPositionalName = attr.Control.As().PN; + ScheduleId = ScheduleId.Raw(attr.ActivityId); + Input = attr.Input; + foundActivityScheduledEvent = true; + } + } + if (!foundActivityScheduledEvent) + throw new IncompleteEventGraphException(string.Format("Can not found activity scheduled event id {0}.", scheduledEventId)); + } + + public override string ToString() + { + return $"{GetType().Name} for activity name {_activityName}, version {_activityVersion} and positional name {_activityPositionalName}"; + } + + internal override bool InChainOf(IEnumerable workflowItemEvents) + { + foreach (var itemEvent in workflowItemEvents.OfType()) + { + if (IsInChainOf(itemEvent)) + return true; + } + return false; + } + private bool IsInChainOf(ActivityEvent otherActivityEvent) + { + return _startedEventId == otherActivityEvent._startedEventId || + _scheduledEventId == otherActivityEvent._scheduledEventId; + } + } } \ No newline at end of file diff --git a/Guflow/Decider/Activity/ActivityItem.cs b/Guflow/Decider/Activity/ActivityItem.cs index ce63a5e..eeaa32f 100644 --- a/Guflow/Decider/Activity/ActivityItem.cs +++ b/Guflow/Decider/Activity/ActivityItem.cs @@ -21,9 +21,11 @@ internal sealed class ActivityItem : WorkflowItem, IFluentActivityItem, IActivit private Func _priorityFunc; private Func _timeoutsFunc; private readonly TimerItem _rescheduleTimer; + private readonly ScheduleId _scheduleId; internal ActivityItem(Identity identity, IWorkflow workflow) : base(identity, workflow) { + _scheduleId = identity.ScheduleId(); _onCompletionAction = c => c.DefaultAction(workflow); _onFailedAction = c => c.DefaultAction(workflow); _onTimedoutAction = t => t.DefaultAction(workflow); @@ -36,7 +38,7 @@ internal ActivityItem(Identity identity, IWorkflow workflow) _onFalseAction = _ =>IsStartupItem() ? WorkflowAction.Empty : new TriggerActions(this).FirstJoint(); _priorityFunc = a => null; _timeoutsFunc = a => new ActivityTimeouts(); - _rescheduleTimer = TimerItem.Reschedule(this, Identity, workflow); + _rescheduleTimer = TimerItem.Reschedule(this, _scheduleId, workflow); } public override WorkflowItemEvent LastEvent(bool includeRescheduleTimerEvents = false) @@ -64,6 +66,8 @@ public override IEnumerable AllEvents(bool includeRescheduleT public string Version => Identity.Version; public string PositionalName => Identity.PositionalName; + public override bool Has(ScheduleId id) => _scheduleId == id; + public IFluentActivityItem AfterActivity(string name, string version, string positionalName = "") { @@ -243,7 +247,7 @@ public override IEnumerable ScheduleDecisions() public override IEnumerable ScheduleDecisionsByIgnoringWhen() { - var scheduleActivityDecision = new ScheduleActivityDecision(Identity); + var scheduleActivityDecision = new ScheduleActivityDecision(_scheduleId); scheduleActivityDecision.Input = _inputFunc(this).ToAwsString(); scheduleActivityDecision.TaskListName = _taskListFunc(this); scheduleActivityDecision.TaskPriority = _priorityFunc(this); @@ -264,7 +268,7 @@ public override IEnumerable CancelDecisions() if (latestTimerEvent != null && lastEvent == latestTimerEvent) return _rescheduleTimer.CancelDecisions(); - return new []{new CancelActivityDecision(Identity)}; + return new []{new CancelActivityDecision(_scheduleId)}; } } diff --git a/Guflow/Decider/Activity/ActivitySchedulingFailedEvent.cs b/Guflow/Decider/Activity/ActivitySchedulingFailedEvent.cs index 62cf5db..c929fda 100644 --- a/Guflow/Decider/Activity/ActivitySchedulingFailedEvent.cs +++ b/Guflow/Decider/Activity/ActivitySchedulingFailedEvent.cs @@ -10,7 +10,7 @@ public class ActivitySchedulingFailedEvent : WorkflowItemEvent internal ActivitySchedulingFailedEvent(HistoryEvent schedulingFailedEvent) : base(schedulingFailedEvent.EventId) { _eventAttributes = schedulingFailedEvent.ScheduleActivityTaskFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(_eventAttributes.ActivityId); + ScheduleId = ScheduleId.Raw(_eventAttributes.ActivityId); } public string Cause { get { return _eventAttributes.Cause; } } diff --git a/Guflow/Decider/Activity/CancelActivityDecision.cs b/Guflow/Decider/Activity/CancelActivityDecision.cs index de30951..c9a7e4c 100644 --- a/Guflow/Decider/Activity/CancelActivityDecision.cs +++ b/Guflow/Decider/Activity/CancelActivityDecision.cs @@ -6,11 +6,11 @@ namespace Guflow.Decider { internal sealed class CancelActivityDecision : WorkflowDecision { - private readonly Identity _identity; + private readonly ScheduleId _id; - public CancelActivityDecision(Identity identity):base(false) + public CancelActivityDecision(ScheduleId id):base(false) { - _identity = identity; + _id = id; } internal override Decision SwfDecision() @@ -20,13 +20,13 @@ internal override Decision SwfDecision() DecisionType = DecisionType.RequestCancelActivityTask, RequestCancelActivityTaskDecisionAttributes = new RequestCancelActivityTaskDecisionAttributes() { - ActivityId = _identity.Id.ToString(), + ActivityId = _id.ToString(), } }; } private bool Equals(CancelActivityDecision other) { - return _identity.Equals(other._identity); + return _id.Equals(other._id); } public override bool Equals(object obj) @@ -38,12 +38,12 @@ public override bool Equals(object obj) public override int GetHashCode() { - return _identity.GetHashCode(); + return _id.GetHashCode(); } public override string ToString() { - return string.Format("{0} for {1}", GetType().Name, _identity); + return string.Format("{0} for {1}", GetType().Name, _id); } } } \ No newline at end of file diff --git a/Guflow/Decider/Activity/ScheduleActivityDecision.cs b/Guflow/Decider/Activity/ScheduleActivityDecision.cs index 72411fe..931c2f3 100644 --- a/Guflow/Decider/Activity/ScheduleActivityDecision.cs +++ b/Guflow/Decider/Activity/ScheduleActivityDecision.cs @@ -7,10 +7,10 @@ namespace Guflow.Decider { internal sealed class ScheduleActivityDecision : WorkflowDecision { - private readonly Identity _identity; - public ScheduleActivityDecision(Identity identity) : base(false) + private readonly ScheduleId _id; + public ScheduleActivityDecision(ScheduleId id) : base(false) { - _identity = identity; + _id = id; } public ActivityTimeouts Timeouts { get; internal set; } @@ -22,19 +22,19 @@ public ScheduleActivityDecision(Identity identity) : base(false) internal override bool IsFor(WorkflowItem workflowItem) { - return workflowItem.Has(_identity); + return workflowItem.Has(_id); } public override bool Equals(object other) { var otherDecision = other as ScheduleActivityDecision; if (otherDecision == null) return false; - return _identity.Equals(otherDecision._identity); + return _id.Equals(otherDecision._id); } public override int GetHashCode() { - return _identity.GetHashCode(); + return _id.GetHashCode(); } internal override Decision SwfDecision() @@ -43,9 +43,9 @@ internal override Decision SwfDecision() { ScheduleActivityTaskDecisionAttributes = new ScheduleActivityTaskDecisionAttributes() { - ActivityType = new ActivityType() { Name = _identity.Name, Version = _identity.Version }, - ActivityId = _identity.Id, - Control = (new ScheduleData() { PN = _identity.PositionalName}).ToJson(), + ActivityType = new ActivityType() { Name = _id.Name, Version = _id.Version }, + ActivityId = _id, + Control = (new ScheduleData() { PN = _id.PositionalName}).ToJson(), HeartbeatTimeout =Timeouts.HeartbeatTimeout.Seconds(), ScheduleToCloseTimeout = Timeouts.ScheduleToCloseTimeout.Seconds(), ScheduleToStartTimeout = Timeouts.ScheduleToStartTimeout.Seconds(), @@ -60,7 +60,7 @@ internal override Decision SwfDecision() public override string ToString() { - return string.Format("{0} for {1}", GetType().Name, _identity); + return string.Format("{0} for {1}", GetType().Name, _id); } } } \ No newline at end of file diff --git a/Guflow/Decider/Cancel/ExternalWorkflowCancelRequestFailedEvent.cs b/Guflow/Decider/Cancel/ExternalWorkflowCancelRequestFailedEvent.cs index f889100..3f628db 100644 --- a/Guflow/Decider/Cancel/ExternalWorkflowCancelRequestFailedEvent.cs +++ b/Guflow/Decider/Cancel/ExternalWorkflowCancelRequestFailedEvent.cs @@ -13,7 +13,7 @@ public class ExternalWorkflowCancelRequestFailedEvent :WorkflowItemEvent internal ExternalWorkflowCancelRequestFailedEvent(HistoryEvent cancelRequestFailedEvent):base(cancelRequestFailedEvent.EventId) { _eventAttributes = cancelRequestFailedEvent.RequestCancelExternalWorkflowExecutionFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(_eventAttributes.WorkflowId); + ScheduleId = ScheduleId.Raw(_eventAttributes.WorkflowId); } internal override WorkflowAction Interpret(IWorkflow workflow) diff --git a/Guflow/Decider/Cancel/ExternalWorkflowCancellationRequestedEvent.cs b/Guflow/Decider/Cancel/ExternalWorkflowCancellationRequestedEvent.cs index 40a6f3a..1be284b 100644 --- a/Guflow/Decider/Cancel/ExternalWorkflowCancellationRequestedEvent.cs +++ b/Guflow/Decider/Cancel/ExternalWorkflowCancellationRequestedEvent.cs @@ -13,7 +13,7 @@ internal ExternalWorkflowCancellationRequestedEvent(HistoryEvent cancelRequested : base(cancelRequested.EventId) { var attr = cancelRequested.ExternalWorkflowExecutionCancelRequestedEventAttributes; - SwfIdentity = SwfIdentity.Raw(attr.WorkflowExecution.WorkflowId); + ScheduleId = ScheduleId.Raw(attr.WorkflowExecution.WorkflowId); } } } \ No newline at end of file diff --git a/Guflow/Decider/ChildWorkflow/ChildWorkflowEvent.cs b/Guflow/Decider/ChildWorkflow/ChildWorkflowEvent.cs index 2f5f12d..003596e 100644 --- a/Guflow/Decider/ChildWorkflow/ChildWorkflowEvent.cs +++ b/Guflow/Decider/ChildWorkflow/ChildWorkflowEvent.cs @@ -43,7 +43,7 @@ protected ChildWorkflowEvent(long eventId) : base(eventId) { var attr = historyEvent.StartChildWorkflowExecutionInitiatedEventAttributes; Input = attr.Input; - SwfIdentity = SwfIdentity.Raw(attr.WorkflowId); + ScheduleId = ScheduleId.Raw(attr.WorkflowId); WorkflowName = attr.WorkflowType.Name; WorkflowVersion = attr.WorkflowType.Version; PositionalName = attr.Control.As().PN; diff --git a/Guflow/Decider/ChildWorkflow/ChildWorkflowItem.cs b/Guflow/Decider/ChildWorkflow/ChildWorkflowItem.cs index 41dee54..1e550df 100644 --- a/Guflow/Decider/ChildWorkflow/ChildWorkflowItem.cs +++ b/Guflow/Decider/ChildWorkflow/ChildWorkflowItem.cs @@ -25,8 +25,8 @@ internal class ChildWorkflowItem : WorkflowItem, IFluentChildWorkflowItem, IChil private Func> _tags; private Func _when; private Func _onWhenFalseAction; - private Identity ScheduleIdentity => Identity.ScheduleIdentity(WorkflowHistoryEvents.WorkflowRunId); - private TimerItem RescheduleTimer => RescheduleTimer(ScheduleIdentity); + private ScheduleId ScheduleId => Identity.ScheduleId(WorkflowHistoryEvents.WorkflowRunId); + private TimerItem RescheduleTimer => RescheduleTimer(ScheduleId); public ChildWorkflowItem(Identity identity, IWorkflow workflow) : base(identity, workflow) { @@ -100,7 +100,7 @@ public override IEnumerable ScheduleDecisions() public override IEnumerable ScheduleDecisionsByIgnoringWhen() { - return new[] {new ScheduleChildWorkflowDecision(ScheduleIdentity, _input(this)) + return new[] {new ScheduleChildWorkflowDecision(ScheduleId, _input(this)) { ChildPolicy = _childPolicy(this), TaskPriority = _taskPriority(this), @@ -125,10 +125,10 @@ public override IEnumerable CancelDecisions() if (latestTimerEvent != null && lastEvent == latestTimerEvent) return RescheduleTimer.CancelDecisions(); - return new[] { new CancelRequestWorkflowDecision(ScheduleIdentity.Id, (lastEvent as ChildWorkflowEvent)?.RunId), }; + return new[] { new CancelRequestWorkflowDecision(ScheduleId, (lastEvent as ChildWorkflowEvent)?.RunId), }; } - public override bool Has(SwfIdentity identity) => ScheduleIdentity.Id == identity; + public override bool Has(ScheduleId id) => ScheduleId == id; public IFluentChildWorkflowItem AfterTimer(string name) { @@ -337,7 +337,7 @@ WorkflowAction ITimer.CancellationFailed(TimerCancellationFailedEvent timerCance public WorkflowAction SignalAction(string signalName, string input) { var lastEvent = LastEvent() as ChildWorkflowEvent; - return WorkflowAction.Signal(signalName, input, ScheduleIdentity.Id, lastEvent?.RunId); + return WorkflowAction.Signal(signalName, input, ScheduleId, lastEvent?.RunId); } public WorkflowAction CancelRequestFailedAction(ExternalWorkflowCancelRequestFailedEvent @event) diff --git a/Guflow/Decider/ChildWorkflow/ScheduleChildWorkflowDecision.cs b/Guflow/Decider/ChildWorkflow/ScheduleChildWorkflowDecision.cs index b72b888..6511a24 100644 --- a/Guflow/Decider/ChildWorkflow/ScheduleChildWorkflowDecision.cs +++ b/Guflow/Decider/ChildWorkflow/ScheduleChildWorkflowDecision.cs @@ -9,12 +9,12 @@ namespace Guflow.Decider { internal class ScheduleChildWorkflowDecision : WorkflowDecision { - private readonly Identity _identity; + private readonly ScheduleId _id; private readonly object _input; - public ScheduleChildWorkflowDecision(Identity identity, object input) : base(false) + public ScheduleChildWorkflowDecision(ScheduleId id, object input) : base(false) { - _identity = identity; + _id = id; _input = input; } @@ -27,7 +27,7 @@ public ScheduleChildWorkflowDecision(Identity identity, object input) : base(fal internal override bool IsFor(WorkflowItem workflowItem) { - return workflowItem.Has(_identity); + return workflowItem.Has(_id); } internal override Decision SwfDecision() @@ -37,10 +37,10 @@ internal override Decision SwfDecision() DecisionType = DecisionType.StartChildWorkflowExecution, StartChildWorkflowExecutionDecisionAttributes = new StartChildWorkflowExecutionDecisionAttributes() { - WorkflowId = _identity.Id, - WorkflowType = new WorkflowType() { Name = _identity.Name, Version = _identity.Version}, + WorkflowId = _id, + WorkflowType = new WorkflowType() { Name = _id.Name, Version = _id.Version}, Input = _input.ToAwsString(), - Control = new ScheduleData() { PN = _identity.PositionalName}.ToJson(), + Control = new ScheduleData() { PN = _id.PositionalName}.ToJson(), ChildPolicy = ChildPolicy, ExecutionStartToCloseTimeout = ExecutionTimeouts.ExecutionStartToCloseTimeout.Seconds(), TaskStartToCloseTimeout = ExecutionTimeouts.TaskStartToCloseTimeout.Seconds(), @@ -56,12 +56,12 @@ public override bool Equals(object obj) { var decision = obj as ScheduleChildWorkflowDecision; return decision != null && - EqualityComparer.Default.Equals(_identity, decision._identity); + EqualityComparer.Default.Equals(_id, decision._id); } public override int GetHashCode() { - return -1493283476 + EqualityComparer.Default.GetHashCode(_identity); + return -1493283476 + EqualityComparer.Default.GetHashCode(_id); } } } \ No newline at end of file diff --git a/Guflow/Decider/IWorkflowItem.cs b/Guflow/Decider/IWorkflowItem.cs index bf99985..6060f27 100644 --- a/Guflow/Decider/IWorkflowItem.cs +++ b/Guflow/Decider/IWorkflowItem.cs @@ -1,71 +1,71 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. -using System.Collections.Generic; - -namespace Guflow.Decider -{ - /// - /// Represents a schedulable workflow item- timer, activity etc. - /// - public interface IWorkflowItem - { - /// - /// Returns all parent activities. - /// - IEnumerable ParentActivities { get; } - /// - /// Returns all parent timers. - /// - IEnumerable ParentTimers { get; } - - - /// - /// Returns all parent lambda functions. - /// - IEnumerable ParentLambdas { get; } - +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. +using System.Collections.Generic; + +namespace Guflow.Decider +{ + /// + /// Represents a schedulable workflow item- timer, activity etc. + /// + public interface IWorkflowItem + { + /// + /// Returns all parent activities. + /// + IEnumerable ParentActivities { get; } + /// + /// Returns all parent timers. + /// + IEnumerable ParentTimers { get; } + + + /// + /// Returns all parent lambda functions. + /// + IEnumerable ParentLambdas { get; } + /// /// Returns all the parent child workflows. - /// - IEnumerable ParentChildWorkflows { get; } - - /// - /// Return latest event for workflow item. Returns null when no event is found. - /// - /// Pass true if want to return reschedule timer event, if any, associated with this workflow item. - WorkflowItemEvent LastEvent(bool includeRescheduleTimerEvents = false); - - /// - /// Returns all events - /// - /// Pass true if want to return reschedule timer events, if any, associated with this workflow item. - IEnumerable AllEvents(bool includeRescheduleTimerEvents = false); - - /// - /// Returns true if workflow item is active otherwise false is return. - /// - bool IsActive { get; } - + /// + IEnumerable ParentChildWorkflows { get; } + + /// + /// Return latest event for workflow item. Returns null when no event is found. + /// + /// Pass true if want to return reschedule timer event, if any, associated with this workflow item. + WorkflowItemEvent LastEvent(bool includeRescheduleTimerEvents = false); + + /// + /// Returns all events + /// + /// Pass true if want to return reschedule timer events, if any, associated with this workflow item. + IEnumerable AllEvents(bool includeRescheduleTimerEvents = false); + + /// + /// Returns true if workflow item is active otherwise false is return. + /// + bool IsActive { get; } + /// - /// Returns the last similar events for this item. e.g. if an activity has following events (starting with latest): ActivityCompletedEvent, ActivityCompletedEvent + /// Returns the last similar events for this item. e.g. if an activity has following events (starting with latest): ActivityCompletedEvent, ActivityCompletedEvent /// ActivityFailedEvent and ActivityFailedEvent. Then this api will return the last two ActivityCompletedEvents. /// - /// - IEnumerable LastSimilarEvents(); - } - - internal interface ITimer - { - WorkflowAction Fired(TimerFiredEvent timerFiredEvent); - WorkflowAction StartFailed(TimerStartFailedEvent timerStartFailedEvent); - WorkflowAction CancellationFailed(TimerCancellationFailedEvent timerCancellationFailedEvent); - } - internal interface IActivity - { - WorkflowAction Completed(ActivityCompletedEvent activityCompletedEvent); - WorkflowAction Failed(ActivityFailedEvent activityFailedEvent); - WorkflowAction Timedout(ActivityTimedoutEvent activityTimedoutEvent); - WorkflowAction Cancelled(ActivityCancelledEvent activityCancelledEvent); - WorkflowAction CancellationFailed(ActivityCancellationFailedEvent activityCancellationFailedEvent); - WorkflowAction SchedulingFailed(ActivitySchedulingFailedEvent activitySchedulingFailedEvent); - } + /// + IEnumerable LastSimilarEvents(); + } + + internal interface ITimer + { + WorkflowAction Fired(TimerFiredEvent timerFiredEvent); + WorkflowAction StartFailed(TimerStartFailedEvent timerStartFailedEvent); + WorkflowAction CancellationFailed(TimerCancellationFailedEvent timerCancellationFailedEvent); + } + internal interface IActivity + { + WorkflowAction Completed(ActivityCompletedEvent activityCompletedEvent); + WorkflowAction Failed(ActivityFailedEvent activityFailedEvent); + WorkflowAction Timedout(ActivityTimedoutEvent activityTimedoutEvent); + WorkflowAction Cancelled(ActivityCancelledEvent activityCancelledEvent); + WorkflowAction CancellationFailed(ActivityCancellationFailedEvent activityCancellationFailedEvent); + WorkflowAction SchedulingFailed(ActivitySchedulingFailedEvent activitySchedulingFailedEvent); + } } \ No newline at end of file diff --git a/Guflow/Decider/Identity.cs b/Guflow/Decider/Identity.cs index 9470a68..ac7b847 100644 --- a/Guflow/Decider/Identity.cs +++ b/Guflow/Decider/Identity.cs @@ -1,60 +1,56 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. -namespace Guflow.Decider -{ - internal class Identity - { - public string Name { get; } - public string Version { get; } +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. +namespace Guflow.Decider +{ + internal class Identity + { + public string Name { get; } + public string Version { get; } public string PositionalName { get; } + private readonly string _id; + private Identity(string name, string version, string positionalName) + { + Name = name; + Version = version; + PositionalName = positionalName; + _id = Decider.ScheduleId.Create(this); + } + public ScheduleId ScheduleId(string salt = "") + { + return Decider.ScheduleId.Create(this,salt); + } + public static readonly Identity Empty = new Identity("","",""); - private Identity(string name, string version, string positionalName) - { - Name = name; - Version = version; - PositionalName = positionalName; - Id = SwfIdentity.Create(Name,Version,PositionalName); - } - //TODO: Move it out of this class - public SwfIdentity Id { get; private set; } - - public Identity ScheduleIdentity(string salt) - { - var identity = new Identity(Name, Version, PositionalName); - identity.Id= SwfIdentity.Create(identity, salt); - return identity; - } - - public static Identity Timer(string name) - { - return new Identity(name,string.Empty,string.Empty); - } - - public static Identity Lambda(string name, string positionalName = "") - { - return new Identity(name, string.Empty, positionalName); - } - - public static Identity New(string name, string version, string positionalName = "") - { - return new Identity(name, version, positionalName); - } - - public override bool Equals(object other) - { - var otherIdentity = other as Identity; - if (otherIdentity == null) - return false; - return Id.Equals(otherIdentity.Id); - } - - public override int GetHashCode() - { - return Id.GetHashCode(); - } - - public override string ToString() - { - return string.Format("{{Name {0}, Version {1} and Positional Name {2}}}", Name, Version, PositionalName); - } - } + public static Identity Timer(string name) + { + return new Identity(name,string.Empty,string.Empty); + } + + public static Identity Lambda(string name, string positionalName = "") + { + return new Identity(name, string.Empty, positionalName); + } + + public static Identity New(string name, string version, string positionalName = "") + { + return new Identity(name, version, positionalName); + } + + public override bool Equals(object other) + { + var otherIdentity = other as Identity; + if (otherIdentity == null) + return false; + return _id.Equals(otherIdentity._id); + } + + public override int GetHashCode() + { + return _id.GetHashCode(); + } + + public override string ToString() + { + return string.Format("{{Name {0}, Version {1} and Positional Name {2}}}", Name, Version, PositionalName); + } + } } \ No newline at end of file diff --git a/Guflow/Decider/Lambda/LambdaEvent.cs b/Guflow/Decider/Lambda/LambdaEvent.cs index ad5fb7d..3a7bc12 100644 --- a/Guflow/Decider/Lambda/LambdaEvent.cs +++ b/Guflow/Decider/Lambda/LambdaEvent.cs @@ -36,13 +36,13 @@ protected void PopulateProperties(long scheduledEventId, IEnumerable().PN; - SwfIdentity = SwfIdentity.Raw(historyEvent.LambdaFunctionScheduledEventAttributes.Id); + ScheduleId = ScheduleId.Raw(historyEvent.LambdaFunctionScheduledEventAttributes.Id); if (!string.IsNullOrEmpty(attr.StartToCloseTimeout)) Timeout = TimeSpan.FromSeconds(Double.Parse(attr.StartToCloseTimeout)); break; } } - if (SwfIdentity == null) + if (ScheduleId == null) throw new IncompleteEventGraphException($"Can not find lambda scheduled event for id {scheduledEventId}."); } internal override bool InChainOf(IEnumerable workflowItemEvents) diff --git a/Guflow/Decider/Lambda/LambdaItem.cs b/Guflow/Decider/Lambda/LambdaItem.cs index 7a10f7a..b68ec7b 100644 --- a/Guflow/Decider/Lambda/LambdaItem.cs +++ b/Guflow/Decider/Lambda/LambdaItem.cs @@ -19,6 +19,7 @@ internal class LambdaItem : WorkflowItem, IFluentLambdaItem, ILambdaItem, ITimer private Func _whenFunc = _ => true; private Func _onFalseTrigger; private TimerItem _rescheduleTimer; + private ScheduleId _scheduleId; public LambdaItem(Identity identity, IWorkflow workflow) : base(identity, workflow) { InitializeDefault(workflow); @@ -26,9 +27,10 @@ public LambdaItem(Identity identity, IWorkflow workflow) : base(identity, workfl private void InitializeDefault(IWorkflow workflow) { + _scheduleId = Identity.ScheduleId(); _input = (item) => WorkflowHistoryEvents.WorkflowStartedEvent().Input; _timeout = item => null; - _rescheduleTimer = TimerItem.Reschedule(this, Identity, workflow); + _rescheduleTimer = TimerItem.Reschedule(this, _scheduleId, workflow); _completedAction = e => e.DefaultAction(workflow); _failedAction = e => e.DefaultAction(workflow); _timedoutAction = e => e.DefaultAction(workflow); @@ -39,6 +41,8 @@ private void InitializeDefault(IWorkflow workflow) public string PositionalName => Identity.PositionalName; + public override bool Has(ScheduleId id) => _scheduleId == id; + public override WorkflowItemEvent LastEvent(bool includeRescheduleTimerEvents = false) { var lambdaEvent = WorkflowHistoryEvents.LastLambdaEvent(this); @@ -70,7 +74,7 @@ public override IEnumerable ScheduleDecisions() public override IEnumerable ScheduleDecisionsByIgnoringWhen() { - return new[] { new ScheduleLambdaDecision(Identity, _input(this), _timeout(this)) }; + return new[] { new ScheduleLambdaDecision(_scheduleId, _input(this), _timeout(this)) }; } public override IEnumerable RescheduleDecisions(TimeSpan timeout) diff --git a/Guflow/Decider/Lambda/LambdaSchedulingFailedEvent.cs b/Guflow/Decider/Lambda/LambdaSchedulingFailedEvent.cs index f283b54..552f601 100644 --- a/Guflow/Decider/Lambda/LambdaSchedulingFailedEvent.cs +++ b/Guflow/Decider/Lambda/LambdaSchedulingFailedEvent.cs @@ -12,7 +12,7 @@ public class LambdaSchedulingFailedEvent : WorkflowItemEvent internal LambdaSchedulingFailedEvent(HistoryEvent failedEvent) : base(failedEvent.EventId) { var attr = failedEvent.ScheduleLambdaFunctionFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(attr.Id); + ScheduleId = ScheduleId.Raw(attr.Id); Cause = attr.Cause?.Value; } diff --git a/Guflow/Decider/Lambda/ScheduleLambdaDecision.cs b/Guflow/Decider/Lambda/ScheduleLambdaDecision.cs index 52cfe64..a0359a3 100644 --- a/Guflow/Decider/Lambda/ScheduleLambdaDecision.cs +++ b/Guflow/Decider/Lambda/ScheduleLambdaDecision.cs @@ -8,20 +8,20 @@ namespace Guflow.Decider { internal class ScheduleLambdaDecision : WorkflowDecision { - private readonly Identity _identity; + private readonly ScheduleId _id; private readonly object _input; private readonly TimeSpan? _timout; - internal ScheduleLambdaDecision(Identity identity, object input, TimeSpan? timout = null) : base(canCloseWorkflow:false, proposal: false) + internal ScheduleLambdaDecision(ScheduleId id, object input, TimeSpan? timout = null) : base(canCloseWorkflow:false, proposal: false) { - _identity = identity; + _id = id; _input = input; _timout = timout; } internal override bool IsFor(WorkflowItem workflowItem) { - return workflowItem.Has(_identity); + return workflowItem.Has(_id); } internal override Decision SwfDecision() @@ -31,23 +31,23 @@ internal override Decision SwfDecision() DecisionType = DecisionType.ScheduleLambdaFunction, ScheduleLambdaFunctionDecisionAttributes = new ScheduleLambdaFunctionDecisionAttributes { - Id = _identity.Id, - Name = _identity.Name, + Id = _id, + Name = _id.Name, Input = _input.ToLambdaInput(), StartToCloseTimeout = _timout.Seconds(), - Control = new ScheduleData() { PN = _identity.PositionalName}.ToJson() + Control = new ScheduleData() { PN = _id.PositionalName}.ToJson() } }; } public override bool Equals(object obj) { var decision = obj as ScheduleLambdaDecision; - return decision != null && _identity.Equals(decision._identity); + return decision != null && _id.Equals(decision._id); } public override int GetHashCode() { - return -1493283476 + _identity.GetHashCode(); + return -1493283476 + _id.GetHashCode(); } } diff --git a/Guflow/Decider/ScheduleId.cs b/Guflow/Decider/ScheduleId.cs new file mode 100644 index 0000000..a003600 --- /dev/null +++ b/Guflow/Decider/ScheduleId.cs @@ -0,0 +1,82 @@ +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. +namespace Guflow.Decider +{ + /// + /// Represent the identity for a scheduled workflow item. This class is used internally. + /// + public sealed class ScheduleId + { + private readonly string _id; + private readonly Identity _itemId; + + private ScheduleId(Identity itemId, string id) + { + _id = id; + _itemId = itemId; + } + + internal string Name => _itemId.Name; + internal string Version => _itemId.Version; + internal string PositionalName => _itemId.PositionalName; + + internal static ScheduleId Create(string name, string version, string positionalName) + { + var timerId = Identity.New(name, version, positionalName); + return Create(timerId); + } + internal static ScheduleId Create(Identity itemId, string salt="") + { + var identity = SwfId(itemId.Name + salt, itemId.Version, itemId.PositionalName); + return new ScheduleId(itemId, identity); + } + + private static string SwfId(string name, string version, string positionalName) + { + var combinedName = string.Format("{0}{1}{2}", name, version, positionalName).ToLower(); + return combinedName.GetMd5Hash(); + } + + internal static ScheduleId Raw(string id) + { + return new ScheduleId(Identity.Empty, id); + } + private bool Equals(ScheduleId other) + { + return string.Equals(_id, other._id); + } + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((ScheduleId)obj); + } + + public static bool operator ==(ScheduleId left, ScheduleId right) + { + if (ReferenceEquals(left, null) && ReferenceEquals(right, null)) + return true; + if (ReferenceEquals(left,null)) + return false; + if (ReferenceEquals(right, null)) + return false; + return left.Equals(right); + } + public static bool operator !=(ScheduleId left, ScheduleId right) + { + return !(left == right); + } + public static implicit operator string(ScheduleId instance) + { + return instance._id; + } + public override int GetHashCode() + { + return _id.GetHashCode(); + } + public override string ToString() + { + return _id; + } + } +} \ No newline at end of file diff --git a/Guflow/Decider/ScheduleTimerDecision.cs b/Guflow/Decider/ScheduleTimerDecision.cs index b8e4b28..512e872 100644 --- a/Guflow/Decider/ScheduleTimerDecision.cs +++ b/Guflow/Decider/ScheduleTimerDecision.cs @@ -7,19 +7,20 @@ namespace Guflow.Decider { internal sealed class ScheduleTimerDecision : WorkflowDecision { - private readonly Identity _timerIdentity; + private readonly ScheduleId _id; private readonly TimeSpan _fireAfter; private readonly bool _isRescheduleTimer; - public ScheduleTimerDecision(Identity timerIdentity, TimeSpan fireAfter, bool isRescheduleTimer=false):base(false) + + public ScheduleTimerDecision(ScheduleId id, TimeSpan fireAfter, bool isRescheduleTimer=false):base(false) { - _timerIdentity = timerIdentity; + _id = id; _fireAfter = fireAfter; _isRescheduleTimer = isRescheduleTimer; } internal override bool IsFor(WorkflowItem workflowItem) { - return workflowItem.Has(_timerIdentity); + return workflowItem.Has(_id); } public override bool Equals(object other) @@ -27,13 +28,13 @@ public override bool Equals(object other) var otherTimer = other as ScheduleTimerDecision; if (otherTimer == null) return false; - return string.Equals(_timerIdentity, otherTimer._timerIdentity) && _fireAfter.Equals(otherTimer._fireAfter) + return string.Equals(_id, otherTimer._id) && _fireAfter.Equals(otherTimer._fireAfter) && _isRescheduleTimer == otherTimer._isRescheduleTimer; } public override int GetHashCode() { - return _timerIdentity.GetHashCode(); + return _id.GetHashCode(); } internal override Decision SwfDecision() @@ -43,16 +44,16 @@ internal override Decision SwfDecision() DecisionType = DecisionType.StartTimer, StartTimerDecisionAttributes = new StartTimerDecisionAttributes() { - TimerId = _timerIdentity.Id.ToString(), + TimerId = _id.ToString(), StartToFireTimeout = Math.Round(_fireAfter.TotalSeconds).ToString(), - Control = (new TimerScheduleData() {IsARescheduleTimer = _isRescheduleTimer, TimerName = _timerIdentity.Name}).ToJson() + Control = (new TimerScheduleData() {IsARescheduleTimer = _isRescheduleTimer, TimerName = _id.Name}).ToJson() } }; } public override string ToString() { - return string.Format("{0} for {1} and reschedulable timer is {2} and interval {3}",GetType().Name,_timerIdentity,_isRescheduleTimer, _fireAfter); + return string.Format("{0} for {1} and reschedulable timer is {2}, interval {3} and id {4}",GetType().Name, _id.Name,_isRescheduleTimer, _fireAfter, _id); } } } \ No newline at end of file diff --git a/Guflow/Decider/SwfIdentity.cs b/Guflow/Decider/SwfIdentity.cs deleted file mode 100644 index 921954c..0000000 --- a/Guflow/Decider/SwfIdentity.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. -namespace Guflow.Decider -{ - public sealed class SwfIdentity - { - private readonly string _identity; - private SwfIdentity(string identity) - { - _identity = identity; - } - public static SwfIdentity Create(string name, string version, string positionalName) - { - var combinedName = string.Format("{0}{1}{2}", name, version, positionalName).ToLower(); - return new SwfIdentity(combinedName.GetMd5Hash()); - } - internal static SwfIdentity Create(Identity identity, string salt) - { - return Create(identity.Name + salt, identity.Version, identity.PositionalName); - } - public static SwfIdentity Raw(string identity) - { - return new SwfIdentity(identity); - } - private bool Equals(SwfIdentity other) - { - return string.Equals(_identity, other._identity); - } - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((SwfIdentity)obj); - } - - public static bool operator ==(SwfIdentity left, SwfIdentity right) - { - if (ReferenceEquals(left, null) && ReferenceEquals(right, null)) - return true; - if (ReferenceEquals(left,null)) - return false; - if (ReferenceEquals(right, null)) - return false; - return left.Equals(right); - } - public static bool operator !=(SwfIdentity left, SwfIdentity right) - { - return !(left == right); - } - public static implicit operator string(SwfIdentity instance) - { - return instance._identity; - } - public override int GetHashCode() - { - return _identity.GetHashCode(); - } - public override string ToString() - { - return _identity; - } - } -} \ No newline at end of file diff --git a/Guflow/Decider/Timer/CancelTimerDecision.cs b/Guflow/Decider/Timer/CancelTimerDecision.cs index fa946c5..fc22e1d 100644 --- a/Guflow/Decider/Timer/CancelTimerDecision.cs +++ b/Guflow/Decider/Timer/CancelTimerDecision.cs @@ -6,10 +6,10 @@ namespace Guflow.Decider { internal sealed class CancelTimerDecision : WorkflowDecision { - private readonly Identity _timerIdentity; - public CancelTimerDecision(Identity timerIdentity):base(false) + private readonly ScheduleId _id; + public CancelTimerDecision(ScheduleId id):base(false) { - _timerIdentity = timerIdentity; + _id = id; } internal override Decision SwfDecision() @@ -19,14 +19,14 @@ internal override Decision SwfDecision() DecisionType = DecisionType.CancelTimer, CancelTimerDecisionAttributes = new CancelTimerDecisionAttributes() { - TimerId = _timerIdentity.Id.ToString() + TimerId = _id.ToString() } }; } private bool Equals(CancelTimerDecision other) { - return _timerIdentity.Equals(other._timerIdentity); + return _id.Equals(other._id); } public override bool Equals(object obj) @@ -39,12 +39,12 @@ public override bool Equals(object obj) public override int GetHashCode() { - return _timerIdentity.GetHashCode(); + return _id.GetHashCode(); } public override string ToString() { - return string.Format("{0} for {1}", GetType().Name, _timerIdentity); + return string.Format("{0} for {1}", GetType().Name, _id); } } } \ No newline at end of file diff --git a/Guflow/Decider/Timer/ITimerItem.cs b/Guflow/Decider/Timer/ITimerItem.cs index 92b618e..291389e 100644 --- a/Guflow/Decider/Timer/ITimerItem.cs +++ b/Guflow/Decider/Timer/ITimerItem.cs @@ -1,4 +1,7 @@ // Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. + +using System; + namespace Guflow.Decider { /// @@ -10,5 +13,17 @@ public interface ITimerItem : IWorkflowItem /// Returns name of timer. /// string Name { get; } + + /// + /// Cancel the already scheduled timer and schedule it again with last timeout. Throws exception if timer is not already active. + /// + /// + WorkflowAction Reset(); + /// + /// Cancel the already scheduled timer and schedule it again with new timeout. Throws exception if timer is not already active. + /// + /// + /// + WorkflowAction Reschedule(TimeSpan timeout); } } \ No newline at end of file diff --git a/Guflow/Decider/Timer/TimerCancellationFailedEvent.cs b/Guflow/Decider/Timer/TimerCancellationFailedEvent.cs index f663981..59acfcd 100644 --- a/Guflow/Decider/Timer/TimerCancellationFailedEvent.cs +++ b/Guflow/Decider/Timer/TimerCancellationFailedEvent.cs @@ -9,7 +9,7 @@ public class TimerCancellationFailedEvent : WorkflowItemEvent internal TimerCancellationFailedEvent(HistoryEvent timerCancellationFailedEvent) : base(timerCancellationFailedEvent.EventId) { _eventAttributes = timerCancellationFailedEvent.CancelTimerFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(_eventAttributes.TimerId); + ScheduleId = ScheduleId.Raw(_eventAttributes.TimerId); } public string Cause { get { return _eventAttributes.Cause; } } internal override WorkflowAction Interpret(IWorkflow workflow) diff --git a/Guflow/Decider/Timer/TimerEvent.cs b/Guflow/Decider/Timer/TimerEvent.cs index 4ea4fc6..256699d 100644 --- a/Guflow/Decider/Timer/TimerEvent.cs +++ b/Guflow/Decider/Timer/TimerEvent.cs @@ -26,7 +26,7 @@ protected void PopulateProperties(long timerStartedEventId, IEnumerable(); IsARescheduledTimer = timerScheduleData.IsARescheduleTimer; _timerName = timerScheduleData.TimerName; @@ -52,6 +52,9 @@ private bool IsInChainOf(TimerEvent otherTimerEvent) { return _timerStartedEventId == otherTimerEvent._timerStartedEventId; } + + internal ScheduleId Id => ScheduleId; + internal TimeSpan Timeout => _firedAfter; public override string ToString() { return string.Format("{0} for timer {1}, fired after {2}",GetType().Name,_timerName,_firedAfter); diff --git a/Guflow/Decider/Timer/TimerItem.cs b/Guflow/Decider/Timer/TimerItem.cs index 7f3dd16..190a976 100644 --- a/Guflow/Decider/Timer/TimerItem.cs +++ b/Guflow/Decider/Timer/TimerItem.cs @@ -6,6 +6,7 @@ namespace Guflow.Decider { + //TODO: Move out RescheduleTimer out of TimerItem. RescheduleTimer can be a decorator on Timer. internal sealed class TimerItem : WorkflowItem, IFluentTimerItem, ITimerItem, ITimer { private TimeSpan _fireAfter= new TimeSpan(); @@ -18,20 +19,25 @@ internal sealed class TimerItem : WorkflowItem, IFluentTimerItem, ITimerItem, IT private Func _timerCancelAction; private TimerItem _rescheduleTimer; + private readonly ScheduleId _defaultScheduleId; + private ScheduleId ResetScheduleId => Identity.ScheduleId(WorkflowHistoryEvents.WorkflowRunId + "Reset"); + private bool _invokedTimerCancelAction = false;// to avoid recurssion. - private TimerItem(Identity identity, IWorkflow workflow) + private TimerItem(Identity identity, ScheduleId defaultScheduleId, IWorkflow workflow) : base(identity, workflow) { + _defaultScheduleId = defaultScheduleId; _canSchedule = t => true; _falseAction = t=>new TriggerActions(this).FirstJoint(); _timerCancelAction =_=>WorkflowAction.Empty; _fireAfterFunc = _ => _fireAfter; } - public static TimerItem Reschedule(WorkflowItem ownerItem, Identity identity, IWorkflow workflow) + public static TimerItem Reschedule(WorkflowItem ownerItem, ScheduleId scheduleId, IWorkflow workflow) { - var timerItem = new TimerItem(identity, workflow); + var identity = Identity.New(scheduleId.Name, scheduleId.Version, scheduleId.PositionalName); + var timerItem = new TimerItem(identity, scheduleId, workflow); timerItem._rescheduleTimer = timerItem; timerItem.OnStartFailed(e => WorkflowAction.FailWorkflow("RESCHEDULE_TIMER_START_FAILED", e.Cause)); timerItem.OnCancellationFailed(e => WorkflowAction.FailWorkflow("RESCHEDULE_TIMER_CANCELLATION_FAILED", e.Cause)); @@ -40,8 +46,9 @@ public static TimerItem Reschedule(WorkflowItem ownerItem, Identity identity, IW } public static TimerItem New(Identity identity, IWorkflow workflow) { - var timerItem = new TimerItem(identity, workflow); - timerItem._rescheduleTimer = Reschedule(timerItem, timerItem.Identity, workflow); + var scheduleId = identity.ScheduleId(); + var timerItem = new TimerItem(identity, scheduleId, workflow); + timerItem._rescheduleTimer = Reschedule(timerItem, scheduleId, workflow); timerItem.OnStartFailed(e => e.DefaultAction(workflow)); timerItem.OnCancellationFailed(e => e.DefaultAction(workflow)); timerItem.OnFired(e => e.DefaultAction(workflow)); @@ -59,6 +66,7 @@ public IFluentTimerItem FireAfter(TimeSpan time) return this; } + public override bool Has(ScheduleId id) => AllScheduleIds.Contains(id); public IFluentTimerItem FireAfter(Func time) { Ensure.NotNull(time, "time"); @@ -183,7 +191,7 @@ public override IEnumerable ScheduleDecisions() public override IEnumerable ScheduleDecisionsByIgnoringWhen() { - return new[] { new ScheduleTimerDecision(Identity, _fireAfterFunc(this), this == _rescheduleTimer) }; + return new[] { new ScheduleTimerDecision(ScheduleId , _fireAfterFunc(this), this == _rescheduleTimer) }; } public override IEnumerable RescheduleDecisions(TimeSpan timeout) @@ -203,7 +211,7 @@ public override IEnumerable CancelDecisions() cancelDecisions = _timerCancelAction(this).Decisions(); } - return new []{new CancelTimerDecision(Identity)}.Concat(cancelDecisions); + return new []{new CancelTimerDecision(ScheduleId)}.Concat(cancelDecisions); } finally { @@ -211,5 +219,22 @@ public override IEnumerable CancelDecisions() } } + public WorkflowAction Reset() => RescheduleAction(); + public WorkflowAction Reschedule(TimeSpan timeout) => RescheduleAction(timeout); + private WorkflowAction RescheduleAction(TimeSpan? timeout= null) + { + if (!IsActive) + throw new InvalidOperationException( + $"Can not reschedule the timer {this}. It should be already active for it be reschedule."); + var lastTimerEvent = (TimerEvent) LastEvent(); + var rescheduleId = RescheduleId(lastTimerEvent.Id); + return WorkflowAction.Custom(new CancelTimerDecision(lastTimerEvent.Id), + new ScheduleTimerDecision(rescheduleId, timeout ?? lastTimerEvent.Timeout)); + } + private ScheduleId RescheduleId(ScheduleId lastScheduleId) => AllScheduleIds.First(id=>id!=lastScheduleId); + private ScheduleId[] AllScheduleIds => new[] {_defaultScheduleId, ResetScheduleId}; + + private ScheduleId ScheduleId => + LastEvent(true) == null ? _defaultScheduleId : ((TimerEvent) LastEvent(true)).Id; } } diff --git a/Guflow/Decider/Timer/TimerStartFailedEvent.cs b/Guflow/Decider/Timer/TimerStartFailedEvent.cs index afcd464..828cb9b 100644 --- a/Guflow/Decider/Timer/TimerStartFailedEvent.cs +++ b/Guflow/Decider/Timer/TimerStartFailedEvent.cs @@ -9,7 +9,7 @@ public class TimerStartFailedEvent : WorkflowItemEvent internal TimerStartFailedEvent(HistoryEvent startTimerFailedEvent) : base(startTimerFailedEvent.EventId) { _startTimerFailedAttributes = startTimerFailedEvent.StartTimerFailedEventAttributes; - SwfIdentity = SwfIdentity.Raw(_startTimerFailedAttributes.TimerId); + ScheduleId = ScheduleId.Raw(_startTimerFailedAttributes.TimerId); } internal string Cause { get { return _startTimerFailedAttributes.Cause; } } diff --git a/Guflow/Decider/Timer/TimerStartedEvent.cs b/Guflow/Decider/Timer/TimerStartedEvent.cs index 654ae5a..cffcac5 100644 --- a/Guflow/Decider/Timer/TimerStartedEvent.cs +++ b/Guflow/Decider/Timer/TimerStartedEvent.cs @@ -1,18 +1,18 @@ -// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. -using System.Collections.Generic; -using Amazon.SimpleWorkflow.Model; - -namespace Guflow.Decider -{ +// Copyright (c) Gurmit Teotia. Please see the LICENSE file in the project root for license information. +using System.Collections.Generic; +using Amazon.SimpleWorkflow.Model; + +namespace Guflow.Decider +{ /// /// Raised when timer is started in SWF. - /// - public class TimerStartedEvent : TimerEvent - { - internal TimerStartedEvent(HistoryEvent timerStartedEvent, IEnumerable allHistoryEvents):base(timerStartedEvent.EventId) - { - PopulateProperties(timerStartedEvent.EventId,allHistoryEvents); - IsActive = true; - } - } + /// + public class TimerStartedEvent : TimerEvent + { + internal TimerStartedEvent(HistoryEvent timerStartedEvent, IEnumerable allHistoryEvents):base(timerStartedEvent.EventId) + { + PopulateProperties(timerStartedEvent.EventId,allHistoryEvents); + IsActive = true; + } + } } \ No newline at end of file diff --git a/Guflow/Decider/Workflow.cs b/Guflow/Decider/Workflow.cs index 01093f0..7d6813f 100644 --- a/Guflow/Decider/Workflow.cs +++ b/Guflow/Decider/Workflow.cs @@ -416,12 +416,15 @@ protected static WorkflowAction CancelWorkflow(string details) { return WorkflowAction.CancelWorkflow(details); } + /// /// Close the current workflow in Amazon SWF and restart it again. /// + /// If it is true then default properties, configured when workflow was registered, are used otherwise it will populate the properties from current workflow. /// - protected RestartWorkflowAction RestartWorkflow() + protected RestartWorkflowAction RestartWorkflow(bool defaultProperties=false) { + if (defaultProperties) return WorkflowAction.RestartWorkflowWithDefaultProperties(); IWorkflow workflow = this; return WorkflowAction.RestartWorkflow(workflow.WorkflowHistoryEvents); } diff --git a/Guflow/Decider/WorkflowActionItem.cs b/Guflow/Decider/WorkflowActionItem.cs index a4cf84a..6fdc826 100644 --- a/Guflow/Decider/WorkflowActionItem.cs +++ b/Guflow/Decider/WorkflowActionItem.cs @@ -35,6 +35,8 @@ public override IEnumerable CancelDecisions() { return Enumerable.Empty(); } + + public override bool Has(ScheduleId id) => false; private static Identity RandomIdentity() { return Identity.New(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); diff --git a/Guflow/Decider/WorkflowHistoryEvents.cs b/Guflow/Decider/WorkflowHistoryEvents.cs index 78c80d8..4652c88 100644 --- a/Guflow/Decider/WorkflowHistoryEvents.cs +++ b/Guflow/Decider/WorkflowHistoryEvents.cs @@ -17,9 +17,6 @@ internal class WorkflowHistoryEvents : IWorkflowHistoryEvents private readonly Dictionary _cachedLambdaEvents = new Dictionary(); private readonly Dictionary _cachedChildWorkflowEvents = new Dictionary(); - private static readonly List ActivityLastEventFilters = new List(){typeof(ActivityCancelRequestedEvent), typeof(ActivityCancellationFailedEvent)}; - private static readonly List ChildWorkflowLastEventFilters = new List(){typeof(ExternalWorkflowCancelRequestFailedEvent), typeof(ExternalWorkflowCancellationRequestedEvent)}; - //TODO : Get rid of this constructor once the dependent constructor is deleted. private WorkflowHistoryEvents(IEnumerable allHistoryEvents, long previousStartedEventId, long newStartedEventId) { @@ -48,7 +45,7 @@ public WorkflowItemEvent LastActivityEvent(ActivityItem activityItem) WorkflowItemEvent result = null; if (_cachedActivityEvents.TryGetValue(activityItem, out result)) return result; - result = AllActivityEvents(activityItem).FirstOrDefault(e=>!ActivityLastEventFilters.Contains(e.GetType())); + result = AllActivityEvents(activityItem).FirstOrDefault(e=>!LastEventFilters.Activity.Contains(e)); _cachedActivityEvents.Add(activityItem, result); return result; } @@ -58,7 +55,7 @@ public WorkflowItemEvent LastTimerEvent(TimerItem timerItem, bool includeResched WorkflowItemEvent result = null; if (_cachedTimerEvents.TryGetValue(timerItem, out result)) return result; - result = AllTimerEvents(timerItem, includeRescheduleTimerEvents).FirstOrDefault(); + result = AllTimerEvents(timerItem, includeRescheduleTimerEvents).FirstOrDefault(e => !LastEventFilters.Timer.Contains(e)); _cachedTimerEvents.Add(timerItem, result); return result; } @@ -181,7 +178,7 @@ public WorkflowItemEvent LastLambdaEvent(LambdaItem lambdaItem) WorkflowItemEvent @event = null; if (_cachedLambdaEvents.TryGetValue(lambdaItem, out @event)) return @event; - @event = AllLambdaEvents(lambdaItem).FirstOrDefault(); + @event = AllLambdaEvents(lambdaItem).FirstOrDefault(e=>!LastEventFilters.Lambda.Contains(e)); _cachedLambdaEvents.Add(lambdaItem, @event); return @event; } @@ -206,7 +203,7 @@ public WorkflowItemEvent LastChildWorkflowEvent(ChildWorkflowItem childWorkflowI WorkflowItemEvent @event = null; if (_cachedChildWorkflowEvents.TryGetValue(childWorkflowItem, out @event)) return @event; - @event = AllChildWorkflowEvents(childWorkflowItem).FirstOrDefault(e=>!ChildWorkflowLastEventFilters.Contains(e.GetType())); + @event = AllChildWorkflowEvents(childWorkflowItem).FirstOrDefault(e=>!LastEventFilters.ChildWorkflow.Contains(e)); _cachedChildWorkflowEvents.Add(childWorkflowItem, @event); return @event; } @@ -219,5 +216,25 @@ private bool IsRescheduleTimerEvent(WorkflowItemEvent @event) return timerEvent != null && timerEvent.IsARescheduledTimer; } + private class LastEventFilters + { + private readonly Type[] _filterOutTypes; + + private LastEventFilters(params Type[] filterOutTypes) + { + _filterOutTypes = filterOutTypes; + } + public static readonly LastEventFilters Activity = + new LastEventFilters(typeof(ActivityCancelRequestedEvent), typeof(ActivityCancellationFailedEvent), typeof(ActivitySchedulingFailedEvent)); + public static readonly LastEventFilters ChildWorkflow = + new LastEventFilters(typeof(ExternalWorkflowCancelRequestFailedEvent), typeof(ExternalWorkflowCancellationRequestedEvent), typeof(ChildWorkflowStartFailedEvent)); + public static readonly LastEventFilters Timer = + new LastEventFilters(typeof(TimerStartFailedEvent), typeof(TimerCancellationFailedEvent)); + public static readonly LastEventFilters Lambda = + new LastEventFilters(typeof(LambdaSchedulingFailedEvent)); + + public bool Contains(WorkflowItemEvent @event) + => _filterOutTypes.Contains(@event.GetType()); + } } } diff --git a/Guflow/Decider/WorkflowItem.cs b/Guflow/Decider/WorkflowItem.cs index 796aea2..4de4ebf 100644 --- a/Guflow/Decider/WorkflowItem.cs +++ b/Guflow/Decider/WorkflowItem.cs @@ -73,10 +73,8 @@ public IEnumerable Parents() public abstract IEnumerable ScheduleDecisionsByIgnoringWhen(); public abstract IEnumerable RescheduleDecisions(TimeSpan timeout); public abstract IEnumerable CancelDecisions(); - public virtual bool Has(SwfIdentity identity) - { - return Identity.Id == identity; - } + public abstract bool Has(ScheduleId id); + public bool Has(Identity identity) { return Identity.Equals(identity); @@ -148,7 +146,7 @@ protected void AddParent(Identity identity) _parentItems.Add(parentItem); } protected IWorkflowHistoryEvents WorkflowHistoryEvents => _workflow.WorkflowHistoryEvents; - protected TimerItem RescheduleTimer(Identity identity) => TimerItem.Reschedule(this, identity, _workflow); + protected TimerItem RescheduleTimer(ScheduleId identity) => TimerItem.Reschedule(this, identity, _workflow); public WorkflowAction DefaultActionOnLastEvent() { return LastEvent().DefaultAction(_workflow); diff --git a/Guflow/Decider/WorkflowItemEvent.cs b/Guflow/Decider/WorkflowItemEvent.cs index 543efd8..3ea507c 100644 --- a/Guflow/Decider/WorkflowItemEvent.cs +++ b/Guflow/Decider/WorkflowItemEvent.cs @@ -10,10 +10,10 @@ namespace Guflow.Decider /// public abstract class WorkflowItemEvent : WorkflowEvent { - protected SwfIdentity SwfIdentity; + protected ScheduleId ScheduleId; internal bool IsFor(WorkflowItem workflowItem) { - return workflowItem.Has(SwfIdentity); + return workflowItem.Has(ScheduleId); } protected WorkflowItemEvent(long eventId)