Ejemplo n.º 1
0
 public string ReplayOrchestration(Type orchestrationType, string serializedHistoryEvents)
 {
     return(ReplayOrchestration(
                NameVersionHelper.GetDefaultName(orchestrationType),
                NameVersionHelper.GetDefaultVersion(orchestrationType),
                serializedHistoryEvents));
 }
Ejemplo n.º 2
0
 /// <inheritdoc/>
 public override Task <T> CreateSubOrchestrationInstance <T>(Type orchestrationType, object input)
 {
     PreUpdateProperties();
     return(Wrap(CreateSubOrchestrationInstance <T>(
                     TypeShortName.ToString(orchestrationType, includeTopAssembly: false),
                     NameVersionHelper.GetDefaultVersion(orchestrationType),
                     input)));
 }
Ejemplo n.º 3
0
 /// <inheritdoc/>
 public override Task <TResult> ScheduleTask <TResult>(Type activityType, params object[] parameters)
 {
     PreUpdateProperties();
     return(Wrap(ScheduleTask <TResult>(
                     TypeShortName.ToString(activityType, includeTopAssembly: false),
                     NameVersionHelper.GetDefaultVersion(activityType),
                     parameters)));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskActivityDescriptor"/> class.
        /// This activity will have its <see cref="MemberInfo.DeclaringType"/> fetched from the
        /// <see cref="IServiceProvider"/> and invoked on it.
        /// </summary>
        /// <param name="method">The method info.</param>
        /// <param name="name">The name of the type.</param>
        /// <param name="version">The version of the type.</param>
        public TaskActivityDescriptor(MethodInfo method, string name = null, string version = null)
        {
            Method = Check.NotNull(method, nameof(method));
            Check.NotNull(method.DeclaringType, nameof(method) + nameof(method.DeclaringType));

            Name    = name ?? NameVersionHelper.GetDefaultName(method);
            Version = version ?? NameVersionHelper.GetDefaultVersion(method);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskOrchestrationDescriptor"/> class.
        /// </summary>
        /// <param name="type">The service type.</param>
        /// <param name="name">The name of the type.</param>
        /// <param name="version">The version of the type.</param>
        public TaskOrchestrationDescriptor(Type type, string name = null, string version = null)
        {
            Check.NotNull(type, nameof(type));
            Check.ConcreteType <TaskOrchestration>(type, nameof(type));

            Type    = type;
            Name    = name ?? TypeShortName.ToString(type, false);
            Version = version ?? NameVersionHelper.GetDefaultVersion(type);
        }
        public void Ctor_MethodInfo_DefaultNameVersion()
        {
            var methodInfo = typeof(IMyServce).GetMethod(nameof(IMyServce.SomethingAsync));
            var descriptor = new TaskActivityDescriptor(methodInfo);

            descriptor.Type.Should().BeNull();
            descriptor.Method.Should().BeSameAs(methodInfo);
            descriptor.Name.Should().Be(NameVersionHelper.GetDefaultName(methodInfo));
            descriptor.Version.Should().Be(NameVersionHelper.GetDefaultVersion(methodInfo));
        }
Ejemplo n.º 7
0
 /// <inheritdoc/>
 public override Task <T> ScheduleWithRetry <T>(
     Type taskActivityType, RetryOptions retryOptions, params object[] parameters)
 {
     PreUpdateProperties();
     return(Wrap(ScheduleWithRetry <T>(
                     TypeShortName.ToString(taskActivityType, includeTopAssembly: false),
                     NameVersionHelper.GetDefaultVersion(taskActivityType),
                     retryOptions,
                     parameters)));
 }
Ejemplo n.º 8
0
        public void Ctor_TypeSet_DerivedType()
        {
            // arrange, act
            var descriptor = new NamedTypeDescriptor <IInterfaceType>(typeof(ConcreteType));

            // assert
            descriptor.Type.Should().Be(typeof(ConcreteType));
            descriptor.Name.Should().Be(NameVersionHelper.GetDefaultName(typeof(ConcreteType)));
            descriptor.Version.Should().Be(NameVersionHelper.GetDefaultVersion(typeof(ConcreteType)));
        }
Ejemplo n.º 9
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));
        }
        /// <summary>
        /// Initialize these values with the provided type.
        /// </summary>
        /// <param name="type">The type this attribute was applied to.</param>
        internal void InitializeIfNecessary(Type type)
        {
            if (string.IsNullOrEmpty(Name))
            {
                Name = NameVersionHelper.GetDefaultName(type);
            }

            if (string.IsNullOrEmpty(Version))
            {
                Version = NameVersionHelper.GetDefaultVersion(type);
            }
        }
 public static IDurableTaskWorkerBuilder AddOrchestrationMethod(
     this IDurableTaskWorkerBuilder builder,
     Type type,
     MethodInfo methodInfo,
     string name    = null,
     string version = null)
 {
     return(builder.AddOrchestration(
                p => new MethodTaskOrchestration(ActivatorUtilities.GetServiceOrCreateInstance(p, type), methodInfo),
                name ?? NameVersionHelper.GetDefaultName(methodInfo),
                version ?? NameVersionHelper.GetDefaultVersion(methodInfo)));
 }
        public static IDurableTaskWorkerBuilder AddOrchestration(
            this IDurableTaskWorkerBuilder builder,
            Type type,
            string name    = null,
            string version = null)
        {
            builder.Services.AddScoped(type, type);

            return(builder.AddOrchestration(
                       p => ActivatorUtilities.GetServiceOrCreateInstance(p, type) as TaskOrchestration,
                       name ?? NameVersionHelper.GetDefaultName(type),
                       version ?? NameVersionHelper.GetDefaultVersion(type)));
        }
        public async Task SimplestGreetingsJumpStartDelayTest()
        {
            var    sbService = (ServiceBusOrchestrationService)taskHub.orchestrationService;
            string name      = NameVersionHelper.GetDefaultName(typeof(SimplestGreetingsOrchestration));
            string version   = NameVersionHelper.GetDefaultVersion(typeof(SimplestGreetingsOrchestration));

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

            OrchestrationInstance id = await TestHelpers.CreateOrchestrationInstanceAsync(sbService, name, version, null, null, true, false);

            // Wait only 8 seconds, the jumptstartinterval is set to 10
            bool isCompleted = await TestHelpers.WaitForInstanceAsync(client, id, 8);

            Assert.IsFalse(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 8));
        }
        public async Task DupeDetectionByInstanceStoreTest()
        {
            var    sbService = (ServiceBusOrchestrationService)taskHub.orchestrationService;
            string name      = NameVersionHelper.GetDefaultName(typeof(SimplestGreetingsOrchestration));
            string version   = NameVersionHelper.GetDefaultVersion(typeof(SimplestGreetingsOrchestration));

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

            // Write to jumpstart table only
            OrchestrationInstance id = await TestHelpers.CreateOrchestrationInstanceAsync(sbService, name, version, null, null, true, false);

            // Try to create orchestraton with same instanceId
            var exception = await TestHelpers.ThrowsAsync <OrchestrationAlreadyExistsException>(() => TestHelpers.CreateOrchestrationInstanceAsync(sbService, name, version, id.InstanceId, null, false, false));

            Assert.IsTrue(exception.Message.Contains("already exists"));
        }
        public async Task SimplestGreetingsJumpStartTest()
        {
            var    sbService = (ServiceBusOrchestrationService)taskHub.orchestrationService;
            string name      = NameVersionHelper.GetDefaultName(typeof(SimplestGreetingsOrchestration));
            string version   = NameVersionHelper.GetDefaultVersion(typeof(SimplestGreetingsOrchestration));

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

            OrchestrationInstance id = await TestHelpers.CreateOrchestrationInstanceAsync(sbService, name, version, null, null, true, false);

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

            Assert.IsTrue(isCompleted, TestHelpers.GetInstanceNotCompletedMessage(client, id, 60));
            Assert.AreEqual("Greeting send to Gabbar", SimplestGreetingsOrchestration.Result,
                            "Orchestration Result is wrong!!!");
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
            protected override async Task ExecuteAsync(CancellationToken stoppingToken)
            {
                OrchestrationInstance instance = await _client.CreateOrchestrationInstanceAsync(
                    NameVersionHelper.GetDefaultName(typeof(GreetingsOrchestration)),
                    NameVersionHelper.GetDefaultVersion(typeof(GreetingsOrchestration)),
                    _instanceId,
                    null,
                    new Dictionary <string, string>()
                {
                    ["CorrelationId"] = Guid.NewGuid().ToString(),
                });

                OrchestrationState result = await _client.WaitForOrchestrationAsync(
                    instance, TimeSpan.FromSeconds(60));

                _console.WriteLine();
                _console.WriteLine($"Orchestration finished.");
                _console.WriteLine($"Run stats: {result.Status}");
                _console.WriteLine("Press Ctrl+C to exit");
            }
Ejemplo n.º 18
0
        public async Task DupeDetectionByServiceBusQueueTest()
        {
            var    sbService = (ServiceBusOrchestrationService)this.taskHub.orchestrationService;
            string name      = NameVersionHelper.GetDefaultName(typeof(SimplestGreetingsOrchestration));
            string version   = NameVersionHelper.GetDefaultVersion(typeof(SimplestGreetingsOrchestration));

            await this.taskHub.AddTaskOrchestrations(typeof(GenerationBasicOrchestration))
            .AddTaskActivities(new GenerationBasicTask())
            .AddTaskOrchestrations(typeof(SimplestGreetingsOrchestration))
            .AddTaskActivities(typeof(SimplestGetUserTask), typeof(SimplestSendGreetingTask))
            .StartAsync();

            GenerationBasicTask.GenerationCount = 0;
            var generationCount      = 0;
            OrchestrationInstance id = await this.client.CreateOrchestrationInstanceAsync(typeof(GenerationBasicOrchestration), generationCount);

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

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

            // We use instanceId and execution for SB level d-dup
            // Write to ServiceBus only. SB drops the message and the orchestration does not start
            id = await TestHelpers.CreateOrchestrationInstanceAsync(sbService, name, version, id.InstanceId, id.ExecutionId, false, true);

            await Task.Delay(TimeSpan.FromSeconds(5));

            // ReSharper disable once UnusedVariable
            long count = TestHelpers.GetOrchestratorQueueMessageCount();

            IList <OrchestrationState> executions = await this.client.GetOrchestrationStateAsync(id.InstanceId, true);

            Assert.AreEqual(1, executions.Count, "Duplicate detection failed and orchestration ran for second time");

            // Make sure the second orchestration never started by checking the output from first orchestration
            Assert.AreNotEqual("Greeting send to Gabbar", executions[0].Output);
            Assert.AreEqual(generationCount + 1, int.Parse(executions[0].Output));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedTypeDescriptor{TBase}"/> class.
 /// </summary>
 /// <param name="type">The service type.</param>
 public NamedTypeDescriptor(Type type)
     : this(type, NameVersionHelper.GetDefaultName(type), NameVersionHelper.GetDefaultVersion(type))
 {
 }
Ejemplo n.º 20
0
 void Initialize(object obj)
 {
     Name    = NameVersionHelper.GetDefaultName(obj);
     Version = NameVersionHelper.GetDefaultVersion(obj);
 }
Ejemplo n.º 21
0
 public Task <T> RunOrchestration <T>(OrchestrationInstance instance, Type orchestrationType, object input)
 {
     return(RunOrchestration <T>(instance, NameVersionHelper.GetDefaultName(orchestrationType),
                                 NameVersionHelper.GetDefaultVersion(orchestrationType), input));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskAliasAttribute"/> class.
 /// </summary>
 /// <param name="type">The type to get the default name and version from.</param>
 /// <param name="version">The version for this task.</param>
 public TaskAliasAttribute(Type type, string version = null)
 {
     Check.NotNull(type, nameof(type));
     Name    = NameVersionHelper.GetDefaultName(type);
     Version = string.IsNullOrEmpty(version) ? NameVersionHelper.GetDefaultVersion(type) : version;
 }
Ejemplo n.º 23
0
 void Initialize(object obj)
 {
     this.Name    = $"@{NameVersionHelper.GetDefaultName(obj)}";
     this.Version = NameVersionHelper.GetDefaultVersion(obj);
 }
Ejemplo n.º 24
0
 void Initialize()
 {
     Name    = NameVersionHelper.GetDefaultName(typeof(T));
     Version = NameVersionHelper.GetDefaultVersion(typeof(T));
 }