public void It_throws_if_non_transport_transaction_scope_exists()
    {
        if (!SupportsDistributedTransactions)
        {
            Assert.Ignore();
        }
        using (new TransactionScope())
        {
            var transportTransaction = new TransportTransaction();
            transportTransaction.Set(Transaction.Current);
            using (new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled))
            {
                var ex = Assert.ThrowsAsync <Exception>(() => sqlDialect.Convert().TryAdaptTransportConnection(transportTransaction, new ContextBag(), dbConnection,
                                                                                                               (conn, tx, arg3) => new StorageSession(conn, tx, false, null)));

                StringAssert.StartsWith("A TransactionScope has been opened in the current context overriding the one created by the transport.", ex.Message);
            }
        }
    }
Exemplo n.º 2
0
    OutboxPersister Setup(string theSchema)
    {
        var persister = new OutboxPersister(
            connectionManager: connectionManager,
            tablePrefix: $"{GetTablePrefix()}_",
            sqlDialect: sqlDialect.Convert(theSchema),
            cleanupBatchSize: 5);

        using (var connection = GetConnection()(theSchema))
        {
            connection.Open();
            connection.ExecuteCommand(OutboxScriptBuilder.BuildDropScript(sqlDialect), GetTablePrefix(), schema: theSchema);
            connection.ExecuteCommand(OutboxScriptBuilder.BuildCreateScript(sqlDialect), GetTablePrefix(), schema: theSchema);
        }
        return(persister);
    }
    SagaPersister SetUp(string endpointName, string theSchema)
    {
        var runtimeSqlDialect = sqlDialect.Convert(theSchema);

        var sagaMetadataCollection = new SagaMetadataCollection();

        sagaMetadataCollection.Initialize(GetSagasAndFinders());

        var infoCache = new SagaInfoCache(
            versionSpecificSettings: null,
            jsonSerializer: Serializer.JsonSerializer,
            readerCreator: reader => new JsonTextReader(reader),
            writerCreator: writer => new JsonTextWriter(writer),
            tablePrefix: $"{endpointName}_",
            sqlDialect: runtimeSqlDialect,
            metadataCollection: sagaMetadataCollection,
            nameFilter: sagaName => sagaName);

        return(new SagaPersister(infoCache, runtimeSqlDialect));
    }
    SubscriptionPersister Setup(string theSchema)
    {
        dbConnection = GetConnection();
        tablePrefix  = GetTablePrefix();
        var persister = new SubscriptionPersister(
            connectionBuilder: () => dbConnection(theSchema),
            tablePrefix: $"{tablePrefix}_",
            sqlDialect: sqlDialect.Convert(theSchema),
            cacheFor: TimeSpan.FromSeconds(10)
            );

        using (var connection = dbConnection(theSchema))
        {
            connection.Open();
            connection.ExecuteCommand(SubscriptionScriptBuilder.BuildDropScript(sqlDialect), tablePrefix, schema: theSchema);
            connection.ExecuteCommand(SubscriptionScriptBuilder.BuildCreateScript(sqlDialect), tablePrefix, schema: theSchema);
        }

        return(persister);
    }
    TimeoutPersister Setup(string theSchema, TimeSpan?cleanupInterval = null)
    {
        var name = GetTablePrefix();

        using (var connection = dbConnection(theSchema))
        {
            connection.Open();
            connection.ExecuteCommand(TimeoutScriptBuilder.BuildDropScript(sqlDialect), name, schema: theSchema);
            connection.ExecuteCommand(TimeoutScriptBuilder.BuildCreateScript(sqlDialect), name, schema: theSchema);
        }

        var preventCleanupInterval = goodUtcNowValue - new DateTime() + TimeSpan.FromDays(1); //Prevents entering cleanup mode right away (load timeouts from beginning of time)

        return(new TimeoutPersister(
                   connectionBuilder: () => dbConnection(theSchema),
                   tablePrefix: $"{name}_",
                   sqlDialect: sqlDialect.Convert(theSchema),
                   timeoutsCleanupExecutionInterval: cleanupInterval ?? preventCleanupInterval,
                   utcNow: () => goodUtcNowValue));
    }
Exemplo n.º 6
0
    OutboxPersister Setup(string theSchema)
    {
        var dialect        = sqlDialect.Convert(theSchema);
        var outboxCommands = OutboxCommandBuilder.Build(dialect, $"{GetTablePrefix()}_");

        var connectionManager = new ConnectionManager(() => GetConnection()(theSchema));
        var persister         = new OutboxPersister(
            connectionManager: connectionManager,
            sqlDialect: dialect,
            outboxCommands: outboxCommands,
            outboxTransactionFactory: () =>
        {
            ConcurrencyControlStrategy behavior;
            if (pessimistic)
            {
                behavior = new PessimisticConcurrencyControlStrategy(dialect, outboxCommands);
            }
            else
            {
                behavior = new OptimisticConcurrencyControlStrategy(dialect, outboxCommands);
            }

            return(transactionScope
                    ? (ISqlOutboxTransaction) new TransactionScopeSqlOutboxTransaction(behavior, connectionManager, IsolationLevel.ReadCommitted)
                    : new AdoNetSqlOutboxTransaction(behavior, connectionManager, System.Data.IsolationLevel.ReadCommitted));
        },
            cleanupBatchSize: 5);

        using (var connection = GetConnection()(theSchema))
        {
            connection.Open();
            connection.ExecuteCommand(OutboxScriptBuilder.BuildDropScript(sqlDialect), GetTablePrefix(), schema: theSchema);
            connection.ExecuteCommand(OutboxScriptBuilder.BuildCreateScript(sqlDialect), GetTablePrefix(), schema: theSchema);
        }
        return(persister);
    }