示例#1
0
        public void Throws_exception_when_hosted_workflow_is_not_found()
        {
            var hostedWorkflow  = new TestWorkflow1();
            var hostedWorkflows = new WorkflowHost(_domain, new[] { hostedWorkflow });

            Assert.Throws <WorkflowNotHostedException>(() => hostedWorkflows.FindBy("TestWorkflow2", "2.0"));
        }
示例#2
0
        public void By_default_execution_exceptions_are_unhandled()
        {
            var workflowTasks   = WorkflowTask.CreateFor(DecisionTasksWithSignalEvents("token"), _domain);
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new WorkflowThrowsExceptionOnSignal(new ApplicationException("")) });

            Assert.ThrowsAsync <ApplicationException>(async() => await workflowTasks.ExecuteForAsync(hostedWorkflows));
        }
        internal static WorkflowHost Get()
        {
            var connectionString = WebSettings.GetInstanceStoreConnectionString();
            var host             = new WorkflowHost(connectionString);

            return(host);
        }
示例#4
0
        public static void Run()
        {
            WorkflowHost host = new WorkflowHost();
            ServiceHost service = new ServiceHost(host);
            service.Open();

            Console.ReadLine();
        }
示例#5
0
        public void Status_is_set_to_stopped_when_workflow_host_is_stopped_execution()
        {
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new TestWorkflow1() });

            hostedWorkflows.StartExecution(new TaskList("name"));
            hostedWorkflows.StopExecution();
            Assert.That(hostedWorkflows.Status, Is.EqualTo(HostStatus.Stopped));
        }
示例#6
0
 public void Status_is_set_to_executing_when_workflow_host_is_executing()
 {
     using (var hostedWorkflows = new WorkflowHost(_domain, new[] { new TestWorkflow1() }))
     {
         hostedWorkflows.StartExecution(new TaskList("name"));
         Assert.That(hostedWorkflows.Status, Is.EqualTo(HostStatus.Executing));
     }
 }
示例#7
0
        public void Invalid_error_handler_argument_tests()
        {
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new TestWorkflow1() });

            Assert.Throws <ArgumentNullException>(() => hostedWorkflows.OnError(null));
            Assert.Throws <ArgumentNullException>(() => hostedWorkflows.OnResponseError(null));
            Assert.Throws <ArgumentNullException>(() => hostedWorkflows.OnPollingError(null));
        }
示例#8
0
        public async Task Setup()
        {
            _domain        = new TestDomain();
            _emptyWorkflow = new EmptyWorkflow();
            _workflowHost  = await _domain.Host(_emptyWorkflow);

            _taskListName = Guid.NewGuid().ToString();
            _workflowHost.StartExecution(new TaskList(_taskListName));
        }
示例#9
0
        public async Task On_execution_send_decisions_to_amazon_swf()
        {
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new WorkflowCompleteOnSignal("result") });
            var workflowTasks   = WorkflowTask.CreateFor(DecisionTasksWithSignalEvents("token"), _domain);

            await workflowTasks.ExecuteForAsync(hostedWorkflows);

            AssertThatInterpretedDecisionsAreSentOverWorkflowClient("token", Times.Once());
        }
示例#10
0
        public void Returns_matching_hosted_workflow_by_name_and_version()
        {
            var hostedWorkflow1 = new TestWorkflow1();
            var hostedWorkflow2 = new TestWorkflow2();
            var hostedWorkflows = new WorkflowHost(_domain, new Workflow[] { hostedWorkflow1, hostedWorkflow2 });

            Assert.That(hostedWorkflows.FindBy("TestWorkflow1", "2.0"), Is.EqualTo(hostedWorkflow1));
            Assert.That(hostedWorkflows.FindBy("TestWorkflow2", "1.0"), Is.EqualTo(hostedWorkflow2));
        }
示例#11
0
        public async Task Throws_exception_when_workflow_history_events_are_queried_after_execution()
        {
            var hostedWorkflow  = new WorkflowCompleteOnSignal();
            var hostedWorkflows = new WorkflowHost(_domain, new[] { hostedWorkflow });
            var workflowTasks   = WorkflowTask.CreateFor(DecisionTasksWithSignalEvents("token"), _domain);
            await workflowTasks.ExecuteForAsync(hostedWorkflows);

            Assert.Throws <InvalidOperationException>(() => hostedWorkflow.AccessHistoryEvents());
        }
示例#12
0
        public async Task Execution_exception_can_handled_to_retry()
        {
            var workflowTasks   = WorkflowTask.CreateFor(DecisionTasksWithSignalEvents("token"), _domain);
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new WorkflowThrowsExceptionOnSignal(new ApplicationException("")) });

            workflowTasks.OnExecutionError(ErrorHandler.Default(e => ErrorAction.Retry));

            await workflowTasks.ExecuteForAsync(hostedWorkflows);

            AssertThatInterpretedDecisionsAreSentOverWorkflowClient("token", Times.Once());
        }
示例#13
0
        void CreateHost()
        {
            _host = Catalog.Preconfigure()
                    .Add(WorkflowConfiguration.WorkflowDataRepositoryKey, "Workflow")
                    .Add(WorkflowConfiguration.WorkflowMessagingKey, "Workflow")
                    .Add(WorkflowConfiguration.WorkflowWorkspaceKey, "Workflow")
                    .ConfiguredCreate(() => new WorkflowHost());

            _host.Initialize(_cts.Token);
            _host.OnStart();
        }
示例#14
0
        public void Status_is_set_to_faulted_when_workflow_host_can_not_handle_exception()
        {
            _simpleWorkflow.Setup(s => s.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(),
                                                                  It.IsAny <CancellationToken>())).Throws <Exception>();

            var hostedWorkflows = new WorkflowHost(_domain, new[] { new TestWorkflow1() });

            hostedWorkflows.OnError(e => ErrorAction.Unhandled);
            hostedWorkflows.StartExecution(new TaskList("name"));
            hostedWorkflows.StopExecution();
            Assert.That(hostedWorkflows.Status, Is.EqualTo(HostStatus.Faulted));
        }
示例#15
0
        public void Poll_on_default_task_list_when_multiple_workflows_have_same_defautl_task_list()
        {
            var @pollingEvent = PollingEvent();

            using (var host = new WorkflowHost(_domain, new Workflow[] { new TestWorkflow2(), new TestWorkflow3() }))
            {
                host.PollingIdentity = TaskList;
                host.StartExecution();
                @pollingEvent.WaitOne();
            }

            AssertThatSWFIsPolledWithDefaultTaskList();
        }
示例#16
0
        public async Task Response_exception_can_be_handled_to_continue()
        {
            _amazonWorkflowClient.SetupSequence(c => c.RespondDecisionTaskCompletedAsync(It.IsAny <RespondDecisionTaskCompletedRequest>(), It.IsAny <CancellationToken>()))
            .Throws(new UnknownResourceException("msg"))
            .Returns(Task.FromResult(new RespondDecisionTaskCompletedResponse()));
            var hostedWorkflows = new WorkflowHost(_domain, new[] { new WorkflowCompleteOnSignal() });

            hostedWorkflows.OnResponseError(e => ErrorAction.Continue);
            var workflowTasks = WorkflowTask.CreateFor(DecisionTasksWithSignalEvents("token"), _domain);

            await workflowTasks.ExecuteForAsync(hostedWorkflows);

            AssertThatInterpretedDecisionsAreSentOverWorkflowClient("token", Times.Once());
        }
示例#17
0
        public async Task Can_schedule_the_activity_with_custom_input()
        {
            var @event   = new ManualResetEvent(false);
            var workflow = new WorkflowToScheduleActivityWithCustomInput("activity input");

            workflow.Closed += (s, e) => @event.Set();
            _workflowHost    = await HostAsync(workflow);

            await _domain.StartWorkflow <WorkflowToScheduleActivityWithCustomInput>("input", _taskListName);

            @event.WaitOne();

            Assert.That(TestActivityWithInput.Input, Is.EqualTo("activity input"));
        }
示例#18
0
        public async Task Failed_activity_can_be_retried_after_time_out()
        {
            var  @event        = new ManualResetEvent(false);
            uint retryAttempts = 2;
            var  workflow      = new WorkflowToRetryActivityAfterTimeout(retryAttempts);

            workflow.Failed += (s, e) => @event.Set();
            _workflowHost    = await HostAsync(workflow);

            await _domain.StartWorkflow <WorkflowToRetryActivityImmediately>("input", _taskListName);

            @event.WaitOne();

            Assert.That(FailingActivity.ExecutionTimes, Is.EqualTo(retryAttempts + 1));
        }
示例#19
0
        public async Task By_default_schedule_the_activity_with_workflow_input()
        {
            var @event   = new ManualResetEvent(false);
            var workflow = new WorkflowWithMultipleParent();

            workflow.Closed += (s, e) => @event.Set();
            _workflowHost    = await HostAsync(workflow);

            await _domain.StartWorkflow <WorkflowWithMultipleParent>("input", _taskListName);

            @event.WaitOne();

            Assert.That(SendEmailActivity.Input.File1, Is.EqualTo("TranscodedPathMP4"));
            Assert.That(SendEmailActivity.Input.File2, Is.EqualTo("TranscodedPathAV"));
        }
示例#20
0
        public void Raise_faulted_event_on_unhandled_exception()
        {
            var expectedException = new Exception();

            _simpleWorkflow.Setup(s => s.PollForDecisionTaskAsync(It.IsAny <PollForDecisionTaskRequest>(),
                                                                  It.IsAny <CancellationToken>())).Throws(expectedException);
            Exception actualException = null;
            var       hostedWorkflows = new WorkflowHost(_domain, new[] { new TestWorkflow1() });

            hostedWorkflows.OnError(e => ErrorAction.Unhandled);
            hostedWorkflows.OnFault += (s, e) => actualException = e.Exception;
            hostedWorkflows.StartExecution(new TaskList("name"));
            hostedWorkflows.StopExecution();
            Assert.That(actualException, Is.EqualTo(expectedException));
        }
示例#21
0
        public async Task Schedule_a_lambda_function()
        {
            var    @event   = new ManualResetEvent(false);
            var    workflow = new ScheduleLambdaWorkflow();
            string result   = "";

            workflow.Closed    += (s, e) => @event.Set();
            workflow.Completed += (s, e) => result = e.Result;
            _workflowHost       = await HostAsync(workflow);

            await _domain.StartWorkflow <ScheduleLambdaWorkflow>(new { Id = 10, Age = 20 }, _taskListName, _configuration["LambdaRole"]);

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("\"hotelbooked-10-20\""));
        }
示例#22
0
        public async Task Can_schedule_the_activity_with_custom_input_built_from_workflow_input()
        {
            var @event   = new ManualResetEvent(false);
            var workflow = new WorkflowToAccessDynamicInput();

            workflow.Closed += (s, e) => @event.Set();
            _workflowHost    = await HostAsync(workflow);

            var input = new { Name = "name", Age = 10 }.ToJson();

            await _domain.StartWorkflow <WorkflowToScheduleActivityWithCustomInput>(input, _taskListName);

            @event.WaitOne();

            Assert.That(TestActivityWithInput.Input, Is.EqualTo(input));
        }
示例#23
0
        public async Task By_default_failed_activity_fails_workflow()
        {
            var    @event   = new ManualResetEvent(false);
            var    workflow = new WorkflowWithNoRetry();
            string reason   = null;
            string details  = null;

            workflow.Failed += (s, e) => { reason = e.Reason; details = e.Details; @event.Set(); };
            _workflowHost    = await HostAsync(workflow);

            await _domain.StartWorkflow <WorkflowWithNoRetry>("input", _taskListName);

            @event.WaitOne();

            Assert.That(reason, Is.EqualTo(typeof(IOException).Name));
            Assert.That(details, Is.EqualTo("Failed to write to disk."));
        }
示例#24
0
        public async Task Wait_for_a_signal_with_a_timeout_and_continue_on_timing_out_the_signal()
        {
            var    @event   = new AutoResetEvent(false);
            var    timeout  = TimeSpan.FromSeconds(3);
            var    workflow = new UserActivateWorkflowWithTimeout(@event, timeout);
            string reason   = null;

            workflow.Failed += (s, e) => { reason = e.Reason; @event.Set(); };
            _workflowHost    = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <UserActivateWorkflow>("input", _taskListName);

            @event.WaitOne();
            @event.WaitOne(timeout.Add(TimeSpan.FromSeconds(2)));

            Assert.That(reason, Is.EqualTo("Signal_timeout"));
        }
        public async Task Wait_for_any_signal_with_timeout_and_continue_with_timeout()
        {
            var    @event   = new AutoResetEvent(false);
            var    timeout  = TimeSpan.FromSeconds(2);
            var    workflow = new ExpenseAnySignalWorkflowWithTimeout(@event, timeout);
            string result   = null;

            workflow.Failed += (s, e) => { result = e.Reason; @event.Set(); };
            _workflowHost    = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <ExpenseAnySignalWorkflowWithTimeout>("input", _taskListName, _configuration["LambdaRole"]);

            @event.WaitOne();

            @event.WaitOne(timeout.Add(TimeSpan.FromSeconds(3)));

            Assert.That(result, Is.EqualTo("Signal_timedout"));
        }
        public async Task Wait_for_rejected_signal_to_continue()
        {
            var    @event   = new AutoResetEvent(false);
            var    workflow = new ExpenseAnySignalWorkflow(@event);
            string result   = null;

            workflow.Completed += (s, e) => { result = e.Result; @event.Set(); };
            _workflowHost       = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <ExpenseAnySignalWorkflow>("input", _taskListName, _configuration["LambdaRole"]);

            @event.WaitOne();

            await _domain.SendSignal(workflowId, "Rejected", "");

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("\"EmpAction\""));
        }
示例#27
0
        public async Task On_signal_can_schedule_paused_workflow()
        {
            var    @event   = new AutoResetEvent(false);
            var    workflow = new WorkflowWithMultipleParent(@event);
            string result   = null;

            workflow.Completed += (s, e) => { result = e.Result; @event.Set(); };
            _workflowHost       = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <WorkflowWithMultipleParent>("input", _taskListName);

            @event.WaitOne();

            await _domain.SendSignal(workflowId, "InventoryFilled", "Enough");

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("Item is on the way"));
        }
示例#28
0
        public async Task Wait_for_a_signal_to_reschedule()
        {
            var    @event   = new AutoResetEvent(false);
            var    workflow = new OrderWorkflow(@event);
            string result   = null;

            workflow.Completed += (s, e) => { result = e.Result; @event.Set(); };
            _workflowHost       = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <OrderWorkflow>("input", _taskListName);

            @event.WaitOne();

            await _domain.SendSignal(workflowId, "ItemsArrived", "");

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("Charged"));
        }
示例#29
0
        public async Task Schedule_child_workflow()
        {
            var    @event   = new ManualResetEvent(false);
            string result   = null;
            var    workflow = new ParentWorkflow();

            workflow.Completed += (s, e) =>
            {
                result = e.Result;
                @event.Set();
            };
            _workflowHost = await HostAsync(workflow, new ChildWorkflow());

            await _domain.StartWorkflow <ParentWorkflow>("input", _taskListName);

            @event.WaitOne();

            Assert.That(result, Is.EqualTo(ActivityResult));
        }
        public async Task Wait_for_any_signal_with_timeout_and_continue_with_approved_signal()
        {
            var    @event   = new AutoResetEvent(false);
            var    workflow = new ExpenseAnySignalWorkflowWithTimeout(@event, TimeSpan.FromSeconds(2));
            string result   = null;

            workflow.Completed += (s, e) => { result = e.Result; @event.Set(); };
            _workflowHost       = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <ExpenseAnySignalWorkflowWithTimeout>("input", _taskListName, _configuration["LambdaRole"]);

            @event.WaitOne();

            await _domain.SendSignal(workflowId, "Approved", "");

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("\"AccountDone\""));
        }
示例#31
0
        public async Task Wait_for_a_signal_to_continue()
        {
            var    @event   = new AutoResetEvent(false);
            var    workflow = new UserActivateWorkflow(@event);
            string result   = null;

            workflow.Completed += (s, e) => { result = e.Result; @event.Set(); };
            _workflowHost       = await HostAsync(workflow);

            var workflowId = await _domain.StartWorkflow <UserActivateWorkflow>("input", _taskListName);

            @event.WaitOne();

            await _domain.SendSignal(workflowId, "EmailConfirmed", "");

            @event.WaitOne();

            Assert.That(result, Is.EqualTo("Activated"));
        }