コード例 #1
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, bool inMemoryDb)
        {
            using (var connectionInfo = new IntegrationConnectionInfo(inMemoryDb))
            {
                var queueName = GenerateQueueName.Create();
                var logProvider = LoggerShared.Create(queueName, GetType().Name);
                using (
                    var queueCreator =
                        new QueueCreationContainer<SqLiteMessageQueueInit>(
                            serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
                {
                    try
                    {

                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation<SqLiteMessageQueueCreation>(queueName,
                                    connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.Options.EnableDelayedProcessing = true;
                            oCreation.Options.EnableHeartBeat = true;
                            oCreation.Options.EnableStatus = true;
                            oCreation.Options.EnableStatusTable = true;

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

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

                            //process data
                            var consumer = new ConsumerAsyncErrorShared<FakeMessage>();
                            consumer.RunConsumer<SqLiteMessageQueueInit>(queueName,connectionInfo.ConnectionString,
                                false,
                                logProvider,
                                messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35));
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, messageCount);
                            new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options).Verify(messageCount, true, false);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation<SqLiteMessageQueueCreation>(queueName,
                                    connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, bool useTransactions)
        {
            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);

                        //process data
                        var consumer = new ConsumerAsyncErrorShared <FakeMessage>();
                        consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          messageCount, workerCount, timeOut, queueSize, readerCount,
                                                                          TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", null);
                        ValidateErrorCounts(queueName, messageCount);
                        new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(messageCount, true, false);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
コード例 #3
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize)
        {
            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 ConsumerAsyncErrorShared <FakeMessage>();
                            consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", null, false);
                            ValidateErrorCounts(oCreation.Scope, messageCount);
                            new VerifyQueueRecordCount().Verify(oCreation.Scope, messageCount, false);

                            consumer.PurgeErrorMessages <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                                 false, logProvider, true);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <MessageQueueCreation>(queueName,
                                                                                     connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
コード例 #4
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, 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);
                    }
                    else
                    {
                        var producer = new ProducerShared();
                        producer.RunTest <RedisQueueInit, FakeMessage>(queueName,
                                                                       connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                       Helpers.Verify, false, null);
                    }

                    //process data
                    var defaultRoute = route ? Helpers.DefaultRoute : null;
                    var consumer     = new ConsumerAsyncErrorShared <FakeMessage>();
                    consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                          logProvider,
                                                          messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", defaultRoute);
                    ValidateErrorCounts(queueName, messageCount, connectionString);
                    using (
                        var count = new VerifyQueueRecordCount(queueName, connectionString))
                    {
                        count.Verify(messageCount, false, 2);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
コード例 #5
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, ConnectionInfoTypes type)
        {
            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
                    var producer = new ProducerShared();
                    producer.RunTest<RedisQueueInit, FakeMessage>(queueName,
                        connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                        Helpers.Verify, false);

                    //process data
                    var consumer = new ConsumerAsyncErrorShared<FakeMessage>();
                    consumer.RunConsumer<RedisQueueInit>(queueName, connectionString, false,
                        logProvider,
                        messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12));
                    ValidateErrorCounts(queueName, messageCount, connectionString);
                    using (
                        var count = new VerifyQueueRecordCount(queueName, connectionString))
                    {
                        count.Verify(messageCount, false, 2);
                    }

                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation<RedisQueueCreation>(queueName,
                                connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
コード例 #6
0
        public void Run <TTransportInit, TMessage, TTransportCreate>(
            QueueConnection queueConnection,
            int messageCount, int timeOut, int workerCount,
            int readerCount, int queueSize, 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, scope, false);

                    //process data
                    var consumer = new ConsumerAsyncErrorShared <TMessage>();
                    consumer.RunConsumer <TTransportInit>(queueConnection,
                                                          false,
                                                          logProvider,
                                                          messageCount, workerCount, timeOut, queueSize, readerCount, 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);
                    validateErrorCounts(queueConnection, messageCount, scope);

                    //purge error messages and verify that count is 0
                    consumer.PurgeErrorMessages <TTransportInit>(queueConnection,
                                                                 false, logProvider, true, scope);
                    validateErrorCounts(queueConnection, 0, scope);
                }
                finally
                {
                    oCreation?.RemoveQueue();
                    oCreation?.Dispose();
                    scope?.Dispose();
                }
            }
        }
コード例 #7
0
        public void Run(int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, bool inMemoryDb, bool enableChaos)
        {
            using (var connectionInfo = new IntegrationConnectionInfo(inMemoryDb))
            {
                var queueName   = GenerateQueueName.Create();
                var logProvider = LoggerShared.Create(queueName, GetType().Name);
                using (
                    var queueCreator =
                        new QueueCreationContainer <SqLiteMessageQueueInit>(
                            serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
                {
                    try
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.Options.EnableDelayedProcessing = true;
                            oCreation.Options.EnableHeartBeat         = true;
                            oCreation.Options.EnableStatus            = true;
                            oCreation.Options.EnableStatusTable       = true;

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

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

                            //process data
                            var consumer = new ConsumerAsyncErrorShared <FakeMessage>();
                            consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", null, enableChaos);
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, messageCount);
                            new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options).Verify(messageCount, true, false);

                            //don't purge
                            consumer.PurgeErrorMessages <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                                 false, logProvider, false);
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, messageCount);

                            //purge error messages and verify that count is 0
                            consumer.PurgeErrorMessages <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                                 false, logProvider, true);
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, 0);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }