コード例 #1
0
    public void SetUp()
    {
        using (var connection = MsSqlConnectionBuilder.Build())
        {
            connection.Open();
            using (var command = connection.CreateCommand())
            {
                command.CommandText = @"
if not exists (
    select  *
    from sys.schemas
    where name = 'schema_name')
exec('create schema schema_name');";
                command.ExecuteNonQuery();
            }
        }
        using (var connection = PostgreSqlConnectionBuilder.Build())
        {
            connection.Open();
            using (var command = connection.CreateCommand())
            {
                command.CommandText = @"create schema if not exists ""SchemaName"";";
                command.ExecuteNonQuery();
            }
        }
    }
コード例 #2
0
    public Task Configure(string endpointName, EndpointConfiguration configuration, RunSettings settings, PublisherMetadata publisherMetadata)
    {
        queueBindings = configuration.GetSettings().Get <QueueBindings>();

        var transportConfig = configuration.UseTransport <SqlServerTransport>();

        transportConfig.UseCustomSqlConnectionFactory(async() =>
        {
            var conn = MsSqlConnectionBuilder.Build();
            await conn.OpenAsync().ConfigureAwait(false);
            return(conn);
        });

        var routingConfig = transportConfig.Routing();

        foreach (var publisher in publisherMetadata.Publishers)
        {
            foreach (var eventType in publisher.Events)
            {
                routingConfig.RegisterPublisher(eventType, publisher.PublisherName);
            }
        }

        return(Task.FromResult(0));
    }
    public async Task SmokeTest(TransportTransactionMode transactionMode)
    {
        var endpointConfiguration = EndpointConfigBuilder.BuildEndpoint(nameof(SqlTransportIntegrationTests));
        var typesToScan           = TypeScanner.NestedTypes <SqlTransportIntegrationTests>();

        endpointConfiguration.SetTypesToScan(typesToScan);
        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();

        transport.Transactions(transactionMode);
        transport.UseCustomSqlConnectionFactory(async() =>
        {
            var connection = MsSqlConnectionBuilder.Build();
            await connection.OpenAsync().ConfigureAwait(false);
            return(connection);
        });
        var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

        persistence.SqlDialect <SqlDialect.MsSqlServer>();
        persistence.ConnectionBuilder(MsSqlConnectionBuilder.Build);
        persistence.DisableInstaller();
        persistence.SubscriptionSettings().DisableCache();

        var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

        var startSagaMessage = new StartSagaMessage
        {
            StartId = Guid.NewGuid()
        };
        await endpoint.SendLocal(startSagaMessage).ConfigureAwait(false);

        ManualResetEvent.WaitOne();
        await endpoint.Stop().ConfigureAwait(false);
    }
        public async Task Should_remove_old_property_after_phase_three()
        {
            var variant    = BuildSqlVariant.MsSqlServer;
            var sagaPhase1 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase1Saga), variant);
            var sagaPhase2 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase2Saga), variant);
            var sagaPhase3 = RuntimeSagaDefinitionReader.GetSagaDefinition(typeof(Phase3Saga), variant);

            using (var connection = MsSqlConnectionBuilder.Build())
            {
                await connection.OpenAsync().ConfigureAwait(false);

                connection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(sagaPhase1, variant), "");
                connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase1, variant), "");
                var phase1Schema = GetSchema(connection);
                connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase2, variant), "");
                var phase2Schema = GetSchema(connection);
                connection.ExecuteCommand(SagaScriptBuilder.BuildCreateScript(sagaPhase3, variant), "");
                var phase3Schema = GetSchema(connection);

                CollectionAssert.Contains(phase1Schema, "Correlation_OrderNumber");
                CollectionAssert.DoesNotContain(phase1Schema, "Correlation_OrderId");

                CollectionAssert.Contains(phase2Schema, "Correlation_OrderNumber");
                CollectionAssert.Contains(phase2Schema, "Correlation_OrderId");

                CollectionAssert.DoesNotContain(phase3Schema, "Correlation_OrderNumber");
                CollectionAssert.Contains(phase3Schema, "Correlation_OrderId");
            }
        }
コード例 #5
0
    public void SetUp()
    {
#if NET452
        ObjectApproval.ObjectApprover.JsonSerializer.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
#endif
        FixCurrentDirectory();
        using (var connection = MsSqlConnectionBuilder.Build())
        {
            connection.Open();
            using (var command = connection.CreateCommand())
            {
                command.CommandText = @"
if not exists (
    select  *
    from sys.schemas
    where name = 'schema_name')
exec('create schema schema_name');";
                command.ExecuteNonQuery();
            }
        }
        using (var connection = PostgreSqlConnectionBuilder.Build())
        {
            connection.Open();
            using (var command = connection.CreateCommand())
            {
                command.CommandText = @"create schema if not exists ""SchemaName"";";
                command.ExecuteNonQuery();
            }
        }
    }
コード例 #6
0
 public void Setup()
 {
     using (var connection = MsSqlConnectionBuilder.Build())
     {
         connection.Open();
         SqlQueueDeletion.DeleteQueuesForEndpoint(connection, "dbo", endpointName);
     }
 }
 protected override Func <DbConnection> GetConnection()
 {
     return(() =>
     {
         var connection = MsSqlConnectionBuilder.Build();
         connection.Open();
         return connection;
     });
 }
コード例 #8
0
        public static void Setup(string tenantId)
        {
            var dbName = "nservicebus_" + tenantId.ToLower();

            using (var conn = MsSqlConnectionBuilder.Build())
            {
                conn.Open();
                conn.ExecuteCommand($"if not exists (select * from sysdatabases where name = '{dbName}') create database {dbName};");
            }
        }
コード例 #9
0
 void Execute(string script)
 {
     using (var sqlConnection = MsSqlConnectionBuilder.Build())
     {
         sqlConnection.Open();
         using (var command = sqlConnection.CreateCommand())
         {
             command.CommandText = script;
             command.ExecuteNonQuery();
         }
     }
 }
コード例 #10
0
 public Task In_native_SqlTransport_mode_enlists_in_native_transaction()
 {
     return(RunTest(e =>
     {
         var transport = e.UseTransport <SqlServerTransport>();
         transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
         transport.UseCustomSqlConnectionFactory(async() =>
         {
             var connection = MsSqlConnectionBuilder.Build();
             await connection.OpenAsync().ConfigureAwait(false);
             return connection;
         });
     }));
 }
コード例 #11
0
 public MixedSagaAndNoOutbox()
 {
     dbConnection = MsSqlConnectionBuilder.Build();
     dbConnection.Open();
     sagaDefinition = new SagaDefinition(
         tableSuffix: nameof(Saga1),
         name: nameof(Saga1),
         correlationProperty: new CorrelationProperty
         (
             name: nameof(Saga1.SagaData.StartId),
             type: CorrelationPropertyType.Guid
         )
         );
 }
 public SqlTransportIntegrationTests()
 {
     dbConnection = MsSqlConnectionBuilder.Build();
     dbConnection.Open();
     sagaDefinition = new SagaDefinition(
         tableSuffix: "Saga1",
         name: "Saga1",
         correlationProperty: new CorrelationProperty
         (
             name: "StartId",
             type: CorrelationPropertyType.Guid
         )
         );
 }
 public MsmqTransportIntegrationTests()
 {
     dbConnection = MsSqlConnectionBuilder.Build();
     dbConnection.Open();
     sagaDefinition = new SagaDefinition(
         tableSuffix: nameof(Saga1),
         name: nameof(Saga1),
         correlationProperty: new CorrelationProperty
         (
             name: nameof(Saga1.SagaData.StartId),
             type: CorrelationPropertyType.Guid
         )
         );
 }
コード例 #14
0
 void Execute(string script)
 {
     using (var sqlConnection = MsSqlConnectionBuilder.Build())
     {
         sqlConnection.Open();
         using (var command = sqlConnection.CreateCommand())
         {
             command.CommandText = script;
             command.AddParameter("tablePrefix", $"{endpointName}_");
             command.AddParameter("schema", "dbo");
             command.ExecuteNonQuery();
         }
     }
 }
コード例 #15
0
 public Task In_DTC_mode_enlists_in_the_ambient_transaction()
 {
     Requires.DtcSupport();
     return(RunTest(e =>
     {
         var transport = e.UseTransport <SqlServerTransport>();
         transport.UseCustomSqlConnectionFactory(async() =>
         {
             var connection = MsSqlConnectionBuilder.Build();
             await connection.OpenAsync().ConfigureAwait(false);
             return connection;
         });
         transport.Transactions(TransportTransactionMode.TransactionScope);
     }));
 }
コード例 #16
0
    public Task Cleanup()
    {
        using (var conn = MsSqlConnectionBuilder.Build())
        {
            conn.Open();

            var queueAddresses = queueBindings.ReceivingAddresses.Select(QueueAddress.Parse).ToList();
            foreach (var address in queueAddresses)
            {
                TryDeleteTable(conn, address);
                TryDeleteTable(conn, new QueueAddress(address.Table + ".Delayed", address.Schema, address.Catalog));
            }
        }
        return(Task.FromResult(0));
    }
コード例 #17
0
 public Task In_outbox_mode_enlists_in_outbox_transaction()
 {
     return(RunTest(configuration =>
     {
         configuration.GetSettings().Set("DisableOutboxTransportCheck", true);
         var transport = configuration.UseTransport <SqlServerTransport>();
         transport.UseCustomSqlConnectionFactory(async() =>
         {
             var connection = MsSqlConnectionBuilder.Build();
             await connection.OpenAsync().ConfigureAwait(false);
             return connection;
         });
         configuration.EnableOutbox();
     }));
 }
コード例 #18
0
 public Task In_DTC_SqlTransport_mode_does_not_escalate()
 {
     Requires.DtcSupport();
     return(RunTest(e =>
     {
         var transport = e.UseTransport <SqlServerTransport>();
         transport.Transactions(TransportTransactionMode.TransactionScope);
         transport.UseCustomSqlConnectionFactory(async() =>
         {
             var connection = MsSqlConnectionBuilder.Build();
             await connection.OpenAsync().ConfigureAwait(false);
             return connection;
         });
         e.Pipeline.Register(new EscalationChecker(), "EscalationChecker");
     }));
 }
コード例 #19
0
    public void SetUp()
    {
        FixCurrentDirectory();
        using (var connection = MsSqlConnectionBuilder.Build())
        {
            connection.Open();
            using (var command = connection.CreateCommand())
            {
                command.CommandText = @"
if not exists (
    select  *
    from sys.schemas
    where name = 'schema_name')
exec('create schema schema_name');";
                command.ExecuteNonQuery();
            }
        }
    }
    public async Task Should_correlate_the_following_message_correctly()
    {
        if (!MsSqlConnectionBuilder.IsSql2016OrHigher())
        {
            return;
        }
        var context = await Scenario.Define <Context>()
                      .WithEndpoint <SagaEndpoint>(b => b
                                                   .When(session =>
        {
            var startSagaMessage = new StartSagaMessage
            {
                Property = "Test"
            };
            return(session.SendLocal(startSagaMessage));
        }))
                      .Done(c => c.HandledOtherMessage)
                      .Run()
                      .ConfigureAwait(false);

        Assert.True(context.StartSagaFinderUsed);
    }
コード例 #21
0
    public void Should_throw_validation_exception()
    {
        if (!MsSqlConnectionBuilder.IsSql2016OrHigher())
        {
            return;
        }
        var exception = Assert.ThrowsAsync <Exception>(async() =>
                                                       await Scenario.Define <Context>()
                                                       .WithEndpoint <SagaEndpoint>(b => b
                                                                                    .When(session =>
        {
            var startSagaMessage = new StartSagaMessage
            {
                Property = "Test"
            };
            return(session.SendLocal(startSagaMessage));
        }))
                                                       .Done(c => c.StartSagaFinderUsed)
                                                       .Run());

        Assert.AreEqual("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition.", exception.Message);
    }
コード例 #22
0
        [TestCase(TransportTransactionMode.ReceiveOnly)]            //Uses the Outbox to ensure exactly-once
        public async Task Should_rollback_changes_when_transport_transaction_is_rolled_back(TransportTransactionMode transactionMode)
        {
            using (var connection = MsSqlConnectionBuilder.Build())
            {
                await connection.OpenAsync().ConfigureAwait(false);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = CreateUserDataTableText;
                    await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                }
            }

            var context = await Scenario.Define <Context>()
                          .WithEndpoint <Endpoint>(
                b => b.When((session, ctx) => session.SendLocal(new MyMessage()
            {
                Id = ctx.TestRunId
            })).DoNotFailOnErrorMessages().CustomConfig(c =>
            {
                if (transactionMode == TransportTransactionMode.ReceiveOnly)
                {
                    c.EnableOutbox();
                }
                else
                {
                    c.ConfigureTransport().Transactions(transactionMode);
                }
            }))
                          .Done(c => c.ReplyReceived)
                          .Run();

            Assert.True(context.ReplyReceived);
            Assert.IsFalse(context.TransactionEscalatedToDTC);
            Assert.AreEqual(2, context.InvocationCount, "Handler should be called twice");
            Assert.AreEqual(1, context.RecordCount, "There should be only once record in the database");
        }
 protected override Func <string, DbConnection> GetConnection()
 {
     return(x => MsSqlConnectionBuilder.Build());
 }
コード例 #24
0
 public void SetUp()
 {
     MsSqlConnectionBuilder.DropDbIfCollationIncorrect();
     MsSqlConnectionBuilder.CreateDbIfNotExists();
 }
コード例 #25
0
    async Task RunTest(Action <EndpointConfiguration> testCase)
    {
        manualResetEvent.Reset();
        string message = null;

        Execute(endpointName, OutboxScriptBuilder.BuildDropScript(BuildSqlDialect.MsSqlServer));
        Execute(endpointName, OutboxScriptBuilder.BuildCreateScript(BuildSqlDialect.MsSqlServer));
        Execute(createUserDataTableText);

        var endpointConfiguration = EndpointConfigBuilder.BuildEndpoint(endpointName);

        //Hack: enable outbox to force sql session since we have no saga
        endpointConfiguration.EnableOutbox();
        var typesToScan = TypeScanner.NestedTypes <UserDataConsistencyTests>();

        endpointConfiguration.SetTypesToScan(typesToScan);
        endpointConfiguration.DisableFeature <TimeoutManager>();
        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();

        testCase(endpointConfiguration);
        transport.UseCustomSqlConnectionFactory(async() =>
        {
            var connection = MsSqlConnectionBuilder.Build();
            await connection.OpenAsync().ConfigureAwait(false);
            return(connection);
        });
        var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

        persistence.SqlDialect <SqlDialect.MsSqlServer>();
        persistence.ConnectionBuilder(MsSqlConnectionBuilder.Build);
        persistence.DisableInstaller();
        persistence.SubscriptionSettings().DisableCache();
        endpointConfiguration.DefineCriticalErrorAction(c =>
        {
            message = c.Error;
            manualResetEvent.Set();
            return(Task.FromResult(0));
        });
        endpointConfiguration.LimitMessageProcessingConcurrencyTo(1);
        endpointConfiguration.Pipeline.Register(new FailureTrigger(), "Failure trigger");

        var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

        var dataId = Guid.NewGuid();

        var failingMessage = new FailingMessage
        {
            EntityId = dataId
        };
        await endpoint.SendLocal(failingMessage).ConfigureAwait(false);

        var checkMessage = new CheckMessage
        {
            EntityId = dataId
        };
        await endpoint.SendLocal(checkMessage).ConfigureAwait(false);

        manualResetEvent.WaitOne();
        await endpoint.Stop().ConfigureAwait(false);

        Assert.AreEqual("Success", message);
    }
コード例 #26
0
    async Task RunTest(Action <EndpointConfiguration> testCase)
    {
        ManualResetEvent.Reset();
        string message        = null;
        var    sagaDefinition = new SagaDefinition(
            tableSuffix: nameof(Saga1),
            name: nameof(Saga1),
            correlationProperty: new CorrelationProperty
            (
                name: nameof(Saga1.SagaData.CorrelationId),
                type: CorrelationPropertyType.Guid
            )
            );

        Execute(SagaScriptBuilder.BuildDropScript(sagaDefinition, BuildSqlDialect.MsSqlServer));
        Execute(OutboxScriptBuilder.BuildDropScript(BuildSqlDialect.MsSqlServer));
        Execute(SagaScriptBuilder.BuildCreateScript(sagaDefinition, BuildSqlDialect.MsSqlServer));
        Execute(OutboxScriptBuilder.BuildCreateScript(BuildSqlDialect.MsSqlServer));
        var endpointConfiguration = EndpointConfigBuilder.BuildEndpoint(endpointName);
        var typesToScan           = TypeScanner.NestedTypes <SagaConsistencyTests>();

        endpointConfiguration.SetTypesToScan(typesToScan);
        endpointConfiguration.DisableFeature <NServiceBus.Features.TimeoutManager>();
        var transport = endpointConfiguration.UseTransport <SqlServerTransport>();

        testCase(endpointConfiguration);
        transport.UseCustomSqlConnectionFactory(async() =>
        {
            var connection = MsSqlConnectionBuilder.Build();
            await connection.OpenAsync().ConfigureAwait(false);
            return(connection);
        });
        var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

        persistence.SqlDialect <SqlDialect.MsSqlServer>();
        persistence.ConnectionBuilder(MsSqlConnectionBuilder.Build);
        persistence.SubscriptionSettings().DisableCache();
        persistence.DisableInstaller();
        endpointConfiguration.DefineCriticalErrorAction(c =>
        {
            message = c.Error;
            ManualResetEvent.Set();
            return(Task.FromResult(0));
        });
        endpointConfiguration.LimitMessageProcessingConcurrencyTo(1);
        endpointConfiguration.Pipeline.Register(new FailureTrigger(), "Failure trigger");

        var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

        var sagaId = Guid.NewGuid();
        await endpoint.SendLocal(new StartSagaMessage
        {
            SagaId = sagaId
        }).ConfigureAwait(false);

        await endpoint.SendLocal(new FailingMessage
        {
            SagaId = sagaId
        }).ConfigureAwait(false);

        await endpoint.SendLocal(new CheckMessage
        {
            SagaId = sagaId
        }).ConfigureAwait(false);

        ManualResetEvent.WaitOne();
        await endpoint.Stop().ConfigureAwait(false);

        Assert.AreEqual("Success", message);
    }