public async Task Can_migrate_timeouts()
        {
            var sourceEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(SqlPSource));
            var targetEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(RabbitMqTarget));

            await Scenario.Define <SourceContext>()
            .WithEndpoint <SqlPSource>(b => b.CustomConfig(ec =>
            {
                var persistence = ec.UsePersistence <SqlPersistence>();

                persistence.SqlDialect <NServiceBus.SqlDialect.MsSqlServer>();
                persistence.ConnectionBuilder(
                    connectionBuilder: () =>
                {
                    return(new SqlConnection(connectionString));
                });
            })
                                       .When(async(session, c) =>
            {
                var delayedMessage = new DelayedMessage();

                var options = new SendOptions();

                options.DelayDeliveryWith(TimeSpan.FromSeconds(15));
                options.SetDestination(targetEndpoint);

                await session.Send(delayedMessage, options);

                await WaitUntilTheTimeoutIsSavedInSql(sourceEndpoint);

                c.TimeoutSet = true;
            }))
            .Done(c => c.TimeoutSet)
            .Run(TimeSpan.FromSeconds(30));

            var context = await Scenario.Define <TargetContext>()
                          .WithEndpoint <RabbitMqTarget>(b => b.CustomConfig(ec =>
            {
                ec.UseTransport <RabbitMQTransport>()
                .ConnectionString(rabbitUrl);
            })
                                                         .When(async(_, c) =>
            {
                var logger           = new TestLoggingAdapter(c);
                var timeoutStorage   = new SqlTimeoutsSource(connectionString, new MsSqlServer(), 1024);
                var transportAdapter = new RabbitMqTimeoutTarget(logger, rabbitUrl);
                var migrationRunner  = new MigrationRunner(logger, timeoutStorage, transportAdapter);

                await migrationRunner.Run(DateTime.Now.AddDays(-10), EndpointFilter.SpecificEndpoint(sourceEndpoint), new Dictionary <string, string>());
            }))
                          .Done(c => c.GotTheDelayedMessage)
                          .Run(TimeSpan.FromSeconds(30));

            Assert.True(context.GotTheDelayedMessage);
        }
Beispiel #2
0
        public async Task Can_migrate_timeouts()
        {
            var salesEndpoint     = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(SqlPSource));
            var reportingEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(AsqTarget));

            // Make sure delayed delivery queue is created so that the migration can run.
            await Scenario.Define <SourceContext>()
            .WithEndpoint <SqlPSource>(b => b.CustomConfig(ec =>
            {
                var transportConfig = ec.UseTransport <AzureStorageQueueTransport>();
                transportConfig.ConnectionString(asqConnectionString);
                transportConfig.DisablePublishing();

                transportConfig.DelayedDelivery().DisableTimeoutManager();

                ec.UseSerialization <NewtonsoftSerializer>();
            })).Run(TimeSpan.FromSeconds(10));

            // Sending a delayed delivery message using TimeoutManager
            await Scenario.Define <SourceContext>()
            .WithEndpoint <SqlPSource>(b => b.CustomConfig(ec =>
            {
                var persistence = ec.UsePersistence <SqlPersistence>();
                persistence.SubscriptionSettings().DisableCache();

                persistence.SqlDialect <NServiceBus.SqlDialect.MsSqlServer>();
                persistence.ConnectionBuilder(
                    connectionBuilder: () => new SqlConnection(connectionString));

                ec.UseSerialization <NewtonsoftSerializer>();
            })
                                       .When(async(session, c) =>
            {
                var delayedMessage = new DelayedMessage();

                var options = new SendOptions();

                options.DelayDeliveryWith(TimeSpan.FromSeconds(15));
                options.SetDestination(reportingEndpoint);

                await session.Send(delayedMessage, options);

                await WaitUntilTheTimeoutIsSavedInSql(salesEndpoint);

                c.TimeoutSet = true;
            }))
            .Done(c => c.TimeoutSet)
            .Run(TimeSpan.FromSeconds(30));

            var context = await Scenario.Define <TargetContext>()
                          // Create the sales endpoint to forward the delayed message to the reporting endpoint
                          // This is needed as ASQ stores the delayed messages at the sending endpoint until
                          // delivery is needed
                          .WithEndpoint <SqlPSource>(b => b.CustomConfig(ec =>
            {
                var transportConfig = ec.UseTransport <AzureStorageQueueTransport>();
                transportConfig.ConnectionString(asqConnectionString);
                transportConfig.DisablePublishing();

                transportConfig.DelayedDelivery().DisableTimeoutManager();

                ec.UseSerialization <NewtonsoftSerializer>();
            }))
                          // Start the reporting endpoint to receieve and process the delayed message
                          .WithEndpoint <AsqTarget>(b => b.CustomConfig(ec =>
            {
                var transportConfig = ec.UseTransport <AzureStorageQueueTransport>();
                transportConfig.ConnectionString(asqConnectionString);
                transportConfig.DisablePublishing();

                transportConfig.DelayedDelivery().DisableTimeoutManager();

                ec.UseSerialization <NewtonsoftSerializer>();
            })
                                                    .When(async(_, c) =>
            {
                var logger          = new TestLoggingAdapter(c);
                var timeoutStorage  = new SqlTimeoutsSource(connectionString, new MsSqlServer(), 1024);
                var timeoutsTarget  = new ASQTarget(asqConnectionString, new DelayedDeliveryTableNameProvider());
                var migrationRunner = new MigrationRunner(logger, timeoutStorage, timeoutsTarget);

                await migrationRunner.Run(DateTime.Now.AddDays(-10), EndpointFilter.SpecificEndpoint(salesEndpoint), new Dictionary <string, string>());
            }))
                          .Done(c => c.GotTheDelayedMessage)
                          .Run(TimeSpan.FromSeconds(30));

            Assert.True(context.GotTheDelayedMessage);
        }