public PersistenceTestsConfiguration(TimeSpan?transactionTimeout = null) { var statefulService = (StatefulService)TestContext.CurrentContext.Test.Properties.Get("StatefulService"); stateManager = statefulService.StateManager; var timeout = transactionTimeout ?? TimeSpan.FromSeconds(4); SynchronizedStorage = new SynchronizedStorage(stateManager, timeout); SynchronizedStorageAdapter = new SynchronizedStorageAdapter(); OutboxStorage = new OutboxStorage(statefulService.StateManager, timeout); }
public PersistenceTestsConfiguration() { var statefulService = (StatefulService)TestContext.CurrentContext.Test.Properties.Get("StatefulService"); stateManager = statefulService.StateManager; SynchronizedStorage = new SynchronizedStorage(stateManager); SynchronizedStorageAdapter = new SynchronizedStorageAdapter(); var sagaInfoCache = new SagaInfoCache(); sagaInfoCache.Initialize(SagaMetadataCollection); SagaStorage = new SagaPersister(sagaInfoCache); var sagaIdGenerator = new SagaIdGenerator(); sagaIdGenerator.Initialize(sagaInfoCache); SagaIdGenerator = sagaIdGenerator; OutboxStorage = new OutboxStorage(statefulService.StateManager); }
public async Task Configure(CancellationToken cancellationToken = default) { var statefulService = (StatefulService)TestContext.CurrentContext.Test.Properties.Get("StatefulService"); stateManager = statefulService.StateManager; var timeout = SessionTimeout ?? TimeSpan.FromSeconds(4); SynchronizedStorage = new SynchronizedStorage(stateManager, timeout); SynchronizedStorageAdapter = new SynchronizedStorageAdapter(); var sagaInfoCache = new SagaInfoCache(); sagaInfoCache.Initialize(SagaMetadataCollection); SagaStorage = new SagaPersister(sagaInfoCache); var sagaIdGenerator = new SagaIdGenerator(); sagaIdGenerator.Initialize(sagaInfoCache); SagaIdGenerator = sagaIdGenerator; OutboxStorage = new OutboxStorage(statefulService.StateManager, timeout); await stateManager.RegisterOutboxStorage((OutboxStorage)OutboxStorage, cancellationToken).ConfigureAwait(false); }
public Task Configure(CancellationToken cancellationToken = default) { var variant = (SqlTestVariant)Variant.Values[0]; var dialect = variant.Dialect; var buildDialect = variant.BuildDialect; var connectionFactory = variant.ConnectionFactory; var pessimisticMode = variant.UsePessimisticMode; if (SessionTimeout.HasValue) { dialect = new TimeoutSettingDialect(dialect, (int)SessionTimeout.Value.TotalSeconds); } var infoCache = new SagaInfoCache( null, Serializer.JsonSerializer, reader => new JsonTextReader(reader), writer => new JsonTextWriter(writer), "PersistenceTests_", dialect, SagaMetadataCollection, name => ShortenSagaName(name)); var connectionManager = new ConnectionManager(connectionFactory); SagaIdGenerator = new DefaultSagaIdGenerator(); SagaStorage = new SagaPersister(infoCache, dialect); SynchronizedStorage = new SynchronizedStorage(connectionManager, infoCache, null); SynchronizedStorageAdapter = new StorageAdapter(connectionManager, infoCache, dialect, null); OutboxStorage = CreateOutboxPersister(connectionManager, dialect, false, false); SupportsPessimisticConcurrency = pessimisticMode; GetContextBagForSagaStorage = () => { var contextBag = new ContextBag(); contextBag.Set(new IncomingMessage("MessageId", new Dictionary <string, string>(), new byte[0])); return(contextBag); }; GetContextBagForOutbox = () => { var contextBag = new ContextBag(); contextBag.Set(new IncomingMessage("MessageId", new Dictionary <string, string>(), new byte[0])); return(contextBag); }; using (var connection = connectionFactory()) { connection.Open(); foreach (var saga in SagaMetadataCollection) { CorrelationProperty correlationProperty = null; if (saga.TryGetCorrelationProperty(out var propertyMetadata)) { correlationProperty = new CorrelationProperty(propertyMetadata.Name, CorrelationPropertyType.String); } var tableName = ShortenSagaName(saga.SagaType.Name); var definition = new SagaDefinition(tableName, saga.EntityName, correlationProperty); connection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(definition, buildDialect), "PersistenceTests"); connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(definition, buildDialect), "PersistenceTests"); } connection.ExecuteCommand(OutboxScriptBuilder.BuildDropScript(buildDialect), "PersistenceTests"); connection.ExecuteCommand(OutboxScriptBuilder.BuildCreateScript(buildDialect), "PersistenceTests"); } return(Task.CompletedTask); }