Exemplo n.º 1
0
        internal void ScheduleActivity_SuspendableExceededTimeTest()
        {
            string input = "input data";

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var action = Substitute.For <IActivity, ISuspendable>();

            action.Name.Returns("TestActivity");
            action.MaxAttempts = 3;
            ((ISuspendable)action).WaitingTimeInSeconds = (100);

            var state = new SchedulableState
            {
                StepNumber            = 0,
                StepKey               = "activityKey",
                ActionNumber          = 0,
                AttemptNumber         = 1,
                MaxAttempts           = action.MaxAttempts,
                TotalActions          = 1,
                DelayTimeoutInSeconds = action.Options.DelayTimeoutInSeconds,
                StartedDate           = DateTime.UtcNow.AddSeconds(-((ISuspendable)action).WaitingTimeInSeconds - 1)      // Was started 100 seconds ago.
            };

            var decisions = workflow.ScheduleActivity(state, input, action);

            workflow.Received().FailWorkflow(action.ActivityId, "Suspendable activity exceeded waiting time.");
        }
Exemplo n.º 2
0
        internal void RetryScheduled_GoodAttemptsTest()
        {
            WorkflowState wfState = new WorkflowState(0);

            SchedulableState state = new SchedulableState()
            {
                StepNumber            = 0,
                StepKey               = "testActivity",
                ActionNumber          = 1,
                AttemptNumber         = 1,
                MaxAttempts           = 1,
                TotalActions          = 1,
                DelayTimeoutInSeconds = 0,
            };

            var context = Substitute.For <WorkflowDecisionContext>();

            context.Control = SchedulableStateSerializer.Serialize(state);

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            /*workflow.RetryScheduled(context, wfState);
             *
             * workflow.Received().FailWorkflow(context.Details, "State is undefined.");
             */
        }
Exemplo n.º 3
0
        internal void ScheduleActivity_ActivityTimerTest()
        {
            string input = "input data";

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var action = Substitute.For <IActivity>();

            action.Name.Returns("TestActivity");
            action.MaxAttempts = 3;
            action.Options.DelayTimeoutInSeconds = 100;

            var state = new SchedulableState
            {
                StepNumber            = 0,
                StepKey               = "activityKey",
                ActionNumber          = 0,
                AttemptNumber         = 1,
                MaxAttempts           = action.MaxAttempts,
                TotalActions          = 1,
                DelayTimeoutInSeconds = action.Options.DelayTimeoutInSeconds
            };

            var decisions = workflow.ScheduleActivity(state, input, action);

            Assert.True(decisions.Count == 2, "Incorrect decisions count.");
            Assert.True(decisions[0].DecisionType == DecisionType.StartTimer,
                        $"The first decision [{decisions[0].DecisionType}] is incorrect.");
            Assert.True(decisions[1].DecisionType == DecisionType.RecordMarker,
                        $"The second decision [{decisions[1].DecisionType}] is incorrect.");
        }
Exemplo n.º 4
0
        internal void ScheduleActivity_SuspendableTest()
        {
            string input = "input data";

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var action = Substitute.For <IActivity, ISuspendable>();

            action.Name.Returns("TestActivity");
            action.MaxAttempts = 3;
            ((ISuspendable)action).WaitingTimeInSeconds = (100);

            var state = new SchedulableState
            {
                StepNumber            = 0,
                StepKey               = "activityKey",
                ActionNumber          = 0,
                AttemptNumber         = 1,
                MaxAttempts           = action.MaxAttempts,
                TotalActions          = 1,
                DelayTimeoutInSeconds = action.Options.DelayTimeoutInSeconds,
                StartedDate           = DateTime.UtcNow
            };

            var decisions = workflow.ScheduleActivity(state, input, action);

            Assert.True(state.StartedDate != DateTime.MinValue);

            Assert.True(decisions.Count == 1, "The only one decision is applicable for a simple non-delayed activity.");
            Assert.True(decisions[0].DecisionType == DecisionType.ScheduleActivityTask,
                        $"Incorrect decision type [{decisions[0].DecisionType}].");
        }
Exemplo n.º 5
0
        internal void NextStepActivity(WorkflowDecisionContext decisionContext, WorkflowState wfState)
        {
            var state = new SchedulableState();

            decisionContext.Control   = SchedulableStateSerializer.Serialize(state);
            decisionContext.ResultRef = Utils.SerializeToJSON(new StepResult <string>());

            var action = Substitute.For <ActivityBase <string, string> >("name", "taskList");

            var step = Substitute.For <WorkflowStep>();

            step.Action     = action;
            step.StepKey    = "activityActionName";
            step.StepNumber = 0;

            _workflow.GetStep(Arg.Any <int>()).Returns(info => step);

            _workflow.ProcessIActivity(decisionContext, step, state)
            .Returns(info => new StepDecision());

            _workflow.NextStep(decisionContext, wfState);

            //check if these methods were called
            _workflow.Received().ProcessIActivity(decisionContext, step, state);
        }
Exemplo n.º 6
0
        internal void ScheduleActivity_ActivityTest()
        {
            string input = "input data";

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var action = Substitute.For <IActivity>();

            action.Name.Returns("TestActivity");
            action.MaxAttempts = 3;
            action.Options.DelayTimeoutInSeconds = 0;

            var state = new SchedulableState
            {
                StepNumber            = 0,
                StepKey               = "activityKey",
                ActionNumber          = 0,
                AttemptNumber         = 1,
                MaxAttempts           = action.MaxAttempts,
                TotalActions          = 1,
                DelayTimeoutInSeconds = action.Options.DelayTimeoutInSeconds
            };

            //workflow.When(x => x.ScheduleActivity(0, 1, step.StepNumber, step.StepKey, 0, input, action)).DoNotCallBase();
            //workflow.ScheduleActivity(0, 1, step.StepNumber, step.StepKey, 0, input, action)
            //	.ReturnsForAnyArgs(info => new List<Decision>() { new Decision() { DecisionType = DecisionType.ScheduleActivityTask } });

            var decisions = workflow.ScheduleActivity(state, input, action);

            Assert.True(decisions.Count == 1, "The only one decision is applicable for a simple non-delayed activity.");
            Assert.True(decisions[0].DecisionType == DecisionType.ScheduleActivityTask,
                        $"Incorrect decision type [{decisions[0].DecisionType}].");
        }
Exemplo n.º 7
0
        internal void ProcessIActivityNotSuccessTest(WorkflowState wfState, SchedulableState schedulableState)
        {
            var action = Substitute.For <ActivityBase <string, string> >("name", "taskList");

            var step = Substitute.For <WorkflowStep>();

            step.Action     = action;
            step.StepKey    = "activityActionName";
            step.StepNumber = 0;

            var stepResult = new StepResult <string>(string.Empty, false, step.StepKey);

            var context = Substitute.For <WorkflowDecisionContext>();

            context.Control   = SchedulableStateSerializer.Serialize(schedulableState);
            context.ResultRef = Utils.SerializeToJSON(stepResult);

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            workflow.WhenForAnyArgs(x => x.FailWorkflow(string.Empty, string.Empty)).DoNotCallBase();
            workflow.FailWorkflow(string.Empty, string.Empty).ReturnsForAnyArgs(info => new Decision());

            workflow.ProcessIActivity(context, step, schedulableState);

            //check if these methods were called
            workflow.ReceivedWithAnyArgs().FailWorkflow(string.Empty, string.Empty);
        }
Exemplo n.º 8
0
        internal void NextStepParallelCollection(WorkflowDecisionContext decisionContext, WorkflowState wfState)
        {
            var state = new SchedulableState();

            decisionContext.Control   = SchedulableStateSerializer.Serialize(state);
            decisionContext.ResultRef = Utils.SerializeToJSON(new StepResult <string>());

            var action = Substitute.For <ParallelActivityCollectionBase <string, string, string, string> >("name", "taskList");

            var step = Substitute.For <WorkflowStep>();

            step.Action     = action;
            step.StepKey    = "activity_ParallelCollection";
            step.StepNumber = 0;

            var workflow = Substitute.For <WorkflowBase>("domain", "NextStepParallelCollection", "version", "taskList", _amazonSwf);

            workflow.Steps.Add(step);

            workflow.GetStep(Arg.Any <int>()).Returns(info => step);

            workflow.ProcessActionCollection(decisionContext, wfState, state, action, step)
            .Returns(info => new StepDecision());

            workflow.ProcessIActivity(decisionContext, step, state)
            .Returns(info => new StepDecision());

            workflow.NextStep(decisionContext, wfState);

            //check if these methods were called
            workflow.Received().ProcessActionCollection(decisionContext, wfState, state, action, step);
            workflow.DidNotReceiveWithAnyArgs().ProcessIActivity(null, null, null);
        }
Exemplo n.º 9
0
        internal void SchedulableState_GetHashCodeTest()
        {
            var a = new SchedulableState()
            {
                StepNumber = 3, ActionNumber = 5
            };

            var expected = 197888;

            Assert.True(a.GetHashCode() == expected);
        }
Exemplo n.º 10
0
        internal void GetActionIdTest([Frozen] string name, [Frozen] SchedulableState state)
        {
            state.StepNumber            = 1;
            state.StepKey               = "testActivity";
            state.ActionNumber          = 1;
            state.AttemptNumber         = 1;
            state.MaxAttempts           = 1;
            state.TotalActions          = 1;
            state.DelayTimeoutInSeconds = 0;

            string activityID = Utils.CreateActionId(name, "", state.StepNumber, state.ActionNumber, state.AttemptNumber);
            string expected   =
                $"{String.Empty}__{name.TrimForID()}._{state.StepNumber}._{state.ActionNumber}._{state.AttemptNumber}";

            Assert.Equal(activityID, expected);
        }
Exemplo n.º 11
0
        internal void SchedulableState_StartedDateTest()
        {
            var state = new SchedulableState();

            Assert.True(state.StartedDate == DateTime.MinValue);

            var expected = DateTime.Now;

            state.StartedDate = expected;

            Assert.True(state.StartedDate == expected.ToUniversalTime());

            state.StartedDate = expected.AddHours(1);

            Assert.True(state.StartedDate == expected.ToUniversalTime());
        }
Exemplo n.º 12
0
        internal void ProcessISuspendableSuspendTest(WorkflowState wfState, SchedulableState schedulableState)
        {
            schedulableState.AttemptNumber = 3;

            var action = Substitute.For <SuspendableActivity <string, string> >("name", "taskList");

            action.Input = string.Empty;
            action.Options.DelayTimeoutInSeconds = 30;

            var activityStep = Substitute.For <WorkflowStep>();

            activityStep.Action     = action;
            activityStep.StepKey    = "activityActionName";
            activityStep.StepNumber = 0;

            var stepResult = new StepResult <string>(string.Empty, false, activityStep.StepKey);
            var result     = Utils.SerializeToJSON(stepResult);

            var context = Substitute.For <WorkflowDecisionContext>();

            context.Control   = SchedulableStateSerializer.Serialize(schedulableState);
            context.ResultRef = result;
            context.InputRef  = stepResult.ReturnValue;

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            workflow.WhenForAnyArgs(x => x.ScheduleActivity(schedulableState, string.Empty, action)).DoNotCallBase();
            workflow.ScheduleActivity(schedulableState, string.Empty, action)
            .ReturnsForAnyArgs(info => new List <Decision>());

            workflow.ProcessISuspendable(context, wfState, activityStep, schedulableState);

            Assert.True(schedulableState.DelayTimeoutInSeconds == action.Options.DelayTimeoutInSeconds, "SchedulableState.DelayTimeoutInSeconds has not been updated.");
            Assert.True(schedulableState.AttemptNumber == 0, "SchedulableState.AttemptNumber has not been reset.");

            //check if these methods were called
            workflow.Received().ScheduleActivity(schedulableState, stepResult.ReturnValue, action);
        }
Exemplo n.º 13
0
        internal void ProcessIActivitySuccessTest(WorkflowState wfState, SchedulableState schedulableState)
        {
            var action = Substitute.For <ActivityBase <string, string> >("name", "taskList");

            var activityStep = Substitute.For <WorkflowStep>();

            activityStep.Action     = action;
            activityStep.StepKey    = "activityActionName";
            activityStep.StepNumber = 0;

            var stepResult = new StepResult <string>(string.Empty, true, activityStep.StepKey);
            var result     = Utils.SerializeToJSON(stepResult);

            var context = Substitute.For <WorkflowDecisionContext>();

            context.Control   = SchedulableStateSerializer.Serialize(schedulableState);
            context.ResultRef = result;

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            workflow.WhenForAnyArgs(x => x.ResolveStepNumber(activityStep, string.Empty, 0)).DoNotCallBase();
            workflow.ResolveStepNumber(activityStep, string.Empty, 0)
            .ReturnsForAnyArgs(info => new StepResult
            {
                Input = string.Empty, StepNumber = activityStep.StepNumber + 1
            });

            workflow.WhenForAnyArgs(x => x.ScheduleStep(0, string.Empty, 3)).DoNotCallBase();
            workflow.ScheduleStep(0, string.Empty, 3)
            .ReturnsForAnyArgs(info => new StepDecision());

            workflow.ProcessIActivity(context, activityStep, schedulableState);

            //check if these methods were called
            workflow.Received().ResolveStepNumber(activityStep, string.Empty, activityStep.StepNumber + 1);
            workflow.Received().ScheduleStep(activityStep.StepNumber + 1, string.Empty, 0);
        }
Exemplo n.º 14
0
        internal void SchedulableState_EqualsTest()
        {
            var a = new SchedulableState()
            {
                StepNumber = 1, ActionNumber = 1
            };
            var b = new SchedulableState()
            {
                StepNumber = 2, ActionNumber = 1
            };

            Assert.False(a.Equals(null));

            Assert.True(a.Equals(a));

            Assert.False(a.Equals("data"));

            Assert.False(a.Equals(b));

            var c = a;

            Assert.True(a.Equals(c));

            var a1 = new SchedulableState()
            {
                StepNumber = 1, ActionNumber = 1
            };

            Assert.True(a.Equals(a1));

            var d = new SchedulableState()
            {
                StepNumber = 1, ActionNumber = 2
            };

            Assert.False(a.Equals(d));
        }
Exemplo n.º 15
0
        internal void ProcessActionCollectionTest(WorkflowState state, SchedulableState schedulableState)
        {
            state.CurrentStepNumber = 0;
            state.Results.AddOrUpdate(1, "TestResult", (i, s) => $"{s}{i}");

            schedulableState.StepNumber            = 0;
            schedulableState.StepKey               = "testActivity";
            schedulableState.ActionNumber          = 1;
            schedulableState.AttemptNumber         = 1;
            schedulableState.MaxAttempts           = 1;
            schedulableState.TotalActions          = 1;
            schedulableState.DelayTimeoutInSeconds = 0;

            var action = Substitute.For <ParallelActivityCollectionBase <string, string, string, string> >("name", "taskList");

            var step = Substitute.For <WorkflowStep>();

            step.Action     = action;
            step.StepKey    = "activityActionName";
            step.StepNumber = 0;
            //_workflow.Steps.Add(activityStep);

            //_workflow.GetStep(Arg.Any<int>()).Returns(info => activityStep);

            //_processor = new WorkflowEventsProcessor(_decisionTask, _workflow, _pollforDecisionTaskRequest, _amazonSwf);
            //_workflow.GetStep(1).ReturnsForAnyArgs(info => activityStep);

            var context = Substitute.For <WorkflowDecisionContext>();

            context.Control = SchedulableStateSerializer.Serialize(schedulableState);

            Dictionary <int, string> results = state.Results.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);


            context.Results[schedulableState.StepNumber] = results;

            var workflow = Substitute.ForPartsOf <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            workflow.WhenForAnyArgs(x => x.GetStep(Arg.Any <int>())).DoNotCallBase();
            workflow.GetStep(Arg.Any <int>()).Returns(info => step);

            workflow.WhenForAnyArgs(x => x.CallReducer(action, results)).DoNotCallBase();
            workflow.CallReducer(action, results).Returns(info => String.Empty);

            workflow.WhenForAnyArgs(x => x.ResolveStepNumber(step, String.Empty, 0)).DoNotCallBase();
            workflow.ResolveStepNumber(step, String.Empty, 0)
            .ReturnsForAnyArgs(info => new StepResult
            {
                Input = String.Empty, StepNumber = 0
            });

            workflow.WhenForAnyArgs(x => x.ScheduleStep(0, String.Empty, 3)).DoNotCallBase();
            workflow.ScheduleStep(0, String.Empty, 3)
            .ReturnsForAnyArgs(info => new StepDecision());

            workflow.ProcessActionCollection(context, state, schedulableState, action, step);

            //check if these methods were called
            workflow.Received().CallReducer(action, results);
            workflow.Received().ResolveStepNumber(step, String.Empty, 1);
            //1 is expected from schedulableState.StepNumber = 0 + 1
            workflow.Received().ScheduleStep(0, String.Empty, 0);             // 0 is expected from schedulableState.AttemptNumber = 1 - 1;
        }