public async Task ThenTheWorkflowInstanceWithIdShouldContainContextItems(string instanceId, Table expectedContextItems) { ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext) .GetService <ITenantedWorkflowInstanceStoreFactory>(); ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext) .GetService <ITenantProvider>(); IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false); WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync( () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false); Assert.AreEqual( expectedContextItems.Rows.Count, instance.Context.Count, "The number of context items in the workflow instance is different to the number of items in the specified list"); foreach (TableRow current in expectedContextItems.Rows) { Assert.IsTrue( instance.Context.TryGetValue(current[0], out string actualValue), $"The instance context does not contain expected item with key '{current[0]}'"); Assert.AreEqual(current[1], actualValue, $"The instance context does not contain the expected value for key '{current[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); } }
/// <summary> /// Initializes a new instance of the <see cref="GetWorkflowInstanceCountActivity"/> class. /// </summary> /// <param name="workflowInstanceStoreFactory">The factory class for the workflow instance store.</param> /// <param name="serializerSettingsProvider">The serialization settings provider.</param> /// <param name="tenantProvider">The tenant provider.</param> public GetWorkflowInstanceCountActivity( ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory, IJsonSerializerSettingsProvider serializerSettingsProvider, ITenantProvider tenantProvider) { this.workflowInstanceStoreFactory = workflowInstanceStoreFactory; this.tenantProvider = tenantProvider; this.serializerSettingsProvider = serializerSettingsProvider; }
public async Task ThenThereShouldBeANewWorkflowInstanceInTheWorkflowInstanceStore(int expected) { ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false); IEnumerable <string> instances = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false); Assert.AreEqual(expected, instances.Count()); }
public async Task TheWorkflowInstanceStoreIsEmpty() { ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false); IEnumerable <string> instanceIds = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false); foreach (string current in instanceIds) { await store.DeleteWorkflowInstanceAsync(current).ConfigureAwait(false); } }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryWorkflowMessageQueue" /> class. /// </summary> /// <param name="workflowEngineFactory"> /// The workflow engine factory to create the engine to which to hand off the triggers. /// </param> /// <param name="workflowInstanceStoreFactory"> /// The workflow instance store factory to use to access underlying instance storage. /// </param> /// <param name="tenantProvider"> /// The tenant provider that will be used when accessing storage. /// </param> /// <param name="propertyBagFactory"> /// The <see cref="IPropertyBagFactory"/> that will be used when creating new /// <see cref="WorkflowMessageEnvelope"/> instances. /// </param> /// <param name="logger"> /// Logger to use to write diagnostic messages. /// </param> /// <remarks> /// <para> /// The queue will be created in the "Stopped" state. To begin processing, /// call the <see cref="StartProcessing" /> method. /// </para> /// </remarks> public InMemoryWorkflowMessageQueue( ITenantedWorkflowEngineFactory workflowEngineFactory, ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory, ITenantProvider tenantProvider, IPropertyBagFactory propertyBagFactory, ILogger <InMemoryWorkflowMessageQueue> logger) { this.logger = logger; this.tenantProvider = tenantProvider; this.workflowEngineFactory = workflowEngineFactory; this.queue = new ConcurrentQueue <WorkflowMessageEnvelope>(); this.workflowInstanceStoreFactory = workflowInstanceStoreFactory; this.propertyBagFactory = propertyBagFactory; }
/// <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 ThenTheWorkflowInstanceWithIdShouldHaveStatus(string instanceId, string expectedStatus) { ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext) .GetService <ITenantedWorkflowInstanceStoreFactory>(); ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext) .GetService <ITenantProvider>(); IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false); WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync( () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false); Assert.AreEqual(expectedStatus, instance.Status.ToString()); }
private async Task <WorkflowInstance> GetWorkflowInstance(string id, bool failTestOnException = true) { await this.EnsureWorkflowInstanceIsNotBeingModified(id).ConfigureAwait(false); ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false); try { WorkflowInstance instance = await store.GetWorkflowInstanceAsync(id).ConfigureAwait(false); return(instance); } catch (Exception ex) when(failTestOnException) { Assert.Fail($"Couldn't find an instance with id {id}: {ex}"); } return(null); }
public static async Task TeardownCosmosDb(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 = (CosmosWorkflowStore)await workflowStoreFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync( () => workflowStore.Container.DeleteContainerAsync()).ConfigureAwait(false); ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>(); var workflowInstanceStore = (CosmosWorkflowInstanceStore)await workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync( () => workflowInstanceStore.Container.DeleteContainerAsync()).ConfigureAwait(false); await featureContext.RunAndStoreExceptionsAsync( () => featureContext.Get <Container>(TestDocumentsRepository).DeleteContainerAsync()).ConfigureAwait(false); }
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); }