Ejemplo n.º 1
0
        public async Task Should_stop_pumping_messages_after_first_unsuccessful_receive()
        {
            var successfulReceives = 46;
            var queueSize          = 1000;

            var parser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            var inputQueue = new FakeTableBasedQueue(parser.Parse("input").QualifiedTableName, queueSize, successfulReceives);

            var pump = new MessagePump(
                m => new ProcessWithNoTransaction(sqlConnectionFactory),
                qa => qa == "input" ? (TableBasedQueue)inputQueue : new TableBasedQueue(parser.Parse(qa).QualifiedTableName, qa),
                new QueuePurger(sqlConnectionFactory),
                new ExpiredMessagesPurger(_ => sqlConnectionFactory.OpenNewConnection(), TimeSpan.MaxValue, 0),
                new QueuePeeker(sqlConnectionFactory, new QueuePeekerOptions()),
                new SchemaInspector(_ => sqlConnectionFactory.OpenNewConnection()),
                TimeSpan.MaxValue);

            await pump.Init(
                _ => Task.FromResult(0),
                _ => Task.FromResult(ErrorHandleResult.Handled),
                new CriticalError(_ => Task.FromResult(0)),
                new PushSettings("input", "error", false, TransportTransactionMode.None));

            pump.Start(new PushRuntimeSettings(1));

            await WaitUntil(() => inputQueue.NumberOfPeeks > 1);

            await pump.Stop();

            Assert.That(inputQueue.NumberOfReceives, Is.AtMost(successfulReceives + 2), "Pump should stop receives after first unsuccessful attempt.");
        }
Ejemplo n.º 2
0
        public async Task SetUp()
        {
            var addressParser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            await ResetQueue(addressParser);

            queue = new TableBasedQueue(addressParser.Parse(QueueTableName).QualifiedTableName, QueueTableName);
        }
        Task PurgeOutputQueue(QueueAddressTranslator addressParser, CancellationToken cancellationToken = default)
        {
            purger = new QueuePurger(sqlConnectionFactory);
            var queueAddress = addressParser.Parse(ValidAddress);

            queue = new TableBasedQueue(queueAddress.QualifiedTableName, queueAddress.Address, true);

            return(purger.Purge(queue, cancellationToken));
        }
Ejemplo n.º 4
0
        Task PurgeOutputQueue(QueueAddressTranslator addressParser)
        {
            purger = new QueuePurger(sqlConnectionFactory);
            var queueAddress = addressParser.Parse(validAddress);

            queue = new TableBasedQueue(queueAddress.QualifiedTableName, queueAddress.Address, true);

            return(purger.Purge(queue));
        }
        public void Should_not_change_canonical_address()
        {
            var parser = new QueueAddressTranslator(null, "dbo", null, new QueueSchemaAndCatalogOptions());

            var address          = "my.tb[e@[my.[sch@ma]@[my.c@ta]]og]";
            var canonicalAddress = parser.Parse(address).Address;

            Assert.AreEqual(address, canonicalAddress);
        }
        public async Task SetUp()
        {
            var addressParser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            var connectionString = Environment.GetEnvironmentVariable("SqlServerTransportConnectionString") ?? @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True";

            sqlConnectionFactory = SqlConnectionFactory.Default(connectionString);

            await ResetQueue(addressParser, sqlConnectionFactory);

            queue = new TableBasedQueue(addressParser.Parse(QueueTableName).QualifiedTableName, QueueTableName, false);
        }
Ejemplo n.º 7
0
        public async Task Should_stop_receiving_messages_after_first_unsuccessful_receive()
        {
            var successfulReceives = 46;
            var queueSize          = 1000;

            var parser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            var inputQueueAddress = parser.Parse("input").Address;
            var inputQueue        = new FakeTableBasedQueue(inputQueueAddress, queueSize, successfulReceives);

            var connectionString = Environment.GetEnvironmentVariable("SqlServerTransportConnectionString");

            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True";
            }

            var transport = new SqlServerTransport(SqlConnectionFactory.Default(connectionString).OpenNewConnection)
            {
                TransportTransactionMode = TransportTransactionMode.None,
                TimeToWaitBeforeTriggeringCircuitBreaker = TimeSpan.MaxValue,
            };

            transport.Testing.QueueFactoryOverride = qa =>
                                                     qa == inputQueueAddress ? inputQueue : new TableBasedQueue(parser.Parse(qa).QualifiedTableName, qa, true);

            var receiveSettings = new ReceiveSettings("receiver", inputQueueAddress, true, false, "error");
            var hostSettings    = new HostSettings("IntegrationTests", string.Empty, new StartupDiagnosticEntries(),
                                                   (_, __, ___) => { },
                                                   true);

            var infrastructure = await transport.Initialize(hostSettings, new[] { receiveSettings }, new string[0]);

            var receiver = infrastructure.Receivers.First().Value;

            await receiver.Initialize(
                new PushRuntimeSettings(1),
                (_, __) => Task.CompletedTask,
                (_, __) => Task.FromResult(ErrorHandleResult.Handled));

            await receiver.StartReceive();

            await WaitUntil(() => inputQueue.NumberOfPeeks > 1);

            await receiver.StopReceive();

            await infrastructure.Shutdown();

            Assert.That(inputQueue.NumberOfReceives, Is.AtMost(successfulReceives + 2), "Receiver should stop receives after first unsuccessful attempt.");
        }
        public async Task Should_stop_pumping_messages_after_first_unsuccessful_receive()
        {
            var successfulReceives = 46;
            var queueSize          = 1000;

            var parser = new QueueAddressTranslator("nservicebus", "dbo", null, null);

            var inputQueue = new FakeTableBasedQueue(parser.Parse("input").QualifiedTableName, queueSize, successfulReceives);

            var connectionString = Environment.GetEnvironmentVariable("SqlServerTransportConnectionString");

            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True";
            }

            var sqlConnectionFactory = SqlConnectionFactory.Default(connectionString);

            var pump = new MessagePump(
                m => new ProcessWithNoTransaction(sqlConnectionFactory, null),
                qa => qa == "input" ? (TableBasedQueue)inputQueue : new TableBasedQueue(parser.Parse(qa).QualifiedTableName, qa, true),
                new QueuePurger(sqlConnectionFactory),
                new NoOpExpiredMessagesPurger(),
                new QueuePeeker(sqlConnectionFactory, new QueuePeekerOptions()),
                new QueuePeekerOptions(),
                new SchemaInspector(_ => sqlConnectionFactory.OpenNewConnection(), false),
                TimeSpan.MaxValue);

            await pump.Init(
                _ => Task.FromResult(0),
                _ => Task.FromResult(ErrorHandleResult.Handled),
                new CriticalError(_ => Task.FromResult(0)),
                new PushSettings("input", "error", false, TransportTransactionMode.None));

            pump.Start(new PushRuntimeSettings(1));

            await WaitUntil(() => inputQueue.NumberOfPeeks > 1);

            await pump.Stop();

            Assert.That(inputQueue.NumberOfReceives, Is.AtMost(successfulReceives + 2), "Pump should stop receives after first unsuccessful attempt.");
        }