Esempio n. 1
0
    public void Write()
    {
        var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../");

        foreach (var variant in Enum.GetValues(typeof(BuildSqlVariant)).Cast <BuildSqlVariant>())
        {
            Write(directory, variant, "TimeoutCreate", TimeoutScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "TimeoutDrop", TimeoutScriptBuilder.BuildDropScript(variant));

            Write(directory, variant, "OutboxCreate", OutboxScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "OutboxDrop", OutboxScriptBuilder.BuildDropScript(variant));

            Write(directory, variant, "SubscriptionCreate", SubscriptionScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "SubscriptionDrop", SubscriptionScriptBuilder.BuildDropScript(variant));

            var sagaDefinition = new SagaDefinition(
                tableSuffix: "OrderSaga",
                name: "OrderSaga",
                correlationProperty: new CorrelationProperty(
                    name: "OrderNumber",
                    type: CorrelationPropertyType.Int),
                transitionalCorrelationProperty: new CorrelationProperty(
                    name: "OrderId",
                    type: CorrelationPropertyType.Guid));
            Write(directory, variant, "SagaCreate", SagaScriptBuilder.BuildCreateScript(sagaDefinition, variant));
            Write(directory, variant, "SagaDrop", SagaScriptBuilder.BuildDropScript(sagaDefinition, variant));
        }
        foreach (var variant in Enum.GetValues(typeof(SqlVariant)).Cast <SqlVariant>())
        {
            var timeoutCommands = TimeoutCommandBuilder.Build(sqlVariant: variant, tablePrefix: "EndpointName");
            Write(directory, variant, "TimeoutAdd", timeoutCommands.Add);
            Write(directory, variant, "TimeoutNext", timeoutCommands.Next);
            Write(directory, variant, "TimeoutRange", timeoutCommands.Range);
            Write(directory, variant, "TimeoutRemoveById", timeoutCommands.RemoveById);
            Write(directory, variant, "TimeoutRemoveBySagaId", timeoutCommands.RemoveBySagaId);
            Write(directory, variant, "TimeoutPeek", timeoutCommands.Peek);

            var outboxCommands = OutboxCommandBuilder.Build(variant, "EndpointName");
            Write(directory, variant, "OutboxCleanup", outboxCommands.Cleanup);
            Write(directory, variant, "OutboxGet", outboxCommands.Get);
            Write(directory, variant, "OutboxSetAsDispatched", outboxCommands.SetAsDispatched);
            Write(directory, variant, "OutboxStore", outboxCommands.Store);

            var subscriptionCommands = SubscriptionCommandBuilder.Build(variant, "EndpointName");
            Write(directory, variant, "SubscriptionSubscribe", subscriptionCommands.Subscribe);
            Write(directory, variant, "SubscriptionUnsubscribe", subscriptionCommands.Unsubscribe);
            Write(directory, variant, "SubscriptionGetSubscribers", subscriptionCommands.GetSubscribers(new List <MessageType>
            {
                new MessageType("MessageTypeName", new Version())
            }));

            var sagaCommandBuilder = new SagaCommandBuilder(variant, "EndpointName");
            Write(directory, variant, "SagaComplete", sagaCommandBuilder.BuildCompleteCommand("SagaName"));
            Write(directory, variant, "SagadGetByProperty", sagaCommandBuilder.BuildGetByPropertyCommand("SagaName", "PropertyName"));
            Write(directory, variant, "SagaGetBySagaId", sagaCommandBuilder.BuildGetBySagaIdCommand("SagaName"));
            Write(directory, variant, "SagaSave", sagaCommandBuilder.BuildSaveCommand("SagaName", "CorrelationPproperty", "TransitionalCorrelationPproperty"));
            Write(directory, variant, "SagaUpdate", sagaCommandBuilder.BuildUpdateCommand("SagaName", "TransitionalCorrelationPproperty"));
        }
    }
 public TimeoutPersister(IConnectionManager connectionManager, string tablePrefix, SqlDialect sqlDialect, TimeSpan timeoutsCleanupExecutionInterval, Func <DateTime> utcNow)
 {
     this.connectionManager = connectionManager;
     this.sqlDialect        = sqlDialect;
     this.timeoutsCleanupExecutionInterval = timeoutsCleanupExecutionInterval;
     this.utcNow            = utcNow;
     timeoutCommands        = TimeoutCommandBuilder.Build(sqlDialect, tablePrefix);
     oldestSupportedTimeout = sqlDialect.OldestSupportedTimeout;
 }
Esempio n. 3
0
    public void RemoveBySagaId()
    {
        var timeoutCommands = TimeoutCommandBuilder.Build(sqlDialect, "TheTablePrefix");

        using (NamerFactory.AsEnvironmentSpecificTest(() => GetType().Name))
        {
            Approvals.Verify(timeoutCommands.RemoveBySagaId);
        }
    }
Esempio n. 4
0
    public TimeoutPersister(Func <DbConnection> connectionBuilder, string tablePrefix, SqlVariant sqlVariant, string schema, TimeSpan timeoutsCleanupExecutionInterval)
    {
        this.connectionBuilder = connectionBuilder;
        this.timeoutsCleanupExecutionInterval = timeoutsCleanupExecutionInterval;
        timeoutCommands = TimeoutCommandBuilder.Build(sqlVariant, tablePrefix, schema);
        commandBuilder  = new CommandBuilder(sqlVariant);

        switch (sqlVariant)
        {
        case SqlVariant.MsSqlServer:
            oldestSupportedTimeout = SqlDateTime.MinValue.Value;
            break;

        case SqlVariant.Oracle:
        case SqlVariant.MySql:
            oldestSupportedTimeout = new DateTime(1000, 1, 1);
            break;

        default:
            throw new NotSupportedException("Not supported SQL dialect: " + sqlVariant);
        }
    }
    public void Write()
    {
        var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");

        foreach (var variant in Enum.GetValues(typeof(BuildSqlDialect)).Cast <BuildSqlDialect>())
        {
            Write(directory, variant, "TimeoutCreate", TimeoutScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "TimeoutDrop", TimeoutScriptBuilder.BuildDropScript(variant));

            Write(directory, variant, "OutboxCreate", OutboxScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "OutboxDrop", OutboxScriptBuilder.BuildDropScript(variant));

            Write(directory, variant, "SubscriptionCreate", SubscriptionScriptBuilder.BuildCreateScript(variant));
            Write(directory, variant, "SubscriptionDrop", SubscriptionScriptBuilder.BuildDropScript(variant));

            var sagaDefinition = new SagaDefinition(
                tableSuffix: "OrderSaga",
                name: "OrderSaga",
                correlationProperty: new CorrelationProperty(
                    name: "OrderNumber",
                    type: CorrelationPropertyType.Int),
                transitionalCorrelationProperty: new CorrelationProperty(
                    name: "OrderId",
                    type: CorrelationPropertyType.Guid));
            Write(directory, variant, "SagaCreate", SagaScriptBuilder.BuildCreateScript(sagaDefinition, variant));
            Write(directory, variant, "SagaDrop", SagaScriptBuilder.BuildDropScript(sagaDefinition, variant));
        }

        var dialects = new SqlDialect[]
        {
            new SqlDialect.MsSqlServer(),
            new SqlDialect.MySql(),
            new SqlDialect.Oracle(),
            new SqlDialect.PostgreSql()
        };

        foreach (var dialect in dialects)
        {
            var timeoutCommands = TimeoutCommandBuilder.Build(
                sqlDialect: dialect,
                tablePrefix: "EndpointName");
            Write(directory, dialect, "TimeoutAdd", timeoutCommands.Add);
            Write(directory, dialect, "TimeoutNext", timeoutCommands.Next);
            Write(directory, dialect, "TimeoutRange", timeoutCommands.Range);
            Write(directory, dialect, "TimeoutRemoveById", timeoutCommands.RemoveById);
            Write(directory, dialect, "TimeoutRemoveBySagaId", timeoutCommands.RemoveBySagaId);
            Write(directory, dialect, "TimeoutPeek", timeoutCommands.Peek);

            var outboxCommands = OutboxCommandBuilder.Build(
                tablePrefix: "EndpointName",
                sqlDialect: dialect);
            Write(directory, dialect, "OutboxCleanup", outboxCommands.Cleanup);
            Write(directory, dialect, "OutboxGet", outboxCommands.Get);
            Write(directory, dialect, "OutboxSetAsDispatched", outboxCommands.SetAsDispatched);
            Write(directory, dialect, "OutboxStore", outboxCommands.Store);

            var subscriptionCommands = SubscriptionCommandBuilder.Build(
                sqlDialect: dialect,
                tablePrefix: "EndpointName");
            Write(directory, dialect, "SubscriptionSubscribe", subscriptionCommands.Subscribe);
            Write(directory, dialect, "SubscriptionUnsubscribe", subscriptionCommands.Unsubscribe);
            Write(directory, dialect, "SubscriptionGetSubscribers", subscriptionCommands.GetSubscribers(new List <MessageType>
            {
                new MessageType("MessageTypeName", new Version())
            }));

            Write(directory, dialect, "SagaComplete", dialect.BuildCompleteCommand("EndpointName_SagaName"));
            Write(directory, dialect, "SagaGetByProperty", dialect.BuildGetByPropertyCommand("PropertyName", "EndpointName_SagaName"));
            Write(directory, dialect, "SagaGetBySagaId", dialect.BuildGetBySagaIdCommand("EndpointName_SagaName"));
            Write(directory, dialect, "SagaSave", dialect.BuildSaveCommand("CorrelationProperty", "TransitionalCorrelationProperty", "EndpointName_SagaName"));
            Write(directory, dialect, "SagaUpdate", dialect.BuildUpdateCommand("TransitionalCorrelationProperty", "EndpointName_SagaName"));

            // since we don't have doco on oracle saga finders
            if (!(dialect is SqlDialect.Oracle))
            {
                var createSelectWithWhereClause = dialect.BuildSelectFromCommand("EndpointName_SagaName");
                Write(directory, dialect, "SagaSelect", createSelectWithWhereClause("1 = 1"));
            }
        }
    }
    public void RemoveBySagaId()
    {
        var timeoutCommands = TimeoutCommandBuilder.Build(sqlDialect, "TheTablePrefix");

        Approver.Verify(timeoutCommands.RemoveBySagaId, scenario: GetType().Name);
    }
    public void Peek()
    {
        var timeoutCommands = TimeoutCommandBuilder.Build(sqlDialect, "TheTablePrefix");

        Approver.Verify(timeoutCommands.Peek, scenario: GetType().Name);
    }