Esempio n. 1
0
        static void Main(string[] args)
        {
            AppSettingsReader reader = new AppSettingsReader();
            string            servicebusConnectionString = reader.GetValue("Microsoft.ServiceBus.ConnectionString", typeof(string)).ToString();
            string            taskHubName = reader.GetValue("TaskHubName", typeof(string)).ToString();

            TaskHubClient taskHubClient = new TaskHubClient(taskHubName, servicebusConnectionString);
            TaskHubWorker taskHub       = new TaskHubWorker(taskHubName, servicebusConnectionString);

            taskHub.DeleteHub();
            taskHub.CreateHubIfNotExists();

            OrchestrationInstance instance = null;

            string instanceId = "TestTaskHub : " + Guid.NewGuid();

            taskHub.AddTaskOrchestrations((typeof(TaskHubProcessingOrchestration)));
            taskHub.AddTaskActivitiesFromInterface <IActivityFunction>(new ActivityImplementor(), true);
            taskHub.AddTaskActivities(new GetUserTask());

            instance = taskHubClient.CreateOrchestrationInstance(typeof(TaskHubProcessingOrchestration), instanceId, "hello");

            taskHub.Start();
            Console.WriteLine("Press any key to quit.");
            Console.ReadLine();
            taskHub.Stop(true);
        }
Esempio n. 2
0
        public async Task InitializeAsync(bool startWorker = true)
        {
            // The initialization requires administrative credentials (default)
            await new SqlOrchestrationService(this.OrchestrationServiceOptions).CreateIfNotExistsAsync();

            // Enable multitenancy to isolate each test using low-privilege credentials
            await this.EnableMultitenancyAsync();

            // The runtime will use low-privilege credentials
            string taskHubConnectionString = await this.CreateTaskHubLoginAsync();

            this.OrchestrationServiceOptions = new SqlOrchestrationServiceSettings(taskHubConnectionString)
            {
                LoggerFactory = this.loggerFactory,
            };

            this.OrchestrationServiceMock = new Mock <SqlOrchestrationService>(this.OrchestrationServiceOptions)
            {
                CallBase = true
            };
            this.worker = new TaskHubWorker(this.OrchestrationServiceMock.Object, this.loggerFactory);
            if (startWorker)
            {
                await this.worker.StartAsync();
            }

            this.client = new TaskHubClient(this.OrchestrationServiceMock.Object, loggerFactory: this.loggerFactory);
        }
Esempio n. 3
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Start");
            string serviceBusConnectionString = "";
            string storageConnectionString    = "";
            string taskHubName = "devstoreaccount";

            var instanceStore = new AzureTableInstanceStore(taskHubName, storageConnectionString);

            var orchestrationServiceAndClient = new ServiceBusOrchestrationService(serviceBusConnectionString, taskHubName, instanceStore, null, null);

            await orchestrationServiceAndClient.CreateIfNotExistsAsync();

            var taskHubWorker = await new TaskHubWorker(orchestrationServiceAndClient)
                                .AddTaskOrchestrations(typeof(PredicaOrchestration))
                                .AddTaskActivities(new ApproveInvoice())
                                .AddTaskActivities(new RejectInvoice())
                                .AddTaskActivities(new SendInvoice())
                                .StartAsync();


            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);

            var instanceId = Guid.NewGuid().ToString();
            var instance   = await taskHubClient.CreateOrchestrationInstanceAsync(typeof(PredicaOrchestration), instanceId, $"Predica-Inv-{DateTime.UtcNow.Ticks}");

            await taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.FromMinutes(15), CancellationToken.None);

            await taskHubWorker.StopAsync(false);
        }
Esempio n. 4
0
        private async Task RaiseEventInternalAsync(
            TaskHubClient taskHubClient,
            string taskHubName,
            string instanceId,
            string eventName,
            object eventData)
        {
            OrchestrationState status = await taskHubClient.GetOrchestrationStateAsync(instanceId);

            if (status == null)
            {
                return;
            }

            if (status.OrchestrationStatus == OrchestrationStatus.Running ||
                status.OrchestrationStatus == OrchestrationStatus.Pending ||
                status.OrchestrationStatus == OrchestrationStatus.ContinuedAsNew)
            {
                // External events are not supposed to target any particular execution ID.
                // We need to clear it to avoid sending messages to an expired ContinueAsNew instance.
                status.OrchestrationInstance.ExecutionId = null;

                await taskHubClient.RaiseEventAsync(status.OrchestrationInstance, eventName, eventData);

                this.traceHelper.FunctionScheduled(
                    taskHubName,
                    status.Name,
                    instanceId,
                    reason: "RaiseEvent:" + eventName,
                    functionType: FunctionType.Orchestrator,
                    isReplay: false);
            }
        }
        public ExceptionHandlingIntegrationTests()
        {
            var service = new LocalOrchestrationService();

            this.worker = new TaskHubWorker(service);
            this.client = new TaskHubClient(service);
        }
Esempio n. 6
0
        public async Task MockGenerationTest()
        {
            GenerationBasicOrchestration.Result = 0;
            GenerationBasicTask.GenerationCount = 0;

            LocalOrchestrationService orchService = new LocalOrchestrationService();

            TaskHubWorker worker = new TaskHubWorker(orchService);
            TaskHubClient client = new TaskHubClient(orchService);

            await worker.AddTaskOrchestrations(typeof(GenerationBasicOrchestration))
            .AddTaskActivities(new GenerationBasicTask())
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(GenerationBasicOrchestration), 4);

            // strip out the eid so we wait for the latest one always
            OrchestrationInstance masterid = new OrchestrationInstance {
                InstanceId = id.InstanceId
            };

            OrchestrationState result1 = await client.WaitForOrchestrationAsync(id, TimeSpan.FromSeconds(10), CancellationToken.None);

            OrchestrationState result2 = await client.WaitForOrchestrationAsync(masterid, TimeSpan.FromSeconds(20), CancellationToken.None);

            Assert.AreEqual(OrchestrationStatus.ContinuedAsNew, result1.OrchestrationStatus);
            Assert.AreEqual(OrchestrationStatus.Completed, result2.OrchestrationStatus);

            Assert.AreEqual(4, GenerationBasicOrchestration.Result, "Orchestration Result is wrong!!!");
        }
Esempio n. 7
0
        async Task StartAsync()
        {
            try
            {
                EnsureFabricOrchestrationProviderIsInitialized();

                this.worker = new TaskHubWorker(this.fabricOrchestrationProvider.OrchestrationService, this.fabricOrchestrationProviderSettings.LoggerFactory);

                if (this.registerOrchestrations2 != null)
                {
                    this.localClient = new TaskHubClient(this.fabricOrchestrationProvider.OrchestrationServiceClient, loggerFactory: this.fabricOrchestrationProviderSettings.LoggerFactory);
                    this.registerOrchestrations2(this.worker, this.localClient);
                }
                else
                {
                    this.registerOrchestrations(this.worker);
                }

                await this.worker.StartAsync();

                this.worker.TaskActivityDispatcher.IncludeDetails = true;
            }
            catch (Exception exception)
            {
                ServiceFabricProviderEventSource.Tracing.ServiceRequestFailed("RunAsync failed", $"Exception Details Type: {exception.GetType()}, Message: {exception.Message}, StackTrace: {exception.StackTrace}");
                throw;
            }
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            AzureStorageOrchestrationService orchestrationService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings()
            {
                StorageConnectionString = ServiceSettings.StorageConnectionString,
                TaskHubName             = ServiceSettings.TaskHubName
            });

            TaskHubClient client = new TaskHubClient(orchestrationService);

            Console.WriteLine("Enter -1 to exit anything else will be fed to the orchestration");
            do
            {
                var s = Console.ReadLine();

                if (s == "-1")
                {
                    break;
                }

                var instance = client.CreateOrchestrationInstanceAsync(typeof(LetterCountOrchestration), s).Result;
                Console.WriteLine("Workflow Instance Started: " + instance);

                var result = client.WaitForOrchestrationAsync(instance, TimeSpan.MaxValue).Result;

                Console.WriteLine($"Task done: {result?.OrchestrationStatus}");
            } while (1 == 1);
        }
Esempio n. 9
0
        public void TestInitialize()
        {
            client = TestHelpers.CreateTaskHubClient();

            taskHub = TestHelpers.CreateTaskHub();
            taskHub.orchestrationService.CreateAsync(true).Wait();
        }
Esempio n. 10
0
        public static OrchestrationInstance StartOrchestrationInstance(TaskHubClient client, string name, string instanceId, string[] parameters)
        {
            OrchestrationInstance instance = null;

            switch (name)
            {
            case "Signup":
                if (parameters == null || parameters.Length < 2)
                {
                    throw new ArgumentException("Signup parameters not provided.");
                }

                UtilitySignupOrchestrationInput signupInput = new UtilitySignupOrchestrationInput
                {
                    Name                   = parameters[0],
                    AccountNumber          = parameters[1],
                    NumberOfCreditAgencies = parameters.Length > 2 ? int.Parse(parameters[2]) : 0,
                    Address                = new CustomerAddress
                    {
                        Street = "One Microsoft Way",
                        City   = "Redmond",
                        State  = "WA",
                        Zip    = 98052,
                    },
                    Checks = SignupChecks.All,
                };
                instance = client.CreateOrchestrationInstance(typeof(UtilitySignupOrchestration), instanceId, signupInput);
                break;

            default:
                throw new Exception("Unsupported Orchestration Name: " + name);
            }

            return(instance);
        }
Esempio n. 11
0
        public async Task MockTimerTest()
        {
            LocalOrchestrationService orchService = new LocalOrchestrationService();

            TaskHubWorker worker = new TaskHubWorker(orchService);

            await worker.AddTaskOrchestrations(typeof(SimplestGreetingsOrchestration))
            .AddTaskActivities(typeof(SimplestGetUserTask), typeof(SimplestSendGreetingTask))
            .StartAsync();

            TaskHubClient client = new TaskHubClient(orchService);

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(SimplestGreetingsOrchestration), "6");

            Stopwatch          sw     = Stopwatch.StartNew();
            OrchestrationState result = await client.WaitForOrchestrationAsync(id, TimeSpan.FromSeconds(40), new CancellationToken());

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);

            Assert.IsTrue(sw.Elapsed.Seconds > 6);

            Assert.AreEqual("Greeting send to Gabbar", SimplestGreetingsOrchestration.Result,
                            "Orchestration Result is wrong!!!");

            await worker.StopAsync(true);
        }
Esempio n. 12
0
        public async Task MockSuborchestrationTest()
        {
            LocalOrchestrationService orchService = new LocalOrchestrationService();

            TaskHubWorker worker = new TaskHubWorker(orchService);
            TaskHubClient client = new TaskHubClient(orchService);

            await worker.AddTaskOrchestrations(typeof(ParentWorkflow), typeof(ChildWorkflow))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(typeof(ParentWorkflow), true);

            OrchestrationState result = await client.WaitForOrchestrationAsync(id,
                                                                               TimeSpan.FromSeconds(40), CancellationToken.None);

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);
            Assert.AreEqual(
                "Child '0' completed.Child '1' completed.Child '2' completed.Child '3' completed.Child '4' completed.",
                ParentWorkflow.Result, "Orchestration Result is wrong!!!");

            ParentWorkflow.Result = string.Empty;

            id = await client.CreateOrchestrationInstanceAsync(typeof(ParentWorkflow), false);

            result = await client.WaitForOrchestrationAsync(id, TimeSpan.FromSeconds(40), CancellationToken.None);

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);
            Assert.AreEqual(
                "Child '0' completed.Child '1' completed.Child '2' completed.Child '3' completed.Child '4' completed.",
                ParentWorkflow.Result, "Orchestration Result is wrong!!!");

            await worker.StopAsync(true);
        }
        Task IDurableOrchestrationClient.RaiseEventAsync(string taskHubName, string instanceId, string eventName, object eventData, string connectionName)
        {
            if (string.IsNullOrEmpty(taskHubName))
            {
                throw new ArgumentNullException(nameof(taskHubName));
            }

            if (string.IsNullOrEmpty(eventName))
            {
                throw new ArgumentNullException(nameof(eventName));
            }

            if (string.IsNullOrEmpty(connectionName))
            {
                connectionName = this.attribute.ConnectionName;
            }

            var attribute = new DurableClientAttribute
            {
                TaskHub        = taskHubName,
                ConnectionName = connectionName,
            };

            TaskHubClient taskHubClient = ((DurableClient)this.config.GetClient(attribute)).client;

            return(this.RaiseEventInternalAsync(taskHubClient, taskHubName, instanceId, eventName, eventData));
        }
 public TestOrchestrationHost(AzureStorageOrchestrationService service)
 {
     this.worker = new TaskHubWorker(service);
     this.client = new TaskHubClient(service);
     this.addedOrchestrationTypes = new HashSet <Type>();
     this.addedActivityTypes      = new HashSet <Type>();
 }
        private void SetStorageServiceAndTaskHubClient(out AzureStorageOrchestrationService orchestrationService, out TaskHubClient taskHubClient, string connectionStringKey = null, string taskHubName = null)
        {
            _connectionStringKey = connectionStringKey ?? _connectionStringKey;
            _taskHubName         = taskHubName ?? _taskHubName;

            var connectionString = Environment.GetEnvironmentVariable(_connectionStringKey); // Prioritize environment variables

            connectionString = connectionString ?? _secretsManager.GetSecrets().FirstOrDefault(s => s.Key.Equals(_connectionStringKey, StringComparison.OrdinalIgnoreCase)).Value;

            if (!string.IsNullOrEmpty(connectionString))
            {
                var settings = new AzureStorageOrchestrationServiceSettings
                {
                    TaskHubName             = _taskHubName,
                    StorageConnectionString = connectionString,
                };

                orchestrationService = new AzureStorageOrchestrationService(settings);
                taskHubClient        = new TaskHubClient(orchestrationService);
            }
            else
            {
                throw new CliException("No storage connection string found.");
            }
        }
        public void TestInitialize()
        {
            client = TestHelpers.CreateTaskHubClient();

            taskHub = TestHelpers.CreateTaskHub();
            taskHub.CreateHub();
        }
Esempio n. 17
0
        public static bool WaitForInstance(TaskHubClient taskHubClient, OrchestrationInstance instance,
                                           int timeoutSeconds,
                                           bool waitForCompletion = true)
        {
            if (instance == null || string.IsNullOrWhiteSpace(instance.InstanceId))
            {
                throw new ArgumentException("instance");
            }

            int sleepForSeconds = 2;

            while (timeoutSeconds > 0)
            {
                OrchestrationState state = taskHubClient.GetOrchestrationState(instance.InstanceId);
                if (state == null || (waitForCompletion && state.OrchestrationStatus == OrchestrationStatus.Running))
                {
                    Thread.Sleep(sleepForSeconds * 1000);
                    timeoutSeconds -= sleepForSeconds;
                }
                else
                {
                    // Session state deleted after completion
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 18
0
        public async Task SimpleGreetingOrchestration()
        {
            var orchestrationService = TestHelpers.GetTestOrchestrationService(nameof(SimpleGreetingOrchestration));

            var worker = new TaskHubWorker(orchestrationService);

            try
            {
                await worker.AddTaskOrchestrations(typeof(SimplestGreetingsOrchestration))
                .AddTaskActivities(typeof(SimplestGetUserTask), typeof(SimplestSendGreetingTask))
                .StartAsync();

                var client = new TaskHubClient(orchestrationService);

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

                OrchestrationState result = await client.WaitForOrchestrationAsync(id, TimeSpan.FromSeconds(Debugger.IsAttached ? 300 : 20), new CancellationToken());

                Assert.Equal(OrchestrationStatus.Completed, result.OrchestrationStatus);

                Assert.Equal("Greeting send to Gabbar", SimplestGreetingsOrchestration.Result);
            }
            finally
            {
                await worker.StopAsync(true);

                await orchestrationService.DeleteAsync();
            }
        }
Esempio n. 19
0
        private async Task RaiseEventInternalAsync(
            TaskHubClient taskHubClient,
            string taskHubName,
            string instanceId,
            string eventName,
            object eventData)
        {
            OrchestrationState status = await taskHubClient.GetOrchestrationStateAsync(instanceId);

            if (status == null)
            {
                return;
            }

            if (status.OrchestrationStatus == OrchestrationStatus.Running ||
                status.OrchestrationStatus == OrchestrationStatus.Pending ||
                status.OrchestrationStatus == OrchestrationStatus.ContinuedAsNew)
            {
                await taskHubClient.RaiseEventAsync(status.OrchestrationInstance, eventName, eventData);

                this.traceHelper.FunctionScheduled(
                    taskHubName,
                    status.Name,
                    instanceId,
                    reason: "RaiseEvent:" + eventName,
                    functionType: FunctionType.Orchestrator,
                    isReplay: false);
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            eventListener = new ObservableEventListener();
            eventListener.LogToConsole();
            eventListener.EnableEvents(DefaultEventSource.Log, EventLevel.LogAlways);

            TraceSource source = new TraceSource("DurableTask");

            source.Listeners.AddRange(Trace.Listeners);

            IOrchestrationServiceInstanceStore instanceStore = new AzureTableInstanceStore(TaskHubName, StorageConnectionString);

            ServiceBusOrchestrationService orchestrationServiceAndClient =
                new ServiceBusOrchestrationService(ServiceBusConnectionString, TaskHubName, instanceStore, null, null);

            orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();

            TaskHubClient taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            TaskHubWorker taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

            taskHub.AddTaskOrchestrations(typeof(CounterOrchestration));
            taskHub.AddTaskActivities(typeof(Task1), typeof(Task2));

            var instance = taskHubClient.CreateOrchestrationInstanceAsync(typeof(CounterOrchestration), Guid.NewGuid().ToString(), new TestOrchestrationInput()).Result;

            taskHub.StartAsync().Wait();

            //taskHubClient.WaitForOrchestrationAsync(instance, TimeSpan.MaxValue).Wait();

            Thread.Sleep(int.MaxValue);
        }
Esempio n. 21
0
        public async Task MockRecreateOrchestrationTest()
        {
            LocalOrchestrationService orchService = new LocalOrchestrationService();

            TaskHubWorker worker = new TaskHubWorker(orchService);

            await worker.AddTaskOrchestrations(typeof(SimplestGreetingsOrchestration))
            .AddTaskActivities(typeof(SimplestGetUserTask), typeof(SimplestSendGreetingTask))
            .StartAsync();

            TaskHubClient client = new TaskHubClient(orchService);

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

            OrchestrationState result = await client.WaitForOrchestrationAsync(id, TimeSpan.FromSeconds(30), new CancellationToken());

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);

            await Assert.ThrowsExceptionAsync <OrchestrationAlreadyExistsException>(() => client.CreateOrchestrationInstanceAsync(typeof(SimplestGreetingsOrchestration), id.InstanceId, null));

            await Assert.ThrowsExceptionAsync <OrchestrationAlreadyExistsException>(() => client.CreateOrchestrationInstanceAsync(typeof(SimplestGreetingsOrchestration), id.InstanceId, null, new OrchestrationStatus[] { OrchestrationStatus.Completed }));

            SimplestGreetingsOrchestration.Result = String.Empty;

            OrchestrationInstance id2 = await client.CreateOrchestrationInstanceAsync(typeof(SimplestGreetingsOrchestration), id.InstanceId, null, new OrchestrationStatus[] {});

            result = await client.WaitForOrchestrationAsync(id2, TimeSpan.FromSeconds(30), new CancellationToken());

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);

            Assert.AreEqual("Greeting send to Gabbar", SimplestGreetingsOrchestration.Result,
                            "Orchestration Result on Re-Create is wrong!!!");

            await worker.StopAsync(true);
        }
Esempio n. 22
0
        /// <summary>
        /// Creates the instance of ServiceClient, which can be used to act with microservice.
        /// </summary>
        /// <param name="sbConnStr"></param>
        /// <param name="storageConnStr"></param>
        /// <param name="hubName"></param>
        public ServiceClient(string sbConnStr, string storageConnStr, string hubName)
        {
            this.m_ServiceBusConnectionString = sbConnStr;
            this.m_StorageConnectionString    = storageConnStr;
            this.m_TaskHubName = hubName;

            this.m_HubClient = createTaskHubClient(!String.IsNullOrEmpty(storageConnStr));
        }
Esempio n. 23
0
        public static void RaiseEvent(TaskHubClient client, string instanceId, string signalName, string signalValue)
        {
            OrchestrationInstance instance = new OrchestrationInstance {
                InstanceId = instanceId
            };

            client.RaiseEvent(instance, signalName, signalValue);
        }
        public void TestInitialize()
        {
            client = TestHelpers.CreateTaskHubClient();

            taskHub = TestHelpers.CreateTaskHub();

            taskHub.DeleteHub();
            taskHub.CreateHubIfNotExists();
        }
Esempio n. 25
0
        public static void DumpAllInstances(TaskHubClient client, int hours)
        {
            DateTime currentTime = DateTime.UtcNow;
            OrchestrationStateQuery statusQuery = new OrchestrationStateQuery();

            statusQuery
            .AddTimeRangeFilter(currentTime.Subtract(TimeSpan.FromHours(hours)), currentTime, OrchestrationStateTimeRangeFilterType.OrchestrationCreatedTimeFilter);

            DumpInstances(client.QueryOrchestrationStates(statusQuery));
        }
Esempio n. 26
0
        public void TestInitialize()
        {
            this.client = TestHelpers.CreateTaskHubClient();

            this.taskHub = TestHelpers.CreateTaskHub();

            this.taskHub.orchestrationService.CreateAsync(true).Wait();

            this.taskHubNoCompression = TestHelpers.CreateTaskHubNoCompression();
        }
Esempio n. 27
0
 public void TestInitialize()
 {
     if (!TestContext.TestName.Contains("TestHost"))
     {
         client  = TestHelpers.CreateTaskHubClient();
         taskHub = TestHelpers.CreateTaskHub();
         taskHubNoCompression = TestHelpers.CreateTaskHubNoCompression();
         taskHub.orchestrationService.CreateAsync(true).Wait();
     }
 }
        public void TestInitialize()
        {
            if (!TestContext.TestName.Contains("TestHost"))
            {
                client = TestHelpers.CreateTaskHubClient();

                taskHub = TestHelpers.CreateTaskHub(TimeSpan.FromSeconds(30));
                taskHub.orchestrationService.CreateAsync(true).Wait();
            }
        }
        public void TestInitialize()
        {
            this.client = TestHelpers.CreateTaskHubClient();
            this.orchestrationService = this.client.ServiceClient as ServiceBusOrchestrationService;
            this.queryClient          = this.orchestrationService?.InstanceStore as AzureTableInstanceStore;

            this.taskHub = TestHelpers.CreateTaskHub();

            this.taskHub.orchestrationService.CreateAsync(true).Wait();
        }
Esempio n. 30
0
        public async Task MockRaiseEventTest()
        {
            LocalOrchestrationService orchService = new LocalOrchestrationService();

            TaskHubWorker worker = new TaskHubWorker(orchService);
            TaskHubClient client = new TaskHubClient(orchService);

            await worker.AddTaskOrchestrations(typeof(GenerationSignalOrchestration))
            .StartAsync();

            OrchestrationInstance id = await client.CreateOrchestrationInstanceAsync(
                typeof(GenerationSignalOrchestration), 5);

            var signalId = new OrchestrationInstance {
                InstanceId = id.InstanceId
            };

            await Task.Delay(2 * 500);

            await client.RaiseEventAsync(signalId, "Count", "1");

            GenerationSignalOrchestration.signal.Set();

            await Task.Delay(2 * 500);

            GenerationSignalOrchestration.signal.Reset();
            await client.RaiseEventAsync(signalId, "Count", "2");

            await Task.Delay(2 * 500);

            await client.RaiseEventAsync(signalId, "Count", "3"); // will be recieved by next generation

            GenerationSignalOrchestration.signal.Set();

            await Task.Delay(2 * 500);

            GenerationSignalOrchestration.signal.Reset();
            await client.RaiseEventAsync(signalId, "Count", "4");

            await Task.Delay(2 * 500);

            await client.RaiseEventAsync(signalId, "Count", "5"); // will be recieved by next generation

            await client.RaiseEventAsync(signalId, "Count", "6"); // lost

            await client.RaiseEventAsync(signalId, "Count", "7"); // lost

            GenerationSignalOrchestration.signal.Set();

            OrchestrationState result = await client.WaitForOrchestrationAsync(new OrchestrationInstance { InstanceId = id.InstanceId },
                                                                               TimeSpan.FromSeconds(40), CancellationToken.None);

            Assert.AreEqual(OrchestrationStatus.Completed, result.OrchestrationStatus);
            Assert.AreEqual("5", GenerationSignalOrchestration.Result, "Orchestration Result is wrong!!!");
        }