public async Task ConcurrentSubOrchestrationsAsTopLevelOrchestrationsTest()
        {
            var c2 = new NameValueObjectCreator <TaskOrchestration>("SleeperSubOrchestration",
                                                                    "V1", typeof(SleeperSubOrchestration));

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

            int numSubOrchestrations = 60;

            var orchestrations = new List <Task <OrchestrationInstance> >();

            for (int i = 0; i < numSubOrchestrations; i++)
            {
                orchestrations.Add(client.CreateOrchestrationInstanceAsync(
                                       "SleeperSubOrchestration",
                                       "V1",
                                       $"{UberOrchestration.ChildWorkflowIdBase}_{i}",
                                       new TestOrchestrationInput {
                    Iterations = 1, Payload = TestUtils.GenerateRandomString(8 * 1024)
                }));
            }

            IList <OrchestrationInstance> orchestrationInstances = (await Task.WhenAll(orchestrations)).ToList();

            IEnumerable <Task <OrchestrationState> > orchestrationResults = orchestrationInstances.Select(async instance =>
            {
                OrchestrationState result = await client.WaitForOrchestrationAsync(instance, TimeSpan.FromSeconds(60));
                return(result);
            });

            var finalResults = await Task.WhenAll(orchestrationResults);

            Assert.AreEqual(numSubOrchestrations, finalResults.Count(status => status.OrchestrationStatus == OrchestrationStatus.Completed));
        }
        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!!!");
        }
Beispiel #3
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);
        }
        public async Task TagsSubOrchestrationTest()
        {
            var c1 = new NameValueObjectCreator <TaskOrchestration>("ParentWorkflow",
                                                                    "V1", typeof(ParentWorkflow));

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

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

            OrchestrationInstance instance = await client.CreateOrchestrationInstanceAsync(
                "ParentWorkflow",
                "V1",
                "TestInstance",
                true,
                new Dictionary <string, string>(2) {
                { ParentWorkflow.ParentTagName, ParentWorkflow.ParentTagValue },
                { ParentWorkflow.SharedTagName, ParentWorkflow.ParentTagValue }
            });

            OrchestrationState state = await client.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(1), CancellationToken.None);

            bool isCompleted = (state?.OrchestrationStatus == OrchestrationStatus.Completed);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, instance, 60));
            Assert.AreEqual("Child completed.", ParentWorkflow.Result, "Orchestration Result is wrong!!!");

            IDictionary <string, string> returnedTags = state.Tags;
            string returnedValue;

            // Check for parent tag untouched
            Assert.IsTrue(returnedTags.TryGetValue(ParentWorkflow.ParentTagName, out returnedValue));
            Assert.AreEqual(ParentWorkflow.ParentTagValue, returnedValue);
            // Check for shared tag on parent with parent value
            Assert.IsTrue(returnedTags.TryGetValue(ParentWorkflow.SharedTagName, out returnedValue));
            Assert.AreEqual(ParentWorkflow.ParentTagValue, returnedValue);

            // Get child state and check completion
            OrchestrationState childState = await client.GetOrchestrationStateAsync(ParentWorkflow.ChildWorkflowId);

            isCompleted = (childState?.OrchestrationStatus == OrchestrationStatus.Completed);
            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, instance, 60));

            returnedTags = childState.Tags;
            // Check for parent tag untouched
            Assert.IsTrue(returnedTags.TryGetValue(ParentWorkflow.ParentTagName, out returnedValue));
            Assert.AreEqual(ParentWorkflow.ParentTagValue, returnedValue);
            // Check for shared tag on with child value
            Assert.IsTrue(returnedTags.TryGetValue(ParentWorkflow.SharedTagName, out returnedValue));
            Assert.AreEqual(ParentWorkflow.ChildTagValue, returnedValue);
            // Check for child tag
            Assert.IsTrue(returnedTags.TryGetValue(ParentWorkflow.ChildTagName, out returnedValue));
            Assert.AreEqual(ParentWorkflow.ChildTagValue, returnedValue);
        }
        public async Task TagsOrchestrationTest()
        {
            GenerationV1Orchestration.WasRun = false;
            GenerationV2Orchestration.WasRun = false;
            GenerationV3Orchestration.WasRun = false;

            var c1 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V1", typeof(GenerationV1Orchestration));

            var c2 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V2", typeof(GenerationV2Orchestration));

            var c3 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V3", typeof(GenerationV3Orchestration));

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

            const string tagName  = "versiontag";
            const string tagValue = "sample_value";

            OrchestrationInstance instance = await client.CreateOrchestrationInstanceAsync(
                "GenerationOrchestration",
                "V1",
                "TestInstance",
                null,
                new Dictionary <string, string>(1) { { tagName, tagValue } });

            OrchestrationState state = await client.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(1), CancellationToken.None);

            bool isCompleted = (state?.OrchestrationStatus == OrchestrationStatus.Completed);

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, instance, 60));
            Assert.IsTrue(GenerationV1Orchestration.WasRun);
            Assert.IsTrue(GenerationV2Orchestration.WasRun);
            Assert.IsTrue(GenerationV3Orchestration.WasRun);
            IDictionary <string, string> returnedTags = state.Tags;
            string returnedValue;

            Assert.IsTrue(returnedTags.TryGetValue(tagName, out returnedValue));
            Assert.AreEqual(tagValue, returnedValue);
        }
Beispiel #6
0
        public OrchestrationTestHost AddTaskActivitiesFromInterface <T>(T activities, bool useFullyQualifiedMethodNames)
        {
            Type @interface = typeof(T);

            if ([email protected])
            {
                throw new Exception("Contract can only be an interface.");
            }

            foreach (MethodInfo methodInfo in @interface.GetMethods())
            {
                TaskActivity taskActivity            = new ReflectionBasedTaskActivity(activities, methodInfo);
                ObjectCreator <TaskActivity> creator =
                    new NameValueObjectCreator <TaskActivity>(
                        NameVersionHelper.GetDefaultName(methodInfo, useFullyQualifiedMethodNames),
                        NameVersionHelper.GetDefaultVersion(methodInfo), taskActivity);
                activityObjectManager.Add(creator);
            }
            return(this);
        }
Beispiel #7
0
        public async Task TestHostGenerationVersionTest()
        {
            var c1 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V1", typeof(GenerationV1Orchestration));

            var c2 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V2", typeof(GenerationV2Orchestration));

            var c3 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V3", typeof(GenerationV3Orchestration));

            var testHost = new OrchestrationTestHost();

            testHost.AddTaskOrchestrations(c1, c2, c3);

            object res = await testHost.RunOrchestration <object>("GenerationOrchestration", "V1", null);

            Assert.IsTrue(GenerationV1Orchestration.WasRun);
            Assert.IsTrue(GenerationV2Orchestration.WasRun);
            Assert.IsTrue(GenerationV3Orchestration.WasRun);
        }
Beispiel #8
0
        public void GenerationVersionTest()
        {
            var c1 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V1", typeof(GenerationV1Orchestration));

            var c2 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V2", typeof(GenerationV2Orchestration));

            var c3 = new NameValueObjectCreator <TaskOrchestration>("GenerationOrchestration",
                                                                    "V3", typeof(GenerationV3Orchestration));

            taskHub.AddTaskOrchestrations(c1, c2, c3)
            .Start();

            OrchestrationInstance id = client.CreateOrchestrationInstance("GenerationOrchestration", "V1", null);

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

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.IsTrue(GenerationV1Orchestration.WasRun);
            Assert.IsTrue(GenerationV2Orchestration.WasRun);
            Assert.IsTrue(GenerationV3Orchestration.WasRun);
        }