public async Task MultipleInstanceStoreTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            OrchestrationInstance id1 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      "WAIT_THROW");

            OrchestrationInstance id2 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      "WAIT_DONTTHROW");

            await TestHelpers.WaitForInstanceAsync(client, id1, 60, false);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60, false);

            OrchestrationState runtimeState1 = await client.GetOrchestrationStateAsync(id1);

            OrchestrationState runtimeState2 = await client.GetOrchestrationStateAsync(id2);

            Assert.AreEqual(OrchestrationStatus.Pending, runtimeState1.OrchestrationStatus);
            Assert.AreEqual(OrchestrationStatus.Pending, runtimeState2.OrchestrationStatus);

            await TestHelpers.WaitForInstanceAsync(client, id1, 60);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60);

            runtimeState1 = await client.GetOrchestrationStateAsync(id1);

            runtimeState2 = await client.GetOrchestrationStateAsync(id2);

            Assert.AreEqual(OrchestrationStatus.Failed, runtimeState1.OrchestrationStatus);
            Assert.AreEqual(OrchestrationStatus.Completed, runtimeState2.OrchestrationStatus);
        }
예제 #2
0
        public async Task GenerationSubFailedTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(GenerationSubFailedParentOrchestration),
                                                typeof(GenerationSubFailedChildOrchestration))
            .AddTaskActivities(new GenerationBasicTask())
            .StartAsync();

            taskHub.TaskOrchestrationDispatcher.IncludeDetails = true;

            GenerationSubFailedChildOrchestration.Count   = 0;
            GenerationSubFailedParentOrchestration.Result = null;
            OrchestrationInstance id =
                await client.CreateOrchestrationInstanceAsync(typeof(GenerationSubFailedParentOrchestration), true);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));

            Assert.AreEqual("Test", GenerationSubFailedParentOrchestration.Result, "Orchestration Result is wrong!!!");
            Assert.AreEqual(1, GenerationSubFailedChildOrchestration.Count, "Child Workflow Count invalid.");

            GenerationSubFailedChildOrchestration.Count   = 0;
            GenerationSubFailedParentOrchestration.Result = null;
            id = await client.CreateOrchestrationInstanceAsync(typeof(GenerationSubFailedParentOrchestration), false);

            isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual("Test", GenerationSubFailedParentOrchestration.Result, "Orchestration Result is wrong!!!");
            Assert.AreEqual(5, GenerationSubFailedChildOrchestration.Count, "Child Workflow Count invalid.");
        }
        public async Task BasicInstanceStoreTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                     "DONT_THROW");

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            OrchestrationState runtimeState = await client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(runtimeState.OrchestrationStatus, OrchestrationStatus.Completed);
            Assert.AreEqual(runtimeState.OrchestrationInstance.InstanceId, id.InstanceId);
            Assert.AreEqual(runtimeState.OrchestrationInstance.ExecutionId, id.ExecutionId);
            Assert.AreEqual("DurableTask.ServiceBus.Tests.OrchestrationHubTableClientTests+InstanceStoreTestOrchestration", runtimeState.Name);
            Assert.AreEqual(runtimeState.Version, string.Empty);
            Assert.AreEqual(runtimeState.Input, "\"DONT_THROW\"");
            Assert.AreEqual(runtimeState.Output, "\"Spartacus\"");

            string history = await client.GetOrchestrationHistoryAsync(id);

            Assert.IsTrue(!string.IsNullOrEmpty(history));
            Assert.IsTrue(history.Contains("ExecutionStartedEvent"));
        }
        public async Task IntermediateStateInstanceStoreTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                     "WAIT");

            await TestHelpers.WaitForInstanceAsync(client, id, 60, false);

            OrchestrationState runtimeState = await client.GetOrchestrationStateAsync(id);

            Assert.IsNotNull(runtimeState);
            Assert.AreEqual(OrchestrationStatus.Pending, runtimeState.OrchestrationStatus);
            Assert.AreEqual(id.InstanceId, runtimeState.OrchestrationInstance.InstanceId);
            Assert.AreEqual(id.ExecutionId, runtimeState.OrchestrationInstance.ExecutionId);
            Assert.AreEqual("DurableTask.ServiceBus.Tests.OrchestrationHubTableClientTests+InstanceStoreTestOrchestration", runtimeState.Name);
            Assert.AreEqual(runtimeState.Version, string.Empty);
            Assert.AreEqual(runtimeState.Input, "\"WAIT\"");
            Assert.AreEqual(runtimeState.Output, null);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            runtimeState = await client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(runtimeState.OrchestrationStatus, OrchestrationStatus.Completed);
        }
예제 #5
0
        public async Task SessionExceededLimitNoCompressionTest()
        {
            string input = TestUtils.GenerateRandomString(150 * 1024);

            ServiceBusOrchestrationService serviceBusOrchestrationService =
                taskHub.orchestrationService as ServiceBusOrchestrationService;

            serviceBusOrchestrationService.Settings.TaskOrchestrationDispatcherSettings.CompressOrchestrationState =
                false;

            await taskHub.AddTaskOrchestrations(typeof(LargeSessionOrchestration))
            .AddTaskActivities(typeof(LargeSessionTaskActivity))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(LargeSessionOrchestration), new Tuple <string, int>(input, 2));

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60, true);

            await Task.Delay(20000);

            OrchestrationState state = await client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(OrchestrationStatus.Completed, state.OrchestrationStatus);
            Assert.AreEqual($"0:{input}-1:{input}-", LargeSessionOrchestration.Result);
        }
예제 #6
0
        public async Task ConcurrentSubOrchestrationsTest()
        {
            var c1 = new NameValueObjectCreator <TaskOrchestration>("UberOrchestration",
                                                                    "V1", typeof(UberOrchestration));

            var c2 = new NameValueObjectCreator <TaskOrchestration>("SleeperSubOrchestration",
                                                                    "V1", typeof(SleeperSubOrchestration));

            await taskHub.AddTaskOrchestrations(c1, c2)
            .StartAsync();

            int numSubOrchestrations = 60;

            OrchestrationInstance instance = await client.CreateOrchestrationInstanceAsync(
                "UberOrchestration",
                "V1",
                "TestInstance",
                new TestOrchestrationInput { Iterations = numSubOrchestrations, Payload = TestUtils.GenerateRandomString(90 * 1024) });

            // Waiting for 60 seconds guarantees that to pass the orchestrations must run in parallel
            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, instance, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, instance, 60));
            Assert.AreEqual(numSubOrchestrations, UberOrchestration.Result, "Orchestration Result is wrong!!!");
        }
        public async Task QueryMultiGenerationalTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            var instance1 = "apiservice1_upgrade1";

            OrchestrationInstance id1 = await this.client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                           instance1, "WAIT_NEWGEN");

            await TestHelpers.WaitForInstanceAsync(this.client, id1, 60);

            // completed apiService1 --> 1 result
            OrchestrationStateQuery query = new OrchestrationStateQuery().
                                            AddInstanceFilter("apiservice1", true).
                                            AddStatusFilter(OrchestrationStatus.Completed);

            IList <OrchestrationState> response = (await this.queryClient.QueryOrchestrationStatesAsync(query)).ToList();

            Assert.IsTrue(response.Count == 1);
            Assert.AreEqual(id1.InstanceId, response.First().OrchestrationInstance.InstanceId);

            // continuedAsNew apiService1 --> 2 results
            query = new OrchestrationStateQuery().
                    AddInstanceFilter("apiservice1", true).
                    AddStatusFilter(OrchestrationStatus.ContinuedAsNew);

            response = (await this.queryClient.QueryOrchestrationStatesAsync(query)).ToList();
            Assert.IsTrue(response.Count == 2);
        }
예제 #8
0
        public async Task RetryTimeoutTest()
        {
            var retryOptions = new RetryOptions(TimeSpan.FromSeconds(5), 10);

            retryOptions.BackoffCoefficient = 2;
            retryOptions.RetryTimeout       = TimeSpan.FromSeconds(10);

            var retryTask = new RetryTask(3);

            await this.taskHub.AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryName, RetryVersion,
                                                                                               () => new RetryOrchestration(retryOptions)))
            .AddTaskActivitiesFromInterface <IRetryTask>(retryTask)
            .StartAsync();

            RetryOrchestration.Result = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(RetryName, RetryVersion, false);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 60);

            Assert.IsNotNull(RetryOrchestration.Result);
            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 60));
            Assert.IsTrue(RetryOrchestration.Result.StartsWith("DoWork Failed. RetryCount is:"),
                          "Orchestration Result is wrong!!!. Result: " + RetryOrchestration.Result);
            Assert.IsTrue(retryTask.RetryCount < 4, "Retry Count is wrong. Count: " + retryTask.RetryCount);
        }
예제 #9
0
        public async Task MessageCompressionToNoCompressionTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(MessageCompressionCompatTest))
            .AddTaskActivities(typeof(AlternatingPayloadTask))
            .StartAsync();

            OrchestrationInstance id =
                await this.clientNoCompression.CreateOrchestrationInstanceAsync(typeof(MessageCompressionCompatTest), null);

            await Task.Delay(2000);

            await this.taskHub.StopAsync(true);

            await this.taskHubNoCompression.AddTaskOrchestrations(typeof(MessageCompressionCompatTest))
            .AddTaskActivities(typeof(AlternatingPayloadTask))
            .StartAsync();

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 60));

            OrchestrationState state = await this.client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(OrchestrationStatus.Completed, state.OrchestrationStatus);
        }
예제 #10
0
        public async Task MessageExceededLimitNoCompressionTest()
        {
            string input = TestUtils.GenerateRandomString(150 * 1024);

            var serviceBusOrchestrationService = this.client.ServiceClient as ServiceBusOrchestrationService;

            Debug.Assert(serviceBusOrchestrationService != null);

            serviceBusOrchestrationService.Settings.MessageCompressionSettings = new CompressionSettings
            {
                Style            = CompressionStyle.Never,
                ThresholdInBytes = 0
            };

            await this.taskHub.AddTaskOrchestrations(typeof(LargeSessionOrchestration))
            .AddTaskActivities(typeof(LargeSessionTaskActivity))
            .StartAsync();

            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(LargeSessionOrchestration), new Tuple <string, int>(input, 2));

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 60);

            Utils.UnusedParameter(isCompleted);
            await Task.Delay(20000);

            OrchestrationState state = await this.client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(OrchestrationStatus.Completed, state.OrchestrationStatus);
            Assert.AreEqual($"0:{input}-1:{input}-", LargeSessionOrchestration.Result);
        }
예제 #11
0
        public async Task RetryCustomHandlerFailTest()
        {
            var retryOptions = new RetryOptions(TimeSpan.FromSeconds(3), 3);

            retryOptions.Handle = e =>
            {
                Assert.IsInstanceOfType(e, typeof(TaskFailedException), "Exception is not TaskFailedException.");
                var taskFailed = (TaskFailedException)e;

                return(taskFailed.InnerException is ArgumentNullException);
            };

            var retryTask = new RetryTask(2);

            await this.taskHub.AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryName, RetryVersion,
                                                                                               () => new RetryOrchestration(retryOptions)))
            .AddTaskActivitiesFromInterface <IRetryTask>(retryTask)
            .StartAsync();

            RetryOrchestration.Result = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(RetryName, RetryVersion, false);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 90);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 90));
            Assert.AreEqual("DoWork Failed. RetryCount is: 1", RetryOrchestration.Result,
                            "Orchestration Result is wrong!!!");
            Assert.AreEqual(1, retryTask.RetryCount, "Retry Count is wrong");
        }
예제 #12
0
        public async Task SessionExceededTerminationLimitTest()
        {
            string input = TestUtils.GenerateRandomString(200 * 1024);

            await this.taskHub.AddTaskOrchestrations(typeof(LargeSessionOrchestration))
            .AddTaskActivities(typeof(LargeSessionTaskActivity))
            .StartAsync();

            var serviceBusOrchestrationService = this.taskHub.orchestrationService as ServiceBusOrchestrationService;

            Debug.Assert(serviceBusOrchestrationService != null);

            serviceBusOrchestrationService.Settings.SessionSettings = new ServiceBusSessionSettings(230 * 1024, 1024 * 1024);

            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(LargeSessionOrchestration), new Tuple <string, int>(input, 10));

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 60);

            Utils.UnusedParameter(isCompleted);
            await Task.Delay(20000);

            OrchestrationState state = await this.client.GetOrchestrationStateAsync(id);

            Assert.AreEqual(OrchestrationStatus.Terminated, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("exceeded"));
        }
예제 #13
0
        public async Task NonDeterminisActivitySubOrchestrationTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(NonDeterministicOrchestration), typeof(NonDeterministicActivityAndSubOrchestration))
            .AddTaskActivities(typeof(FirstTask), typeof(SecondTask))
            .StartAsync();

            this.taskHub.TaskActivityDispatcher.IncludeDetails = true;

            OrchestrationInstance instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicActivityAndSubOrchestration), "FAILTASK");

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            OrchestrationState state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Failed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("activity task"));
            Assert.IsTrue(state.Output.Contains("Was a change made to the orchestrator code after this instance had already started running?"));


            instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicOrchestration), "FAILSUBORCH");

            isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Failed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("sub-orchestration task"));
            Assert.IsTrue(state.Output.Contains("Was a change made to the orchestrator code after this instance had already started running?"));
        }
예제 #14
0
        public async Task SubOrchestrationFailedTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(ParentWorkflow2), typeof(ChildWorkflow2))
            .StartAsync();

            taskHub.TaskOrchestrationDispatcher.IncludeDetails = true;

            ChildWorkflow2.Count   = 0;
            ParentWorkflow2.Result = null;
            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(ParentWorkflow2), true);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));

            Assert.AreEqual("Test", ParentWorkflow2.Result, "Orchestration Result is wrong!!!");
            Assert.AreEqual(1, ChildWorkflow2.Count, "Child Workflow Count invalid.");

            ChildWorkflow2.Count   = 0;
            ParentWorkflow2.Result = null;
            id = await client.CreateOrchestrationInstanceAsync(typeof(ParentWorkflow2), false);

            isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual("Test", ParentWorkflow2.Result, "Orchestration Result is wrong!!!");
            Assert.AreEqual(5, ChildWorkflow2.Count, "Child Workflow Count invalid.");
        }
예제 #15
0
        public async Task RetryMaxIntervalTest()
        {
            var retryOptions = new RetryOptions(TimeSpan.FromSeconds(3), 3);

            retryOptions.BackoffCoefficient = 10;
            retryOptions.MaxRetryInterval   = TimeSpan.FromSeconds(5);

            var retryTask = new RetryTask(2);

            await this.taskHub.AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryName, RetryVersion,
                                                                                               () => new RetryOrchestration(retryOptions)))
            .AddTaskActivitiesFromInterface <IRetryTask>(retryTask)
            .StartAsync();

            RetryOrchestration.Result = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(RetryName, RetryVersion, false);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 90);

            Assert.IsNotNull(RetryOrchestration.Result);
            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 90));
            Assert.AreEqual("DoWork Succeeded. Attempts: 2", RetryOrchestration.Result,
                            "Orchestration Result is wrong!!!");
            Assert.AreEqual(2, retryTask.RetryCount, "Retry Count is wrong");
        }
예제 #16
0
        public async Task RetryOnReasonCustomHandlerTest()
        {
            var retryOptions = new RetryOptions(TimeSpan.FromSeconds(3), 3);

            retryOptions.Handle = e =>
            {
                Assert.IsInstanceOfType(e, typeof(TaskFailedException), "Exception is not TaskFailedException.");
                var taskFailed = (TaskFailedException)e;
                Assert.IsInstanceOfType(taskFailed.InnerException, typeof(InvalidOperationException),
                                        "InnerException is not InvalidOperationException.");
                return(e.Message.StartsWith("DoWork Failed. RetryCount is:"));
            };

            var retryTask = new RetryTask(2);

            await this.taskHub.AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryName, RetryVersion,
                                                                                               () => new RetryOrchestration(retryOptions)))
            .AddTaskActivitiesFromInterface <IRetryTask>(retryTask)
            .StartAsync();

            this.taskHub.TaskActivityDispatcher.IncludeDetails = true;

            RetryOrchestration.Result = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(RetryName, RetryVersion, false);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 90);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 90));
            Assert.AreEqual("DoWork Succeeded. Attempts: 2", RetryOrchestration.Result,
                            "Orchestration Result is wrong!!!");
            Assert.AreEqual(2, retryTask.RetryCount, "Retry Count is wrong");
        }
        public async Task QueryByTimeForRunningOrchestrationsTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            var instanceId1 = "first";

            DateTime firstBatchStart  = DateTime.UtcNow;
            OrchestrationInstance id1 = await this.client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                           instanceId1, "WAIT_DONTTHROW");

            await TestHelpers.WaitForInstanceAsync(this.client, id1, 60, false);

            // running orchestrations never get reported in any CompletedTimeFilter query
            OrchestrationStateQuery query = new OrchestrationStateQuery().AddTimeRangeFilter(firstBatchStart,
                                                                                             firstBatchStart.AddSeconds(60),
                                                                                             OrchestrationStateTimeRangeFilterType.OrchestrationCompletedTimeFilter);

            IEnumerable <OrchestrationState> response = await this.queryClient.QueryOrchestrationStatesAsync(query);

            Assert.AreEqual(0, response.Count());

            await TestHelpers.WaitForInstanceAsync(this.client, id1, 60);

            // now we should get a result
            response = await this.queryClient.QueryOrchestrationStatesAsync(query);

            Assert.AreEqual(1, response.Count());
        }
예제 #18
0
        public async Task BasicSubOrchestrationRetryTest()
        {
            var parentRetryOptions = new RetryOptions(TimeSpan.FromSeconds(3), 2)
            {
                BackoffCoefficient = 2.0,
                MaxRetryInterval   = TimeSpan.FromSeconds(4),
            };
            var retryOptions = new RetryOptions(TimeSpan.FromSeconds(3), 3);
            var retryTask    = new RetryTask(4);

            RetryOrchestration.RethrowException = true;

            await this.taskHub.AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryName, RetryVersion,
                                                                                               () => new RetryOrchestration(retryOptions)))
            .AddTaskOrchestrations(new TestObjectCreator <TaskOrchestration>(RetryParentName, RetryParentVersion,
                                                                             () => new ParentOrchestration(parentRetryOptions)))
            .AddTaskActivitiesFromInterface <IRetryTask>(retryTask)
            .StartAsync();

            ParentOrchestration.Result = null;
            RetryOrchestration.Result  = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(RetryParentName, RetryParentVersion, false);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 90);

            Assert.IsNotNull(RetryOrchestration.Result);
            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 90));
            Assert.AreEqual("DoWork Succeeded. Attempts: 4", ParentOrchestration.Result,
                            "Orchestration Result is wrong!!!");
        }
예제 #19
0
        ////[TestMethod]
        // Disabled until bug https://github.com/Azure/durabletask/issues/47 is fixed
        // Also the test does not work as expected due to debug mode suppressing UnobservedTaskException's
        public async Task ParallelInterfaceExceptionsTest()
        {
            var failureClient = new FailureClient();
            var unobservedTaskExceptionThrown = false;

            TaskScheduler.UnobservedTaskException += (sender, eventArgs) =>
            {
                var    t       = (Task)sender;
                string message = $"id:{t.Id}; {sender.GetType()}; {t.AsyncState}; {t.Status}";
                Trace.TraceError($"UnobservedTaskException caught: {message}");

                eventArgs.SetObserved();
                unobservedTaskExceptionThrown = true;
            };

            await this.taskHub
            .AddTaskOrchestrations(typeof(FailureClientOrchestration))
            .AddTaskActivitiesFromInterface <IFailureClient>(failureClient)
            .StartAsync();

            ParentOrchestration.Result = null;
            RetryOrchestration.Result  = null;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(FailureClientOrchestration), "test");

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 90);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 90));
            Assert.IsFalse(unobservedTaskExceptionThrown, "UnobservedTaskException should not be thrown");
        }
예제 #20
0
        public async Task QueryByNameVersionTest()
        {
            ObjectCreator <TaskOrchestration> c1 = new NameValueObjectCreator <TaskOrchestration>(
                "orch1", "1.0", typeof(InstanceStoreTestOrchestration));

            ObjectCreator <TaskOrchestration> c2 = new NameValueObjectCreator <TaskOrchestration>(
                "orch1", "2.0", typeof(InstanceStoreTestOrchestration));

            ObjectCreator <TaskOrchestration> c3 = new NameValueObjectCreator <TaskOrchestration>(
                "orch2", string.Empty, typeof(InstanceStoreTestOrchestration));

            await taskHub.AddTaskOrchestrations(c1, c2, c3)
            .AddTaskActivities(new Activity1())
            .StartAsync();

            OrchestrationInstance id1 = await client.CreateOrchestrationInstanceAsync("orch1", "1.0", "DONTTHROW");

            OrchestrationInstance id2 = await client.CreateOrchestrationInstanceAsync("orch1", "2.0", "DONTTHROW");

            OrchestrationInstance id3 = await client.CreateOrchestrationInstanceAsync("orch2", string.Empty, "DONTTHROW");

            await TestHelpers.WaitForInstanceAsync(client, id1, 60);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60);

            await TestHelpers.WaitForInstanceAsync(client, id3, 60);

            OrchestrationStateQuery query = new OrchestrationStateQuery().AddNameVersionFilter("orch1");

            IEnumerable <OrchestrationState> response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 2);

            // TODO : for some reason sometimes the order gets inverted
            //Assert.AreEqual(id1.InstanceId, response.First().OrchestrationInstance.InstanceId);
            //Assert.AreEqual(id2.InstanceId, response.ElementAt(1).OrchestrationInstance.InstanceId);

            query = new OrchestrationStateQuery().AddNameVersionFilter("orch1", "2.0");

            response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.AreEqual(1, response.Count());
            Assert.AreEqual(id2.InstanceId, response.First().OrchestrationInstance.InstanceId);

            query = new OrchestrationStateQuery().AddNameVersionFilter("orch1", string.Empty);

            response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 0);

            query = new OrchestrationStateQuery().AddNameVersionFilter("orch2", string.Empty);

            response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 1);
            Assert.AreEqual(id3.InstanceId, response.First().OrchestrationInstance.InstanceId);
        }
예제 #21
0
        public async Task QueryWithMultipleFiltersTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            string instance1 = "apiservice1_upgrade1";
            string instance2 = "apiservice1_upgrade2";
            string instance3 = "system_gc";

            OrchestrationInstance id1 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      instance1, "WAIT_THROW");

            OrchestrationInstance id2 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      instance2, "WAIT_DONTTHROW");

            OrchestrationInstance id3 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      instance3, "WAIT_DONTTHROW");

            await TestHelpers.WaitForInstanceAsync(client, id1, 60);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60);

            await TestHelpers.WaitForInstanceAsync(client, id3, 60);

            // completed apiservice1 --> 1 result
            OrchestrationStateQuery query = new OrchestrationStateQuery().
                                            AddInstanceFilter("apiservice1", true).
                                            AddStatusFilter(OrchestrationStatus.Completed);

            IEnumerable <OrchestrationState> response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 1);
            Assert.AreEqual(id2.InstanceId, response.First().OrchestrationInstance.InstanceId);

            // failed apiservice1 -> 1 result
            query = new OrchestrationStateQuery().
                    AddInstanceFilter("apiservice1", true).
                    AddStatusFilter(OrchestrationStatus.Failed);

            response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 1);
            Assert.AreEqual(id1.InstanceId, response.First().OrchestrationInstance.InstanceId);

            // failed gc -> 0 results
            query = new OrchestrationStateQuery().
                    AddInstanceFilter("system", true).
                    AddStatusFilter(OrchestrationStatus.Failed);

            response = await queryClient.QueryOrchestrationStatesAsync(query);

            Assert.IsTrue(response.Count() == 0);
        }
예제 #22
0
        public async Task BadOrchestrationTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(BadOrchestration))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(BadOrchestration), null);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
        }
예제 #23
0
        public async Task ActorOrchestrationTest()
        {
            var    sbService = (ServiceBusOrchestrationService)this.taskHub.orchestrationService;
            string name      = NameVersionHelper.GetDefaultName(typeof(CounterOrchestration));
            string version   = NameVersionHelper.GetDefaultVersion(typeof(CounterOrchestration));

            await this.taskHub.AddTaskOrchestrations(typeof(CounterOrchestration))
            .StartAsync();

            int initialValue         = 0;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(CounterOrchestration), initialValue);

            // Need to wait for the instance to start before sending events to it.
            // TODO: This requirement may not be ideal and should be revisited.
            await TestHelpers.WaitForInstanceAsync(this.client, id, 10, waitForCompletion : false);

            OrchestrationInstance temp = new OrchestrationInstance()
            {
                InstanceId = id.InstanceId
            };

            // Perform some operations
            await this.client.RaiseEventAsync(temp, "operation", "incr");

            await this.client.RaiseEventAsync(temp, "operation", "incr");

            await this.client.RaiseEventAsync(temp, "operation", "decr");

            await this.client.RaiseEventAsync(temp, "operation", "incr");

            await this.client.RaiseEventAsync(temp, "operation", "incr");

            await this.client.RaiseEventAsync(temp, "operation", "end");

            await Task.Delay(4000);

            // Make sure it's still running and didn't complete early (or fail).
            var status = await client.GetOrchestrationStateAsync(id);

            Assert.IsTrue(
                status?.OrchestrationStatus == OrchestrationStatus.Running ||
                status?.OrchestrationStatus == OrchestrationStatus.ContinuedAsNew);

            // The end message will cause the actor to complete itself.
            await this.client.RaiseEventAsync(temp, "operation", "end");

            status = await client.WaitForOrchestrationAsync(temp, TimeSpan.FromSeconds(10));

            Assert.AreEqual(OrchestrationStatus.Completed, status?.OrchestrationStatus);
            Assert.AreEqual(3, JToken.Parse(status?.Output));

            // When using ContinueAsNew, the original input is discarded and replaced with the most recent state.
            Assert.AreNotEqual(initialValue, JToken.Parse(status?.Input));
        }
예제 #24
0
        public async Task QueryByStatusTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(InstanceStoreTestOrchestration))
            .AddTaskActivities(new Activity1())
            .StartAsync();

            OrchestrationInstance id1 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      "WAIT_THROW");

            OrchestrationInstance id2 = await client.CreateOrchestrationInstanceAsync(typeof(InstanceStoreTestOrchestration),
                                                                                      "WAIT_DONTTHROW");

            OrchestrationStateQuery completedQuery =
                new OrchestrationStateQuery().AddStatusFilter(OrchestrationStatus.Completed);
            OrchestrationStateQuery runningQuery =
                new OrchestrationStateQuery().AddStatusFilter(OrchestrationStatus.Running);
            OrchestrationStateQuery pendingQuery =
                new OrchestrationStateQuery().AddStatusFilter(OrchestrationStatus.Pending);
            OrchestrationStateQuery failedQuery =
                new OrchestrationStateQuery().AddStatusFilter(OrchestrationStatus.Failed);

            await TestHelpers.WaitForInstanceAsync(client, id1, 60, false);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60, false);

            IEnumerable <OrchestrationState> pendingStates = await queryClient.QueryOrchestrationStatesAsync(pendingQuery);

            IEnumerable <OrchestrationState> completedStates = await queryClient.QueryOrchestrationStatesAsync(completedQuery);

            IEnumerable <OrchestrationState> failedStates = await queryClient.QueryOrchestrationStatesAsync(failedQuery);

            Assert.AreEqual(2, pendingStates.Count());
            Assert.AreEqual(0, completedStates.Count());
            Assert.AreEqual(0, failedStates.Count());

            await TestHelpers.WaitForInstanceAsync(client, id1, 60);

            await TestHelpers.WaitForInstanceAsync(client, id2, 60);

            IEnumerable <OrchestrationState> runningStates = await queryClient.QueryOrchestrationStatesAsync(runningQuery);

            completedStates = await queryClient.QueryOrchestrationStatesAsync(completedQuery);

            failedStates = await queryClient.QueryOrchestrationStatesAsync(failedQuery);

            Assert.AreEqual(0, runningStates.Count());
            Assert.AreEqual(1, completedStates.Count());
            Assert.AreEqual(1, failedStates.Count());

            Assert.AreEqual(id1.InstanceId, failedStates.First().OrchestrationInstance.InstanceId);
            Assert.AreEqual(id2.InstanceId, completedStates.First().OrchestrationInstance.InstanceId);
        }
예제 #25
0
        public async Task NonDeterministicOrchestrationTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(NonDeterministicOrchestration))
            .AddTaskActivities(typeof(FirstTask))
            .StartAsync();

            this.taskHub.TaskActivityDispatcher.IncludeDetails = true;

            OrchestrationInstance instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicOrchestration), "FAILTIMER");

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            OrchestrationState state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Failed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("TimerCreatedEvent"));

            instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicOrchestration), "FAILTASK");

            isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Failed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("TaskScheduledEvent"));

            instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicOrchestration), "FAILSUBORCH");

            isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Failed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("SubOrchestrationInstanceCreatedEvent"));

            instance = await this.client.CreateOrchestrationInstanceAsync(typeof(NonDeterministicOrchestration), "PARENTORCH");

            isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, instance, 60);

            Utils.UnusedParameter(isCompleted);

            state = await this.client.GetOrchestrationStateAsync(instance);

            Assert.AreEqual(OrchestrationStatus.Completed, state.OrchestrationStatus);
            Assert.IsTrue(state.Output.Contains("Non-Deterministic workflow detected"));
        }
예제 #26
0
        public async Task GreetingsTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(GreetingsOrchestration))
            .AddTaskActivities(typeof(GetUserTask), typeof(SendGreetingTask))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(GreetingsOrchestration), null);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual("Greeting send to Gabbar", GreetingsOrchestration.Result, "Orchestration Result is wrong!!!");
        }
예제 #27
0
        public async Task SubOrchestrationExplicitIdTest()
        {
            SimpleChildWorkflow.ChildInstanceId = null;
            await taskHub.AddTaskOrchestrations(typeof(SimpleParentWorkflow), typeof(SimpleChildWorkflow))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(SimpleParentWorkflow), null);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual("foo_instance", SimpleChildWorkflow.ChildInstanceId);
        }
예제 #28
0
        public async Task GenericInterfaceMethodTests()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(GenericMethodInterfaceOrchestration))
            .AddTaskActivitiesFromInterface <IGenericMethodInterface>(new GenericMethodImplementation())
            .StartAsync();

            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(GenericMethodInterfaceOrchestration),
                                                                                          new GenericInterfaceOrchestrationInput { Property = 3.142f });

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 60));
        }
예제 #29
0
        public async Task MessageOverflowTest()
        {
            await taskHub.AddTaskOrchestrations(typeof(LargeInputOutputOrchestration)).StartAsync();

            // generate a large string as the orchestration input;
            // make it random so that it won't be compressed too much.
            var largeInput           = TestUtils.GenerateRandomString(1000 * 1024);
            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(LargeInputOutputOrchestration), largeInput);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 60);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual($"output-{largeInput}", LargeInputOutputOrchestration.Result, "Orchestration Result is wrong!!!");
        }
예제 #30
0
        public async Task MaxMessagesLimitTest()
        {
            await this.taskHub.AddTaskOrchestrations(typeof(MaxMessagesLimitOrchestration))
            .AddTaskActivities(new MaxMessagesLimitTask())
            .StartAsync();

            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(MaxMessagesLimitOrchestration), null);

            bool isCompleted = await TestHelpers.WaitForInstanceAsync(this.client, id, 120);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(this.client, id, 120));

            Assert.AreEqual(19900, MaxMessagesLimitOrchestration.Result, "Orchestration Result is wrong!!!");
        }