public void WaitAll_OutputsNothing_WhenAnyTaskIsNotCompleted(
            bool scheduled, bool completed)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateActivityHistory("FunctionA", scheduled: true, completed: true, output: "\"Result1\""), // completed
                CreateActivityHistory("FunctionA", scheduled: true, completed: true, output: "\"Result2\""),
                CreateDurableTimerHistory(timerCreated: scheduled, timerFired: completed, fireAt: _fireAt, _restartTime, orchestratorStartedIsProcessed: false),
                CreateActivityHistory("FunctionB", scheduled: true, completed: true, output: "\"Result3\"") // completed
                );

            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var tasksToWaitFor =
                new ReadOnlyCollection <DurableTask>(
                    new DurableTask[] {
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new DurableTimerTask(_fireAt),
                new ActivityInvocationTask("FunctionB", FunctionInput)
            });

            var durableTaskHandler = new DurableTaskHandler();

            DurableTestUtilities.EmulateStop(durableTaskHandler);

            durableTaskHandler.WaitAll(tasksToWaitFor, orchestrationContext,
                                       _ => { Assert.True(false, "Unexpected output"); });

            VerifyNoOrchestrationActionAdded(orchestrationContext);
        }
        public void WaitAny_WaitsForStop_WhenAllTasksAreNotCompleted(bool completed, bool expectedWaitForStop)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateActivityHistory("FunctionA", scheduled: true, completed: false, output: "\"Result1\""),
                CreateActivityHistory("FunctionA", scheduled: true, completed: completed, output: "\"Result2\"")
                );

            var durableTaskHandler = new DurableTaskHandler();

            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var tasksToWaitFor =
                new ReadOnlyCollection <DurableTask>(
                    new DurableTask[] {
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new ActivityInvocationTask("FunctionA", FunctionInput)
            });

            DurableTestUtilities.VerifyWaitForDurableTasks(
                durableTaskHandler,
                _delayBeforeStopping,
                expectedWaitForStop,
                () =>
            {
                durableTaskHandler.WaitAny(tasksToWaitFor, orchestrationContext, _ => { });
            });
        }
示例#3
0
        public void StopAndInitiateDurableTaskOrReplay_ReplaysMultipleActivitiesWithTheSameName()
        {
            var loadedFunctions = new[]
            {
                DurableTestUtilities.CreateFakeActivityTriggerAzFunctionInfo("FunctionA"),
                DurableTestUtilities.CreateFakeActivityTriggerAzFunctionInfo("FunctionB")
            };

            var history = DurableTestUtilities.MergeHistories(
                CreateHistory("FunctionA", scheduled: true, completed: true, output: "\"Result1\""),
                CreateHistory("FunctionB", scheduled: true, completed: true, output: "\"Result2\""),
                CreateHistory("FunctionA", scheduled: true, completed: true, output: "\"Result3\"")
                );
            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var allOutput = new List <object>();

            var durableTaskHandler = new DurableTaskHandler();

            // Replay FunctionA only
            for (var i = 0; i < 2; ++i)
            {
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                    new ActivityInvocationTask("FunctionA", FunctionInput), orchestrationContext, noWait: false,
                    output => { allOutput.Add(output); });
            }

            // Expect FunctionA results only
            Assert.Equal(new[] { "Result1", "Result3" }, allOutput);
        }
        public void WaitAll_WaitsForStop_WhenAnyTaskIsNotCompleted(bool scheduledAndCompleted, bool expectedWaitForStop)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateActivityHistory("FunctionA", scheduled: true, completed: true, output: "\"Result1\""),
                CreateActivityHistory("FunctionA", scheduled: scheduledAndCompleted, completed: scheduledAndCompleted, output: "\"Result2\""),
                CreateDurableTimerHistory(timerCreated: scheduledAndCompleted, timerFired: scheduledAndCompleted, fireAt: _fireAt, _restartTime, orchestratorStartedIsProcessed: false),
                CreateActivityHistory("FunctionB", scheduled: true, completed: true, output: "\"Result3\"")
                );

            var durableTaskHandler = new DurableTaskHandler();

            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var tasksToWaitFor =
                new ReadOnlyCollection <DurableTask>(
                    new DurableTask[] {
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new DurableTimerTask(_fireAt),
                new ActivityInvocationTask("FunctionB", FunctionInput)
            });

            DurableTestUtilities.VerifyWaitForDurableTasks(
                durableTaskHandler,
                _delayBeforeStopping,
                expectedWaitForStop,
                () =>
            {
                durableTaskHandler.WaitAll(tasksToWaitFor, orchestrationContext, _ => { });
            });
        }
示例#5
0
        private void VerifyCreateDurableTimerActionAdded(OrchestrationContext context, DateTime fireAt)
        {
            var actions = DurableTestUtilities.GetCollectedActions(context);
            var action  = (CreateDurableTimerAction)actions.Last().Last();

            Assert.Equal(action.FireAt, fireAt);
        }
示例#6
0
        public void StopAndInitiateDurableTaskOrReplay_UpdatesCurrentUtcDateTimeToNextOrchestratorStartedTimestamp_OnlyIfTimerCreatedAndFired(bool timerCreated, bool timerFired)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: timerCreated, timerFired: timerFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateOrchestratorStartedHistory(date: _shouldNotHitTime, isProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };

            var durableTaskHandler = new DurableTaskHandler();
            var task = new DurableTimerTask(_fireAt);

            if (!timerCreated || !timerFired)
            {
                DurableTestUtilities.EmulateStop(durableTaskHandler);
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                    task: task, context: context, noWait: false,
                    output: _ => { Assert.True(false, "Unexpected output"); },
                    onFailure: _ => { });
                Assert.Equal(_startTime, context.CurrentUtcDateTime);
            }
            else
            {
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(task: task, context: context, noWait: false, _ => { Assert.True(false, "Unexpected output"); }, errorMessage => { });
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }
            VerifyCreateDurableTimerActionAdded(context, _fireAt);
        }
示例#7
0
        public void StopAndInitiateDurableTaskOrReplay_ContinuesToNextTimer_IfTimersHaveIdenticalFireAt()
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _shouldNotHitTime, orchestratorStartedIsProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history
            };

            var durableTaskHandler = new DurableTaskHandler();

            for (int i = 0; i < 2; i++)
            {
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                    task: new DurableTimerTask(_fireAt), context: context, noWait: false,
                    output: _ => { Assert.True(false, "Unexpected output"); },
                    onFailure: _ => { });
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }

            durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                task: new DurableTimerTask(_fireAt), context: context, noWait: false,
                output: _ => { Assert.True(false, "Unexpected output"); },
                onFailure: _ => { });
            Assert.Equal(_shouldNotHitTime, context.CurrentUtcDateTime);
        }
示例#8
0
        public void ValidateTask_Throws_WhenActivityFunctionHasNoProperBinding(
            string bindingType, BindingInfo.Types.Direction bindingDirection)
        {
            var history = CreateHistory(scheduled: false, completed: false, output: InvocationResultJson);
            var orchestrationContext = new OrchestrationContext {
                History = history
            };

            var loadedFunctions = new[]
            {
                DurableTestUtilities.CreateFakeAzFunctionInfo(FunctionName, "fakeTriggerBindingName", bindingType, bindingDirection)
            };

            var durableTaskHandler = new DurableTaskHandler();

            var exception =
                Assert.Throws <InvalidOperationException>(
                    () => ActivityInvocationTask.ValidateTask(
                        new ActivityInvocationTask(FunctionName, FunctionInput), loadedFunctions));

            Assert.Contains(FunctionName, exception.Message);
            Assert.Contains(ActivityTriggerBindingType, exception.Message);

            DurableTestUtilities.VerifyNoActionAdded(orchestrationContext);
        }
示例#9
0
        public void CurrentUtcDateTime_InitializesToFirstOrchestratorStartedTimestamp_IfOrchestratorInvoked(bool firstExecution, bool completed)
        {
            var history = CreateOrchestratorStartedHistory(startTime: _startTime, isProcessed: false);
            var context = new OrchestrationContext {
                History = history
            };

            if (!firstExecution)
            {
                // Assumes that a context, when passed to OrchestrationInvoker, has all HistoryEvents' IsProcessed reset to false
                history = DurableTestUtilities.MergeHistories(
                    history,
                    CreateActivityHistory(name: FunctionName,
                                          scheduled: true,
                                          completed: true,
                                          output: InvocationResultJson,
                                          date: _restartTime,
                                          orchestratorStartedIsProcessed: false)
                    );
                context.CurrentUtcDateTime = _restartTime;
            }
            _orchestrationBindingInfo = new OrchestrationBindingInfo("ContextParameterName", context);

            InvokeOrchestration(completed: completed);

            Assert.Equal(_orchestrationBindingInfo.Context.History.FirstOrDefault(
                             (e) => e.EventType == HistoryEventType.OrchestratorStarted).Timestamp,
                         _orchestrationBindingInfo.Context.CurrentUtcDateTime);
        }
示例#10
0
        private static void VerifyCallActivityActionAdded(OrchestrationContext orchestrationContext)
        {
            var actions = DurableTestUtilities.GetCollectedActions(orchestrationContext);
            var action  = (CallActivityAction)actions.Single();

            Assert.Equal(FunctionName, action.FunctionName);
            Assert.Equal(FunctionInput, action.Input);
        }
        public void InvocationRunsToCompletionIfNotStopped()
        {
            var invocationAsyncResult = DurableTestUtilities.CreateInvocationResult(completed: true);

            DurableTestUtilities.ExpectBeginInvoke(_mockPowerShellServices, invocationAsyncResult);

            _orchestrationInvoker.Invoke(_orchestrationBindingInfo, _mockPowerShellServices.Object);

            _mockPowerShellServices.Verify(_ => _.BeginInvoke(It.IsAny <PSDataCollection <object> >()), Times.Once);
            _mockPowerShellServices.Verify(_ => _.EndInvoke(invocationAsyncResult), Times.Once);
            _mockPowerShellServices.Verify(_ => _.ClearStreamsAndCommands(), Times.Once);
            _mockPowerShellServices.VerifyNoOtherCalls();
        }
示例#12
0
        public void CurrentUtcDateTime_UpdatesToNextOrchestratorStartedTimestamp_IfActivityFunctionCompleted(bool completed)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(startTime: _startTime, isProcessed: true),
                CreateActivityHistory(
                    name: FunctionName,
                    scheduled: true,
                    completed: completed,
                    output: InvocationResultJson,
                    date: _restartTime,
                    orchestratorStartedIsProcessed: false)
                );

            OrchestrationContext context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };
            var durableTaskHandler = new DurableTaskHandler();
            var allOutput          = new List <object>();

            if (completed)
            {
                history = DurableTestUtilities.MergeHistories(history, CreateActivityHistory(
                                                                  name: FunctionName,
                                                                  scheduled: true,
                                                                  completed: true,
                                                                  output: InvocationResultJson,
                                                                  date: _shouldNotHitTime,
                                                                  orchestratorStartedIsProcessed: false));
            }
            else
            {
                DurableTestUtilities.EmulateStop(durableTaskHandler);
            }

            durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                new ActivityInvocationTask(FunctionName, FunctionInput), context, noWait: false,
                output: output => allOutput.Add(output), onFailure: _ => { });
            if (completed)
            {
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }
            else
            {
                Assert.Equal(_startTime, context.CurrentUtcDateTime);
            }
        }
示例#13
0
        public void CurrentUtcDateTime_UpdatesToNextOrchestratorStartedTimestamp_IfTimestampsAreIdentical()
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateActivityHistory(
                    name: FunctionName,
                    scheduled: true,
                    completed: true,
                    date: _startTime,
                    output: InvocationResultJson,
                    orchestratorStartedIsProcessed: true),
                CreateActivityHistory(
                    name: FunctionName,
                    scheduled: true,
                    completed: true,
                    date: _startTime,
                    output: InvocationResultJson,
                    orchestratorStartedIsProcessed: false),
                CreateActivityHistory(
                    name: FunctionName,
                    scheduled: true,
                    completed: true,
                    date: _shouldNotHitTime,
                    output: InvocationResultJson,
                    orchestratorStartedIsProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };
            var willHitEvent = context.History.First(
                e => e.EventType == HistoryEventType.OrchestratorStarted &&
                e.IsProcessed);
            var allOutput          = new List <object>();
            var durableTaskHandler = new DurableTaskHandler();

            durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                new ActivityInvocationTask(FunctionName, FunctionInput), context, noWait: false,
                output: output => allOutput.Add(output), onFailure: _ => { });

            Assert.Equal(_startTime, context.CurrentUtcDateTime);
            var shouldNotHitEvent = context.History.First(
                e => e.Timestamp.Equals(_shouldNotHitTime));

            Assert.True(willHitEvent.IsProcessed);
            Assert.False(shouldNotHitEvent.IsProcessed);
        }
示例#14
0
        public void StopAndInitiateDurableTaskOrReplay_OutputsNothing_IfActivityNotCompleted(
            bool scheduled, bool completed)
        {
            var history = CreateHistory(scheduled: scheduled, completed: completed, output: InvocationResultJson);
            var orchestrationContext = new OrchestrationContext {
                History = history
            };

            var durableTaskHandler = new DurableTaskHandler();

            DurableTestUtilities.EmulateStop(durableTaskHandler);

            durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                new ActivityInvocationTask(FunctionName, FunctionInput), orchestrationContext, noWait: false,
                _ => { Assert.True(false, "Unexpected output"); });

            VerifyCallActivityActionAdded(orchestrationContext);
        }
示例#15
0
        public void CreateTimerOrContinue_WaitsUntilTimerFires(bool timerScheduledAndFired, bool expectedWaitForStop)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateTimerFiredHistory(timerScheduledAndFired: timerScheduledAndFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };

            VerifyWaitForTimerFired(
                durableTimer: _durableTimer,
                durationSeconds: _longInterval,
                expectedWaitForStop: expectedWaitForStop,
                () =>
            {
                _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt);
            });
        }
示例#16
0
        public void StopAndCreateTimerOrContinue_OutputsNothing_IfNoWaitNotRequested(bool timerCreated, bool timerFired)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: timerCreated, timerFired: timerFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false)
                );

            var context = new OrchestrationContext {
                History = history
            };

            if (!timerCreated)
            {
                EmulateStop(_durableTimer);
            }

            _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt, noWait: false, _ => { Assert.True(false, "Unexpected output"); });
            VerifyCreateDurableTimerActionAdded(context, _fireAt);
        }
示例#17
0
        public void StopAndInitiateDurableTaskOrReplay_OutputsNothing_IfNoWaitNotRequested(bool timerCreated, bool timerFired)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: timerCreated, timerFired: timerFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history
            };

            var durableTaskHandler = new DurableTaskHandler();

            if (!timerCreated || !timerFired)
            {
                DurableTestUtilities.EmulateStop(durableTaskHandler);
            }

            durableTaskHandler.StopAndInitiateDurableTaskOrReplay(task: new DurableTimerTask(_fireAt), context: context, noWait: false, _ => { Assert.True(false, "Unexpected output"); });
            VerifyCreateDurableTimerActionAdded(context, _fireAt);
        }
示例#18
0
        public void StopAndInitiateDurableTaskOrReplay_WaitsForStop_IfActivityNotCompleted(bool scheduledAndCompleted, bool expectedWaitForStop)
        {
            var durableTaskHandler = new DurableTaskHandler();

            var history = CreateHistory(
                scheduled: scheduledAndCompleted, completed: scheduledAndCompleted, output: InvocationResultJson);

            var orchestrationContext = new OrchestrationContext {
                History = history
            };

            DurableTestUtilities.VerifyWaitForDurableTasks(
                durableTaskHandler,
                _delayBeforeStopping,
                expectedWaitForStop,
                () =>
            {
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(
                    new ActivityInvocationTask(FunctionName, FunctionInput), orchestrationContext, noWait: false, _ => { });
            });
        }
示例#19
0
        public void StopAndCreateTimerOrContinue_WaitsUntilTimerFires_IfNoWaitNotRequested(bool timerCreated, bool timerFired, bool expectedWaitForStop)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: timerCreated, timerFired: timerFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false)
                );
            var context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };

            var durableTaskHandler = new DurableTaskHandler();

            DurableTestUtilities.VerifyWaitForDurableTasks(
                durableTaskHandler,
                delayBeforeStopping: _longInterval,
                expectedWaitForStop: expectedWaitForStop,
                () =>
            {
                durableTaskHandler.StopAndInitiateDurableTaskOrReplay(task: new DurableTimerTask(_fireAt), context: context, noWait: false, _ => { Assert.True(false, "Unexpected output"); });
            });
        }
示例#20
0
        public void StopAndCreateTimerOrContinue_ContinuesToNextTimer_IfTimersHaveIdenticalFireAt()
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _shouldNotHitTime, orchestratorStartedIsProcessed: false)
                );

            var context = new OrchestrationContext {
                History = history
            };

            for (int i = 0; i < 2; i++)
            {
                _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt, noWait: false, _ => { });
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }

            _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt, noWait: false, _ => { });
            Assert.Equal(_shouldNotHitTime, context.CurrentUtcDateTime);
        }
        public void WaitAny_OutputsEarliestCompletedTask_WhenAnyTaskCompleted(bool completed)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateActivityHistory("FunctionA", scheduled: true, restartTime: _restartTime, completed: completed, output: "\"Result1\"", orchestratorStartedIsProcessed: false),
                CreateActivityHistory("FunctionA", scheduled: false, completed: false, output: "\"Result2\""),
                CreateDurableTimerHistory(timerCreated: true, timerFired: true, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false)
                );

            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var firedTimer        = new DurableTimerTask(_fireAt);
            var completedActivity = new ActivityInvocationTask("FunctionA", FunctionInput);
            var tasksToWaitFor    =
                new ReadOnlyCollection <DurableTask>(
                    new DurableTask[] {
                completedActivity,
                new ActivityInvocationTask("FunctionA", FunctionInput),
                firedTimer
            });

            var allOutput = new List <object>();

            var durableTaskHandler = new DurableTaskHandler();

            durableTaskHandler.WaitAny(tasksToWaitFor, orchestrationContext, output => { allOutput.Add(output); });

            if (completed)
            {
                Assert.Equal(new[] { completedActivity }, allOutput);
            }
            else
            {
                Assert.Equal(new[] { firedTimer }, allOutput);
            }
            VerifyNoOrchestrationActionAdded(orchestrationContext);
        }
示例#22
0
        public void CreateTimerOrContinue_UpdatesCurrentUtcDateTimeToNextOrchestratorStartedTimestamp_OnlyIfTimerCreatedAndFired(bool timerScheduledAndFired)
        {
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateTimerFiredHistory(timerScheduledAndFired: timerScheduledAndFired, fireAt: _fireAt, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateOrchestratorStartedHistory(date: _shouldNotHitTime, isProcessed: false)
                );
            OrchestrationContext context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };

            if (!timerScheduledAndFired)
            {
                EmulateStop(_durableTimer);
                _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt);
                Assert.Equal(_startTime, context.CurrentUtcDateTime);
            }
            else
            {
                _durableTimer.StopAndCreateTimerOrContinue(context: context, fireAt: _fireAt);
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }
        }
        public void WaitAll_OutputsTaskResults_WhenAllTasksCompleted(
            bool scheduled, bool completed)
        {
            var history = DurableTestUtilities.MergeHistories(
                // Emulate invoking the same function (FunctionA) twice. This is to make sure that
                // both invocations are accounted for, and both results are preserved separately.
                // Without this test, the history lookup algorithm in the WaitForActivityTasks method
                // could just look for the the first history event by function name, and this error
                // would not be detected.
                CreateOrchestratorStartedHistory(date: _startTime, isProcessed: true),
                CreateActivityHistory("FunctionA", scheduled: scheduled, completed: completed, output: "\"Result1\""),
                CreateActivityHistory("FunctionA", scheduled: scheduled, completed: completed, output: "\"Result2\""),
                CreateDurableTimerHistory(timerCreated: scheduled, timerFired: completed, fireAt: _fireAt, _restartTime, orchestratorStartedIsProcessed: false),
                CreateActivityHistory("FunctionB", scheduled: scheduled, completed: completed, output: "\"Result3\"")
                );

            var orchestrationContext = new OrchestrationContext {
                History = history
            };
            var tasksToWaitFor =
                new ReadOnlyCollection <DurableTask>(
                    new DurableTask[] {
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new ActivityInvocationTask("FunctionA", FunctionInput),
                new DurableTimerTask(_fireAt),
                new ActivityInvocationTask("FunctionB", FunctionInput)
            });

            var allOutput = new List <object>();

            var durableTaskHandler = new DurableTaskHandler();

            durableTaskHandler.WaitAll(tasksToWaitFor, orchestrationContext, output => { allOutput.Add(output); });

            Assert.Equal(new[] { "Result1", "Result2", "Result3" }, allOutput);
            VerifyNoOrchestrationActionAdded(orchestrationContext);
        }
示例#24
0
        private void VerifyWaitForTimerFired(
            DurableTimer durableTimer,
            TimeSpan durationSeconds,
            bool expectedWaitForStop,
            Action action
            )
        {
            var delayBeforeStopping = durationSeconds;

            // action() call may block until Stop is invoked from another thread.
            var thread = new Thread(() =>
            {
                Thread.Sleep(delayBeforeStopping);
                durableTimer.Stop();
            });

            thread.Start();
            try
            {
                var elapsedMilliseconds = DurableTestUtilities.MeasureExecutionTimeInMilliseconds(action);

                // Check if CreateTimerOrContinue was actually blocked
                if (expectedWaitForStop)
                {
                    Assert.True(elapsedMilliseconds > delayBeforeStopping.TotalMilliseconds * 0.8);
                }
                else
                {
                    Assert.True(elapsedMilliseconds < delayBeforeStopping.TotalMilliseconds * 0.2);
                }
            }
            finally
            {
                thread.Join();
            }
        }
示例#25
0
        public void CurrentUtcDateTime_UpdatesToNextOrchestratorStartedTimestamp_IfAnyActivitiesCompleted_WhenWaitAnyIsCalled(bool anyCompleted)
        {
            var activityFunctions = new Dictionary <string, bool>();

            activityFunctions.Add("FunctionA", false);
            activityFunctions.Add("FunctionB", anyCompleted);
            activityFunctions.Add("FunctionC", false);
            var history = DurableTestUtilities.MergeHistories(
                CreateOrchestratorStartedHistory(startTime: _startTime, isProcessed: true),
                CreateNoWaitActivityHistory(scheduled: activityFunctions, restartTime: _restartTime, orchestratorStartedIsProcessed: false),
                CreateOrchestratorStartedHistory(startTime: _shouldNotHitTime, isProcessed: false)
                );
            OrchestrationContext context = new OrchestrationContext {
                History = history, CurrentUtcDateTime = _startTime
            };
            var tasksToWaitFor = new ReadOnlyCollection <ActivityInvocationTask>(
                new[] { "FunctionA", "FunctionB", "FunctionC" }.Select(name => new ActivityInvocationTask(name, FunctionInput)).ToArray());
            var durableTaskHandler = new DurableTaskHandler();
            var allOutput          = new List <object>();

            if (!anyCompleted)
            {
                DurableTestUtilities.EmulateStop(durableTaskHandler);
            }

            durableTaskHandler.WaitAny(tasksToWaitFor, context, output => allOutput.Add(output));

            if (anyCompleted)
            {
                Assert.Equal(_restartTime, context.CurrentUtcDateTime);
            }
            else
            {
                Assert.Equal(_startTime, context.CurrentUtcDateTime);
            }
        }
示例#26
0
 private Hashtable InvokeOrchestration(bool completed, PSDataCollection <object> output = null)
 {
     return(DurableTestUtilities.InvokeOrchestration(_orchestrationInvoker, _orchestrationBindingInfo, _mockPowerShellServices, completed, output));
 }
        public static void VerifyNoActionAdded(OrchestrationContext orchestrationContext)
        {
            var actions = DurableTestUtilities.GetCollectedActions(orchestrationContext);

            Assert.Empty(actions);
        }