コード例 #1
0
        public static async Task ClearDownTransientTenantContentStore(FeatureContext context)
        {
            ITenant          transientTenant = TransientTenantManager.GetInstance(context).PrimaryTransientClient;
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context);

            if (transientTenant != null && serviceProvider != null)
            {
                await context.RunAndStoreExceptionsAsync(async() =>
                {
                    ITenantedWorkflowStoreFactory workflowStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
                    IWorkflowStore workflowStore = await workflowStoreFactory.GetWorkflowStoreForTenantAsync(transientTenant).ConfigureAwait(false);
                    if (workflowStore is CosmosWorkflowStore cosmosWorkflowStore)
                    {
                        await cosmosWorkflowStore.Container.DeleteContainerAsync().ConfigureAwait(false);
                    }
                }).ConfigureAwait(false);

                await context.RunAndStoreExceptionsAsync(async() =>
                {
                    ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
                    var workflowInstanceStore = (CosmosWorkflowInstanceStore)await workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(transientTenant).ConfigureAwait(false);
                    await workflowInstanceStore.Container.DeleteContainerAsync().ConfigureAwait(false);
                }).ConfigureAwait(false);
            }
        }
コード例 #2
0
        public async Task GivenIHaveCreatedAndPersistedANewInstanceOfTheDataCatalogWorkflowWithId(string workflowId)
        {
            IWorkflowMessageQueue workflowMessageQueue =
                ContainerBindings.GetServiceProvider(this.featureContext).GetService <IWorkflowMessageQueue>();
            Workflow workflow = DataCatalogWorkflowFactory.Create(workflowId, workflowMessageQueue);

            ITenantedWorkflowStoreFactory storeFactory =
                ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantedWorkflowStoreFactory>();
            ITenantProvider tenantProvider =
                ContainerBindings.GetServiceProvider(this.featureContext).GetService <ITenantProvider>();

            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(async() =>
            {
                try
                {
                    Workflow oldWorkflow = await store.GetWorkflowAsync(workflowId).ConfigureAwait(false);
                    workflow.ETag        = oldWorkflow.ETag;
                }
                catch (WorkflowNotFoundException)
                {
                    // Don't care if there is no old workflow.
                }

                await store.UpsertWorkflowAsync(workflow).ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
コード例 #3
0
        private async Task AddWorkflowToStore(string workflowName, string workflowId, WorkflowEventSubscription[] subscriptions)
        {
            Workflow workflow = TestWorkflowFactory.Get(workflowName);

            workflow.WorkflowEventSubscriptions = subscriptions;
            workflow.Id = workflowId;

            ITenantedWorkflowStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(
                this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            try
            {
                await store.UpsertWorkflowAsync(workflow).ConfigureAwait(false);
            }
            catch (WorkflowConflictException)
            {
                // The workflow already exists. Move on.
            }

            // Get the workflow so we have the correct etag.
            workflow = await store.GetWorkflowAsync(workflow.Id).ConfigureAwait(false);

            this.scenarioContext.Set(workflow, workflowName);
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EngineService"/> class.
 /// </summary>
 /// <param name="workflowEngineFactory">The workflow engine factory.</param>
 /// <param name="workflowStoreFactory">The workflow store factory.</param>
 /// <param name="marainServicesTenancy">The tenancy services.</param>
 public EngineService(
     ITenantedWorkflowEngineFactory workflowEngineFactory,
     ITenantedWorkflowStoreFactory workflowStoreFactory,
     IMarainServicesTenancy marainServicesTenancy)
 {
     this.workflowEngineFactory = workflowEngineFactory;
     this.marainServicesTenancy = marainServicesTenancy;
     this.workflowStoreFactory  = workflowStoreFactory;
 }
コード例 #5
0
        public static async Task TeardownBlobStorage(FeatureContext featureContext)
        {
            // Pretty nasty hack to get rid of the underlying containers for the stores.
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext);
            ITenantProvider  tenantProvider  = serviceProvider.GetRequiredService <ITenantProvider>();

            ITenantedWorkflowStoreFactory workflowStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
            var workflowStore = (BlobStorageWorkflowStore)await workflowStoreFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            await featureContext.RunAndStoreExceptionsAsync(
                () => workflowStore.Container.DeleteAsync()).ConfigureAwait(false);
        }
コード例 #6
0
        public async Task ThenThereShouldBeAWorkflowWithTheIdInTheWorkflowStore(string id)
        {
            ITenantedWorkflowStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            try
            {
                _ = await store.GetWorkflowAsync(id).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Assert.Fail($"Couldn't find a workflow with id {id}: {ex}");
            }
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TenantedWorkflowEngineFactory"/> class.
 /// </summary>
 /// <param name="configuration">Configuration containing the base cloud event publisher source that will be used to create a tenant-specific source for the workflow engine.</param>
 /// <param name="workflowStoreFactory">The factory for retrieving tenanted workflow stores.</param>
 /// <param name="workflowInstanceStoreFactory">The factory for retrieving tenanted workflow instance stores.</param>
 /// <param name="leaseProvider">The lease provider.</param>
 /// <param name="cloudEventPublisherFactory">The publisher factory for workflow events.</param>
 /// <param name="logger">The logger.</param>
 public TenantedWorkflowEngineFactory(
     TenantedWorkflowEngineFactoryConfiguration configuration,
     ITenantedWorkflowStoreFactory workflowStoreFactory,
     ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory,
     ILeaseProvider leaseProvider,
     ITenantedCloudEventPublisherFactory cloudEventPublisherFactory,
     ILogger <IWorkflowEngine> logger)
 {
     this.leaseProvider                = leaseProvider ?? throw new ArgumentNullException(nameof(leaseProvider));
     this.logger                       = logger ?? throw new ArgumentNullException(nameof(logger));
     this.workflowStoreFactory         = workflowStoreFactory ?? throw new ArgumentNullException(nameof(workflowStoreFactory));
     this.workflowInstanceStoreFactory = workflowInstanceStoreFactory ?? throw new ArgumentNullException(nameof(workflowInstanceStoreFactory));
     this.cloudEventPublisherFactory   = cloudEventPublisherFactory ?? throw new ArgumentNullException(nameof(cloudEventPublisherFactory));
     this.configuration                = configuration;
 }
        public async Task GivenGivenIHaveCreatedAndPersistedAWorkflowContainingAnExternalConditionWithIdAsync(string workflowId)
        {
            ExternalServiceBindings.ExternalService externalService            = ExternalServiceBindings.GetService(this.scenarioContext);
            IServiceIdentityAccessTokenSource       serviceIdentityTokenSource =
                ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <IServiceIdentityAccessTokenSource>();

            IJsonSerializerSettingsProvider serializerSettingsProvider =
                ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <IJsonSerializerSettingsProvider>();

            Workflow workflow = ExternalConditionWorkflowFactory.Create(
                workflowId,
                externalService.TestUrl.ToString(),
                serviceIdentityTokenSource,
                serializerSettingsProvider);

            this.condition = workflow.GetInitialState().Transitions
                             .Single()
                             .Conditions
                             .OfType <InvokeExternalServiceCondition>()
                             .Single();

            ITenantedWorkflowStoreFactory storeFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                         .GetService <ITenantedWorkflowStoreFactory>();

            ITenantProvider tenantProvider =
                ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <ITenantProvider>();

            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(async() =>
            {
                try
                {
                    Workflow oldWorkflow = await store.GetWorkflowAsync(workflowId).ConfigureAwait(false);
                    workflow.ETag        = oldWorkflow.ETag;
                }
                catch (WorkflowNotFoundException)
                {
                    // Don't care if there is no old workflow.
                }

                await store.UpsertWorkflowAsync(workflow).ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
コード例 #9
0
        private async Task VerifyWorkflowInstanceState(string instanceId, string expectedStateName, bool useAssert = true)
        {
            WorkflowInstance instance = await this.GetWorkflowInstance(instanceId).ConfigureAwait(false);

            ITenantedWorkflowStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            Workflow workflow = await store.GetWorkflowAsync(instance.WorkflowId).ConfigureAwait(false);

            WorkflowState state = workflow.GetState(instance.StateId);

            if (useAssert)
            {
                Assert.AreEqual(expectedStateName, state.DisplayName);
            }
            else
            {
                if (expectedStateName != state.DisplayName)
                {
                    throw new Exception();
                }
            }
        }
コード例 #10
0
        public async Task ThenTheWorkflowInstanceWithIdShouldBeInTheStateCalled(string instanceId, string stateName)
        {
            ITenantedWorkflowStoreFactory storeFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                         .GetService <ITenantedWorkflowStoreFactory>();
            ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                                         .GetService <ITenantedWorkflowInstanceStoreFactory>();

            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext)
                                             .GetService <ITenantProvider>();

            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false);

            Workflow workflow = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => store.GetWorkflowAsync(instance.WorkflowId)).ConfigureAwait(false);

            WorkflowState currentState = workflow.GetState(instance.StateId);

            Assert.AreEqual(stateName, currentState.DisplayName);
        }