Esempio n. 1
0
        public void Run(int messageCount, int timeOut, int workerCount)
        {
            using (var connectionInfo = new IntegrationConnectionInfo())
            {
                var queueName   = GenerateQueueName.Create();
                var logProvider = LoggerShared.Create(queueName, GetType().Name);
                using (var queueCreator =
                           new QueueCreationContainer <MemoryMessageQueueInit>(
                               serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
                {
                    try
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <MessageQueueCreation>(queueName,
                                                                                     connectionInfo.ConnectionString)
                            )
                        {
                            var result = oCreation.CreateQueue();
                            Assert.True(result.Success, result.ErrorMessage);

                            //create data
                            var producer = new ProducerShared();
                            producer.RunTest <MemoryMessageQueueInit, FakeMessage>(queueName,
                                                                                   connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                   Helpers.Verify, false, oCreation.Scope, false);

                            //process data
                            var consumer = new ConsumerErrorShared <FakeMessage>();
                            consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          workerCount, timeOut, messageCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", null, false);
                            ValidateErrorCounts(oCreation.Scope, messageCount);
                            new VerifyQueueRecordCount().Verify(oCreation.Scope, messageCount, false);

                            //purge error records
                            consumer.PurgeErrorMessages <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                                 false, logProvider, true);

                            //memory queue doesn't actually keep errors, so nothing to check for...
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <MessageQueueCreation>(queueName,
                                                                                     connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run(int messageCount, int timeOut, int workerCount, bool useTransactions, bool enableChaos)
        {
            var queueName   = GenerateQueueName.Create();
            var logProvider = LoggerShared.Create(queueName, GetType().Name);

            using (var queueCreator =
                       new QueueCreationContainer <PostgreSqlMessageQueueInit>(
                           serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                try
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.Options.EnableDelayedProcessing = true;
                        oCreation.Options.EnableHeartBeat         = !useTransactions;
                        oCreation.Options.EnableHoldTransactionUntilMessageCommitted = useTransactions;
                        oCreation.Options.EnableStatus      = !useTransactions;
                        oCreation.Options.EnableStatusTable = true;

                        var result = oCreation.CreateQueue();
                        Assert.True(result.Success, result.ErrorMessage);

                        //create data
                        var producer = new ProducerShared();
                        producer.RunTest <PostgreSqlMessageQueueInit, FakeMessage>(queueName,
                                                                                   ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                   Helpers.Verify, false, oCreation.Scope, false);

                        //process data
                        var consumer = new ConsumerErrorShared <FakeMessage>();
                        consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          workerCount, timeOut, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", null, enableChaos);
                        ValidateErrorCounts(queueName, messageCount);
                        new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(messageCount, true, false);

                        //run, but don't purge
                        consumer.PurgeErrorMessages <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                                 false, logProvider, false);
                        ValidateErrorCounts(queueName, messageCount);

                        //purge error records
                        consumer.PurgeErrorMessages <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                                 false, logProvider, true);

                        //table should be empty now
                        ValidateErrorCounts(queueName, 0);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        public void Run(int messageCount, int timeOut, int workerCount, ConnectionInfoTypes type, bool route)
        {
            var queueName        = GenerateQueueName.Create();
            var logProvider      = LoggerShared.Create(queueName, GetType().Name);
            var connectionString = new ConnectionInfo(type).ConnectionString;

            using (
                var queueCreator =
                    new QueueCreationContainer <RedisQueueInit>(
                        serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                try
                {
                    //create data
                    if (route)
                    {
                        var producer = new ProducerShared();
                        producer.RunTest <RedisQueueInit, FakeMessage>(queueName,
                                                                       connectionString, false, messageCount, logProvider, Helpers.GenerateRouteData,
                                                                       Helpers.Verify, false, null, false);
                    }
                    else
                    {
                        var producer = new ProducerShared();
                        producer.RunTest <RedisQueueInit, FakeMessage>(queueName,
                                                                       connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                       Helpers.Verify, false, null, false);
                    }

                    //process data
                    var defaultRoute = route ? Helpers.DefaultRoute : null;
                    var consumer     = new ConsumerErrorShared <FakeMessage>();
                    consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                          logProvider,
                                                          workerCount, timeOut, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", defaultRoute, false);
                    ValidateErrorCounts(queueName, connectionString, messageCount);
                    using (
                        var count = new VerifyQueueRecordCount(queueName, connectionString))
                    {
                        count.Verify(messageCount, true, 2);
                    }

                    consumer.PurgeErrorMessages <RedisQueueInit>(queueName, connectionString,
                                                                 false, logProvider, false);

                    //table should be empty now
                    ValidateErrorCounts(queueName, connectionString, messageCount);

                    //purge error records
                    consumer.PurgeErrorMessages <RedisQueueInit>(queueName, connectionString,
                                                                 false, logProvider, true);

                    //table should be empty now
                    ValidateErrorCounts(queueName, connectionString, 0);
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
Esempio n. 4
0
        public void Run <TTransportInit, TMessage, TTransportCreate>(
            QueueConnection queueConnection,
            int messageCount, int timeOut, int workerCount, bool enableChaos,
            Action <TTransportCreate> setOptions,
            Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
            Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount,
            Action <QueueConnection, int, ICreationScope> validateErrorCounts)
            where TTransportInit : ITransportInit, new()
            where TMessage : class
            where TTransportCreate : class, IQueueCreation
        {
            var logProvider = LoggerShared.Create(queueConnection.Queue, GetType().Name);

            using (var queueCreator =
                       new QueueCreationContainer <TTransportInit>(
                           serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                ICreationScope scope     = null;
                var            oCreation = queueCreator.GetQueueCreation <TTransportCreate>(queueConnection);
                try
                {
                    setOptions(oCreation);
                    var result = oCreation.CreateQueue();
                    Assert.True(result.Success, result.ErrorMessage);
                    scope = oCreation.Scope;

                    //create data
                    var producer = new ProducerShared();
                    producer.RunTest <TTransportInit, TMessage>(queueConnection, false, messageCount,
                                                                logProvider, generateData,
                                                                verify, false, oCreation.Scope, false);

                    //process data
                    var consumer = new ConsumerErrorShared <TMessage>();
                    consumer.RunConsumer <TTransportInit>(queueConnection,
                                                          false,
                                                          logProvider,
                                                          workerCount, timeOut, messageCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35),
                                                          "second(*%10)", null, enableChaos, scope);

                    validateErrorCounts(queueConnection, messageCount, scope);
                    verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope,
                                     messageCount, true, false);

                    consumer.PurgeErrorMessages <TTransportInit>(queueConnection,
                                                                 false, logProvider, false, scope);

                    //table should not be empty yet
                    validateErrorCounts(queueConnection, messageCount, scope);

                    //purge error records
                    consumer.PurgeErrorMessages <TTransportInit>(queueConnection,
                                                                 false, logProvider, true, scope);

                    //table should be empty now
                    validateErrorCounts(queueConnection, 0, scope);
                }
                finally
                {
                    oCreation?.RemoveQueue();
                    oCreation?.Dispose();
                    scope?.Dispose();
                }
            }
        }