Exemplo n.º 1
0
        public async Task Can_migrate_timeouts()
        {
            var sourceEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(NHibernateSource));
            var targetEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(SqlTTarget));

            using (var testSession = CreateSessionFactory().OpenSession())
            { // Explicit using scope to ensure dispose before SUT connects
                using (var testTx = testSession.BeginTransaction())
                {
                    await testSession.SaveAsync(new TimeoutEntity
                    {
                        Endpoint    = sourceEndpoint,
                        Destination = targetEndpoint,
                        SagaId      = Guid.NewGuid(),
                        Headers     = "{\"NServiceBus.EnclosedMessageTypes\": \"TimeoutMigrationTool.NHibernate.AcceptanceTests.NHibernateToSqlTEndToEnd+DelayedMessage\"}",
                        State       = Encoding.UTF8.GetBytes("{}"),
                        Time        = DateTime.UtcNow.AddSeconds(15)
                    });

                    await testTx.CommitAsync();
                }
            }

            var context = await Scenario.Define <TargetContext>()
                          .WithEndpoint <SqlTTarget>(b => b.CustomConfig(ec =>
            {
                ec.OverrideLocalAddress(sourceEndpoint);
                var transportConfig = ec.UseTransport <SqlServerTransport>();

                transportConfig.ConnectionString(connectionString);

                ec.UseSerialization <NewtonsoftSerializer>();
            })
                                                     .When(async(_, c) =>
            {
                var logger         = new TestLoggingAdapter(c);
                var timeoutsSource = new NHibernateTimeoutsSource(connectionString, 1024, DatabaseDialect);
                var timeoutTarget  = new SqlTTimeoutsTarget(logger, connectionString, "dbo");

                var migrationRunner = new MigrationRunner(logger, timeoutsSource, timeoutTarget);

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

            Assert.True(context.GotTheDelayedMessage);
        }
        public async Task Can_migrate_timeouts()
        {
            var sourceEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(NHibernateSource));
            var targetEndpoint = NServiceBus.AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(AsqTarget));

            using (var testSession = CreateSessionFactory().OpenSession())
            { // Explicit using scope to ensure dispose before SUT connects
                using (var testTx = testSession.BeginTransaction())
                {
                    await testSession.SaveAsync(new TimeoutEntity
                    {
                        Endpoint    = sourceEndpoint,
                        Destination = targetEndpoint,
                        SagaId      = Guid.NewGuid(),
                        Headers     = "{\"NServiceBus.EnclosedMessageTypes\": \"TimeoutMigrationTool.NHibernate.AcceptanceTests.NHibernateToAsqEndToEnd+DelayedMessage\"}",
                        State       = Encoding.UTF8.GetBytes("{}"),
                        Time        = DateTime.UtcNow.AddSeconds(15)
                    });

                    await testTx.CommitAsync();
                }
            }

            var context = await Scenario.Define <TargetContext>()
                          // Create the legacy 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 <NHibernateSource>(b => b.CustomConfig(ec =>
            {
                var transportConfig = ec.UseTransport <AzureStorageQueueTransport>();
                transportConfig.ConnectionString(asqConnectionString);
                transportConfig.DisablePublishing();

                transportConfig.DelayedDelivery().DisableTimeoutManager();

                ec.UseSerialization <NewtonsoftSerializer>();
            }))
                          .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 timeoutsSource  = new NHibernateTimeoutsSource(connectionString, 512, DatabaseDialect);
                var timeoutsTarget  = new ASQTarget(asqConnectionString, new DelayedDeliveryTableNameProvider());
                var migrationRunner = new MigrationRunner(logger, timeoutsSource, timeoutsTarget);

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

            Assert.True(context.GotTheDelayedMessage);
        }