public void Run(
     int producerCount,
     bool inMemoryDb)
 {
     using (var connectionInfo = new IntegrationConnectionInfo(inMemoryDb))
     {
         var queueName = GenerateQueueName.Create();
         using (var queueContainer = new QueueContainer <SqLiteMessageQueueInit>(x => {
         }))
         {
             try
             {
                 var tests = new JobSchedulerTestsShared();
                 tests.RunTestMultipleProducers <SqLiteMessageQueueInit, SqliteJobQueueCreation>(queueName,
                                                                                                 connectionInfo.ConnectionString, true, producerCount, queueContainer.CreateTimeSync(connectionInfo.ConnectionString), LoggerShared.Create(queueName, GetType().Name));
             }
             finally
             {
                 using (var queueCreator =
                            new QueueCreationContainer <SqLiteMessageQueueInit>())
                 {
                     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 inMemoryDb, LinqMethodTypes linqMethodTypes, 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 ProducerMethodShared();
                            var id       = Guid.NewGuid();
                            if (linqMethodTypes == LinqMethodTypes.Compiled)
                            {
                                producer.RunTestCompiled <SqLiteMessageQueueInit>(queueName,
                                                                                  connectionInfo.ConnectionString, false, messageCount, logProvider,
                                                                                  Helpers.GenerateData,
                                                                                  Helpers.Verify, false, id, GenerateMethod.CreateErrorCompiled, 0, oCreation.Scope, false);
                            }
                            else
                            {
                                producer.RunTestDynamic <SqLiteMessageQueueInit>(queueName,
                                                                                 connectionInfo.ConnectionString, false, messageCount, logProvider,
                                                                                 Helpers.GenerateData,
                                                                                 Helpers.Verify, false, id, GenerateMethod.CreateErrorDynamic, 0, oCreation.Scope, false);
                            }

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

                            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();
                        }
                    }
                }
            }
        }
示例#3
0
        public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize,
                        bool useTransactions, int messageType, LinqMethodTypes linqMethodTypes)
        {
            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, queueSize);
            }

            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);
                        var id = Guid.NewGuid();
                        if (messageType == 1)
                        {
                            var producer = new ProducerMethodAsyncShared();
                            producer.RunTestAsync <PostgreSqlMessageQueueInit>(queueName,
                                                                               ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope).Wait(timeOut);

                            var consumer = new ConsumerMethodAsyncShared {
                                Factory = Factory
                            };
                            consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)");
                        }
                        else if (messageType == 2)
                        {
                            var producer = new ProducerMethodAsyncShared();
                            producer.RunTestAsync <PostgreSqlMessageQueueInit>(queueName,
                                                                               ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope).Wait(timeOut);

                            var consumer = new ConsumerMethodAsyncShared {
                                Factory = Factory
                            };
                            consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)");
                        }
                        else if (messageType == 3)
                        {
                            var producer = new ProducerMethodAsyncShared();
                            producer.RunTestAsync <PostgreSqlMessageQueueInit>(queueName,
                                                                               ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope).Wait(timeOut);

                            var consumer = new ConsumerMethodAsyncShared {
                                Factory = Factory
                            };
                            consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)");
                        }

                        new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(0, false, false);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
示例#4
0
        public void Run(int messageCount, int timeOut, int workerCount, bool useTransactions, LinqMethodTypes linqMethodTypes)
        {
            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);
                        var id = Guid.NewGuid();
                        //create data
                        var producer = new ProducerMethodShared();
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <PostgreSqlMessageQueueInit>(queueName,
                                                                                  ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                  Helpers.Verify, false, id, GenerateMethod.CreateNoOpCompiled, 0, oCreation.Scope);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <PostgreSqlMessageQueueInit>(queueName,
                                                                                 ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                 Helpers.Verify, false, id, GenerateMethod.CreateNoOpDynamic, 0, oCreation.Scope);
                        }
#endif
                        //process data
                        var consumer = new ConsumerMethodPoisonMessageShared();

                        consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                          false,
                                                                          workerCount,
                                                                          logProvider, timeOut, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)");

                        ValidateErrorCounts(queueName, messageCount);
                        new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(messageCount, true, true);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        public void Run(int messageCount, int runtime, int timeOut, int workerCount, LinqMethodTypes linqMethodTypes, bool enableChaos)
        {
            var queueName = GenerateQueueName.Create();
            var logProvider = LoggerShared.Create(queueName, GetType().Name);
            using (
                var queueCreator =
                    new QueueCreationContainer<SqlServerMessageQueueInit>(
                        serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                try
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation<SqlServerMessageQueueCreation>(queueName,
                                ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.Options.EnableDelayedProcessing = true;
                        oCreation.Options.EnableHeartBeat = true;
                        oCreation.Options.EnableHoldTransactionUntilMessageCommitted = false;
                        oCreation.Options.EnableStatus = true;
                        oCreation.Options.EnableStatusTable = true;

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

                        var id = Guid.NewGuid();
                        var producer = new ProducerMethodShared();

                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled<SqlServerMessageQueueInit>(queueName,
                          ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                          Helpers.Verify, false, id, GenerateMethod.CreateCancelCompiled, runtime, oCreation.Scope, false);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic<SqlServerMessageQueueInit>(queueName,
                          ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                          Helpers.Verify, false, id, GenerateMethod.CreateCancelDynamic, runtime, oCreation.Scope, false);
                        }
#endif
                        var consumer = new ConsumerMethodCancelWorkShared<SqlServerMessageQueueInit>();
                        consumer.RunConsumer(queueName, ConnectionInfo.ConnectionString, false, logProvider,
                            runtime, messageCount,
                            workerCount, timeOut, serviceRegister => serviceRegister.Register<IMessageMethodHandling>(() => new MethodMessageProcessingCancel(id), LifeStyles.Singleton), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", id, enableChaos);

                        new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(0, false, false);
                        GenerateMethod.ClearCancel(id);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation<SqlServerMessageQueueCreation>(queueName,
                                ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        public void Run(int messageCount, int runtime, int timeOut,
                        int workerCount, bool async, bool inMemoryDb, LinqMethodTypes linqMethodTypes)
        {
            var queueNameSend      = GenerateQueueName.Create();
            var queueNameReceive   = GenerateQueueName.Create();
            var logProviderSend    = LoggerShared.Create(queueNameSend, GetType().Name);
            var logProviderReceive = LoggerShared.Create(queueNameReceive, GetType().Name);

            using (var connectionInfo = new IntegrationConnectionInfo(inMemoryDb))
            {
                using (var queueCreatorReceive =
                           new QueueCreationContainer <SqLiteMessageQueueInit>(
                               serviceRegister => serviceRegister.Register(() => logProviderReceive, LifeStyles.Singleton)))
                {
                    using (var queueCreatorSend =
                               new QueueCreationContainer <SqLiteMessageQueueInit>(
                                   serviceRegister => serviceRegister.Register(() => logProviderSend, LifeStyles.Singleton)))
                    {
                        try
                        {
                            using (
                                var oCreationReceive =
                                    queueCreatorReceive.GetQueueCreation <SqLiteMessageQueueCreation>(queueNameReceive,
                                                                                                      connectionInfo.ConnectionString)
                                )
                            {
                                oCreationReceive.Options.EnableDelayedProcessing = true;
                                oCreationReceive.Options.EnableHeartBeat         = true;
                                oCreationReceive.Options.EnableStatus            = true;
                                oCreationReceive.Options.EnableStatusTable       = true;
                                oCreationReceive.Options.QueueType = QueueTypes.RpcReceive;

                                var resultReceive = oCreationReceive.CreateQueue();
                                Assert.True(resultReceive.Success, resultReceive.ErrorMessage);

                                using (
                                    var oCreation =
                                        queueCreatorSend.GetQueueCreation <SqLiteMessageQueueCreation>(queueNameSend,
                                                                                                       connectionInfo.ConnectionString)
                                    )
                                {
                                    oCreation.Options.EnableDelayedProcessing = true;
                                    oCreation.Options.EnableHeartBeat         = true;
                                    oCreation.Options.EnableStatus            = true;
                                    oCreation.Options.EnableStatusTable       = true;
                                    oCreation.Options.QueueType = QueueTypes.RpcSend;

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

                                    var rpc =
                                        new RpcMethodShared
                                        <SqLiteMessageQueueInit, SqLiteRpcConnection>();

                                    var id = Guid.NewGuid();
                                    rpc.Run(queueNameReceive, queueNameSend, connectionInfo.ConnectionString,
                                            connectionInfo.ConnectionString, logProviderReceive, logProviderSend,
                                            runtime, messageCount, workerCount, timeOut, async,
                                            new SqLiteRpcConnection(connectionInfo.ConnectionString, queueNameSend,
                                                                    connectionInfo.ConnectionString, queueNameReceive, new DbDataSource()),
                                            TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, linqMethodTypes, "second(*%10)");

                                    new VerifyQueueRecordCount(queueNameSend, connectionInfo.ConnectionString, oCreation.Options).Verify(0, false, false);
                                    new VerifyQueueRecordCount(queueNameReceive, connectionInfo.ConnectionString, oCreationReceive.Options).Verify(0, false,
                                                                                                                                                   false);
                                }
                            }
                        }
                        finally
                        {
                            using (
                                var oCreation =
                                    queueCreatorSend.GetQueueCreation <SqLiteMessageQueueCreation>(queueNameSend,
                                                                                                   connectionInfo.ConnectionString)
                                )
                            {
                                oCreation.RemoveQueue();
                            }

                            using (
                                var oCreation =
                                    queueCreatorReceive.GetQueueCreation <SqLiteMessageQueueCreation>(queueNameReceive,
                                                                                                      connectionInfo.ConnectionString)
                                )
                            {
                                oCreation.RemoveQueue();
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        public void Run(int messageCount, int timeOut, int workerCount,
                        int readerCount, int queueSize, LinqMethodTypes linqMethodTypes)
        {
            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 ProducerMethodShared();
                            var id       = Guid.NewGuid();
                            if (linqMethodTypes == LinqMethodTypes.Compiled)
                            {
                                producer.RunTestCompiled <MemoryMessageQueueInit>(queueName,
                                                                                  connectionInfo.ConnectionString, false, messageCount, logProvider,
                                                                                  Helpers.GenerateData,
                                                                                  Helpers.Verify, false, id, GenerateMethod.CreateErrorCompiled, 0, oCreation.Scope);
                            }
#if NETFULL
                            else
                            {
                                producer.RunTestDynamic <MemoryMessageQueueInit>(queueName,
                                                                                 connectionInfo.ConnectionString, false, messageCount, logProvider,
                                                                                 Helpers.GenerateData,
                                                                                 Helpers.Verify, false, id, GenerateMethod.CreateErrorDynamic, 0, oCreation.Scope);
                            }
#endif
                            //process data
                            var consumer = new ConsumerMethodAsyncErrorShared();
                            consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, "second(*%10)");
                            ValidateErrorCounts(oCreation.Scope, messageCount);
                            new VerifyQueueRecordCount().Verify(oCreation.Scope, messageCount, false);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <MessageQueueCreation>(queueName,
                                                                                     connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run <TTransportInit, TTransportCreate>(
            QueueConnection queueConnection,
            int messageCount, int timeOut, int workerCount, int readerCount, int queueSize, LinqMethodTypes linqMethodTypes,
            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 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 ProducerMethodShared();
                    var id       = Guid.NewGuid();
                    if (linqMethodTypes == LinqMethodTypes.Compiled)
                    {
                        producer.RunTestCompiled <TTransportInit>(queueConnection, false, messageCount,
                                                                  logProvider,
                                                                  generateData,
                                                                  verify, false, id, GenerateMethod.CreateErrorCompiled, 0, oCreation.Scope,
                                                                  false);
                    }
                    else
                    {
                        producer.RunTestDynamic <TTransportInit>(queueConnection, false, messageCount,
                                                                 logProvider,
                                                                 generateData,
                                                                 verify, false, id, GenerateMethod.CreateErrorDynamic, 0, oCreation.Scope,
                                                                 false);
                    }

                    //process data
                    var consumer = new ConsumerMethodAsyncErrorShared();
                    consumer.RunConsumer <TTransportInit>(queueConnection,
                                                          false,
                                                          logProvider,
                                                          messageCount, workerCount, timeOut, queueSize, readerCount, TimeSpan.FromSeconds(30),
                                                          TimeSpan.FromSeconds(35), id, "second(*%10)", 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();
                }
            }
        }
        public void Run(
            bool interceptors,
            bool dynamic)
        {
            var queueName = GenerateQueueName.Create();

            using (var queueContainer = new QueueContainer <SqlServerMessageQueueInit>(x => {
            }))
            {
                try
                {
                    var tests = new JobSchedulerTestsShared();
                    if (!dynamic)
                    {
                        tests.RunEnqueueTestCompiled <SqlServerMessageQueueInit, SqlServerJobQueueCreation>(queueName,
                                                                                                            ConnectionInfo.ConnectionString, interceptors,
                                                                                                            Helpers.Verify, Helpers.SetError, queueContainer.CreateTimeSync(ConnectionInfo.ConnectionString), null, LoggerShared.Create(queueName, GetType().Name));
                    }
#if NETFULL
                    else
                    {
                        tests.RunEnqueueTestDynamic <SqlServerMessageQueueInit, SqlServerJobQueueCreation>(queueName,
                                                                                                           ConnectionInfo.ConnectionString, interceptors,
                                                                                                           Helpers.Verify, Helpers.SetError, queueContainer.CreateTimeSync(ConnectionInfo.ConnectionString), null, LoggerShared.Create(queueName, GetType().Name));
                    }
#endif
                }
                finally
                {
                    using (var queueCreator =
                               new QueueCreationContainer <SqlServerMessageQueueInit>())
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqlServerMessageQueueCreation>(queueName,
                                                                                              ConnectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run <TTransportInit, TTransportCreate>(
            QueueConnection queueConnection,
            int messageCount, int runtime,
            int timeOut, int workerCount, LinqMethodTypes linqMethodTypes, bool enableChaos,
            Action <TTransportCreate> setOptions,
            Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
            Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount)
            where TTransportInit : ITransportInit, new()
            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;

                    var producer = new ProducerMethodShared();
                    var id       = Guid.NewGuid();
                    if (linqMethodTypes == LinqMethodTypes.Compiled)
                    {
                        producer.RunTestCompiled <TTransportInit>(queueConnection, false, messageCount,
                                                                  logProvider, generateData,
                                                                  verify, false, id, GenerateMethod.CreateCancelCompiled, runtime,
                                                                  oCreation.Scope, false);
                    }
                    else
                    {
                        producer.RunTestDynamic <TTransportInit>(queueConnection, false, messageCount,
                                                                 logProvider, generateData,
                                                                 verify, false, id, GenerateMethod.CreateCancelDynamic, runtime, oCreation.Scope,
                                                                 false);
                    }


                    var consumer = new ConsumerMethodHeartBeatShared();
                    consumer.RunConsumer <TTransportInit>(queueConnection,
                                                          false,
                                                          logProvider,
                                                          runtime, messageCount,
                                                          workerCount, timeOut, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)",
                                                          enableChaos, scope);

                    verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, 0, false, false);
                    GenerateMethod.ClearCancel(id);
                }
                finally
                {
                    oCreation.RemoveQueue();
                    oCreation.Dispose();
                    scope?.Dispose();
                }
            }
        }
        public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize,
                        int messageType, ConnectionInfoTypes type, LinqMethodTypes linqMethodTypes)
        {
            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, queueSize);
            }

            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
                {
                    var id = Guid.NewGuid();
                    if (messageType == 1)
                    {
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <RedisQueueInit>(queueName,
                                                               connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, null, false).Wait(timeOut);

                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)", false);
                    }
                    else if (messageType == 2)
                    {
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <RedisQueueInit>(queueName,
                                                               connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, null, false).Wait(timeOut);

                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)", false);
                    }
                    else if (messageType == 3)
                    {
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <RedisQueueInit>(queueName,
                                                               connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, null, false).Wait(timeOut);


                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)", false);
                    }

                    using (var count = new VerifyQueueRecordCount(queueName, connectionString))
                    {
                        count.Verify(0, false, -1);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
示例#12
0
        public void Run(
            int messageCount,
            bool interceptors,
            bool batchSending,
            bool enableDelay,
            bool enableExpiration,
            ConnectionInfoTypes type,
            LinqMethodTypes linqMethodTypes)
        {
            var queueName        = GenerateQueueName.Create();
            var logProvider      = LoggerShared.Create(queueName, GetType().Name);
            var producer         = new ProducerMethodShared();
            var connectionString = new ConnectionInfo(type).ConnectionString;

            using (
                var queueCreator =
                    new QueueCreationContainer <RedisQueueInit>(
                        serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                try
                {
                    var id = Guid.NewGuid();
                    if (enableExpiration && enableDelay)
                    {
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <RedisQueueInit>(queueName,
                                                                      connectionString, interceptors, messageCount, logProvider,
                                                                      Helpers.GenerateDelayExpiredData,
                                                                      Helpers.Verify, batchSending, id, GenerateMethod.CreateCompiled, 0, null, false);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <RedisQueueInit>(queueName,
                                                                     connectionString, interceptors, messageCount, logProvider,
                                                                     Helpers.GenerateDelayExpiredData,
                                                                     Helpers.Verify, batchSending, id, GenerateMethod.CreateDynamic, 0, null, false);
                        }
#endif
                    }
                    else if (enableDelay)
                    {
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <RedisQueueInit>(queueName,
                                                                      connectionString, interceptors, messageCount, logProvider, Helpers.GenerateDelayData,
                                                                      Helpers.Verify, batchSending, id, GenerateMethod.CreateCompiled, 0, null, false);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <RedisQueueInit>(queueName,
                                                                     connectionString, interceptors, messageCount, logProvider, Helpers.GenerateDelayData,
                                                                     Helpers.Verify, batchSending, id, GenerateMethod.CreateDynamic, 0, null, false);
                        }
#endif
                    }
                    else if (enableExpiration)
                    {
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <RedisQueueInit>(queueName,
                                                                      connectionString, interceptors, messageCount, logProvider, Helpers.GenerateExpiredData,
                                                                      Helpers.Verify, batchSending, id, GenerateMethod.CreateCompiled, 0, null, false);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <RedisQueueInit>(queueName,
                                                                     connectionString, interceptors, messageCount, logProvider, Helpers.GenerateExpiredData,
                                                                     Helpers.Verify, batchSending, id, GenerateMethod.CreateDynamic, 0, null, false);
                        }
#endif
                    }
                    else
                    {
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <RedisQueueInit>(queueName,
                                                                      connectionString, interceptors, messageCount, logProvider, Helpers.GenerateData,
                                                                      Helpers.Verify, batchSending, id, GenerateMethod.CreateCompiled, 0, null, false);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <RedisQueueInit>(queueName,
                                                                     connectionString, interceptors, messageCount, logProvider, Helpers.GenerateData,
                                                                     Helpers.Verify, batchSending, id, GenerateMethod.CreateDynamic, 0, null, false);
                        }
#endif
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        void RunConsumer <TTransportInit>(string queueName,
                                          string connectionString,
                                          bool addInterceptors,
                                          ILogProvider logProvider,
                                          int runTime,
                                          int messageCount,
                                          int timeOut,
                                          int readerCount,
                                          TimeSpan heartBeatTime,
                                          TimeSpan heartBeatMonitorTime,
                                          string updateTime,
                                          bool enableChaos,
                                          List <string> routes = null)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            var metricName = queueName;

            if (routes != null)
            {
                metricName = routes.Aggregate(metricName, (current, route) => current + route + "|-|");
            }

            using (var metrics = new Metrics.Metrics(metricName))
            {
                var processedCount         = new IncrementWrapper();
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos)
                    )
                {
                    using (
                        var queue =
                            creator
                            .CreateConsumerQueueScheduler(
                                queueName, connectionString, Factory))
                    {
                        SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount, heartBeatTime,
                                                              heartBeatMonitorTime, updateTime, null);

                        if (routes != null)
                        {
                            queue.Configuration.Routes.AddRange(routes);
                        }

                        var waitForFinish = new ManualResetEventSlim(false);
                        waitForFinish.Reset();

                        //start looking for work
                        queue.Start <TMessage>((message, notifications) =>
                        {
                            if (routes != null && routes.Count > 0)
                            {
                                MessageHandlingShared.HandleFakeMessages(message, runTime, processedCount, messageCount * routes.Count,
                                                                         waitForFinish);
                            }
                            else
                            {
                                MessageHandlingShared.HandleFakeMessages(message, runTime, processedCount, messageCount,
                                                                         waitForFinish);
                            }
                        });

                        waitForFinish.Wait(timeOut * 1000);
                    }

                    Assert.Null(processedCount.IdError);
                    if (routes != null && routes.Count > 0)
                    {
                        Assert.Equal(messageCount * routes.Count, processedCount.ProcessedCount);
                        VerifyMetrics.VerifyProcessedCount(queueName, metrics.GetCurrentMetrics(), messageCount * routes.Count);
                    }
                    else
                    {
                        Assert.Equal(messageCount, processedCount.ProcessedCount);
                        VerifyMetrics.VerifyProcessedCount(queueName, metrics.GetCurrentMetrics(), messageCount);
                    }
                    LoggerShared.CheckForErrors(queueName);
                }
            }
        }
        public void Run(
            bool interceptors,
            int producerCount)
        {
            var queueName = GenerateQueueName.Create();

            using (var queueContainer = new QueueContainer <PostgreSqlMessageQueueInit>(x => {
            }))
            {
                try
                {
                    var tests = new JobSchedulerTestsShared();
                    tests.RunTestMultipleProducers <PostgreSqlMessageQueueInit, PostgreSqlJobQueueCreation>(queueName,
                                                                                                            ConnectionInfo.ConnectionString, interceptors, producerCount, queueContainer.CreateTimeSync(ConnectionInfo.ConnectionString), LoggerShared.Create(queueName, GetType().Name));
                }
                finally
                {
                    using (var queueCreator =
                               new QueueCreationContainer <PostgreSqlMessageQueueInit>())
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                               ConnectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run(
            bool dynamic,
            ConnectionInfoTypes type)
        {
            var queueName        = GenerateQueueName.Create();
            var connectionString = new ConnectionInfo(type).ConnectionString;

            using (var queueContainer = new QueueContainer <RedisQueueInit>(x => { }))
            {
                try
                {
                    var tests = new JobSchedulerTestsShared();
                    if (!dynamic)
                    {
                        tests.RunEnqueueTestCompiled <RedisQueueInit, RedisJobQueueCreation>(queueName,
                                                                                             connectionString, true,
                                                                                             Helpers.Verify, Helpers.SetError, queueContainer.CreateTimeSync(connectionString), null, LoggerShared.Create(queueName, GetType().Name));
                    }
#if NETFULL
                    else
                    {
                        tests.RunEnqueueTestDynamic <RedisQueueInit, RedisJobQueueCreation>(queueName,
                                                                                            connectionString, true,
                                                                                            Helpers.Verify, Helpers.SetError, queueContainer.CreateTimeSync(connectionString), null, LoggerShared.Create(queueName, GetType().Name));
                    }
#endif
                }
                finally
                {
                    using (var queueCreator =
                               new QueueCreationContainer <RedisQueueInit>())
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                                   connectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
示例#16
0
        public void Run(int messageCount, int timeOut, int workerCount, 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 ConsumerErrorShared <FakeMessage>();
                            consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          workerCount, timeOut, messageCount, 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);

                            consumer.PurgeErrorMessages <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                                 false, logProvider, false);

                            //table should be empty now
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, messageCount);

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

                            //table should be empty now
                            ValidateErrorCounts(queueName, connectionInfo.ConnectionString, 0);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run(int messageCount, int runtime,
                        int timeOut, int workerCount, 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);

                            var producer = new ProducerMethodMultipleDynamicShared();
                            var id       = Guid.NewGuid();
                            producer.RunTestDynamic <SqLiteMessageQueueInit>(queueName,
                                                                             connectionInfo.ConnectionString, false, messageCount, logProvider,
                                                                             Helpers.GenerateData,
                                                                             Helpers.Verify, false, id, GenerateMethod.CreateMultipleDynamic, runtime, oCreation.Scope);

                            var consumer = new ConsumerMethodShared();
                            consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                          false,
                                                                          logProvider,
                                                                          runtime, messageCount,
                                                                          workerCount, timeOut,
                                                                          TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, "second(*%10)");

                            new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options)
                            .Verify(0, false, false);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
示例#18
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();
                }
            }
        }
示例#19
0
        public void Run(int messageCount, int timeOut, int workerCount,
                        int readerCount, int queueSize, bool useTransactions, bool enableChaos)
        {
            var queueName   = GenerateQueueName.Create();
            var logProvider = LoggerShared.Create(queueName, GetType().Name);

            using (
                var queueCreator =
                    new QueueCreationContainer <SqlServerMessageQueueInit>(
                        serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton)))
            {
                try
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <SqlServerMessageQueueCreation>(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 <SqlServerMessageQueueInit, FakeMessage>(queueName,
                                                                                  ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                  Helpers.Verify, false, oCreation.Scope, false);

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

                        consumer.PurgeErrorMessages <SqlServerMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                                false, logProvider, false);
                        ValidateErrorCounts(queueName, messageCount);

                        //purge error messages and verify that count is 0
                        consumer.PurgeErrorMessages <SqlServerMessageQueueInit>(queueName, ConnectionInfo.ConnectionString,
                                                                                false, logProvider, true);
                        ValidateErrorCounts(queueName, 0);
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <SqlServerMessageQueueCreation>(queueName,
                                                                                          ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize,
                        int messageType, ConnectionInfoTypes type)
        {
            SchedulerContainer schedulerContainer = null;

            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, queueSize, out schedulerContainer);
            }

            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
                {
                    if (messageType == 1)
                    {
                        var producer = new ProducerAsyncShared();
                        producer.RunTestAsync <RedisQueueInit, FakeMessage>(queueName,
                                                                            connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                            Helpers.Verify, false, null).Wait(timeOut * 1000 / 2);

                        var consumer = new ConsumerAsyncShared <FakeMessage> {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)");
                    }
                    else if (messageType == 2)
                    {
                        var producer = new ProducerAsyncShared();
                        producer.RunTestAsync <RedisQueueInit, FakeMessageA>(queueName,
                                                                             connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                             Helpers.Verify, false, null).Wait(timeOut * 1000 / 2);

                        var consumer = new ConsumerAsyncShared <FakeMessageA> {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)");
                    }
                    else if (messageType == 3)
                    {
                        var producer = new ProducerAsyncShared();
                        producer.RunTestAsync <RedisQueueInit, FakeMessageB>(queueName,
                                                                             connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                             Helpers.Verify, false, null).Wait(timeOut * 1000 / 2);


                        var consumer = new ConsumerAsyncShared <FakeMessageB> {
                            Factory = Factory
                        };
                        consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                              logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)");
                    }

                    using (var count = new VerifyQueueRecordCount(queueName, connectionString))
                    {
                        count.Verify(0, false, -1);
                    }
                }
                finally
                {
                    schedulerContainer?.Dispose();
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
示例#21
0
        public void Run <TTransportInit, TTransportCreate>(
            QueueConnection queueConnection,
            int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize,
            int messageType,
            LinqMethodTypes linqMethodTypes,
            bool enableChaos,
            Action <TTransportCreate> setOptions,
            Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
            Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount)
            where TTransportInit : ITransportInit, new()
            where TTransportCreate : class, IQueueCreation
        {
            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, queueSize);
            }

            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;

                    if (messageType == 1)
                    {
                        var id       = Guid.NewGuid();
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <TTransportInit>(queueConnection, false, messageCount, logProvider,
                                                               generateData,
                                                               verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <TTransportInit>(queueConnection,
                                                              false, logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id,
                                                              "second(*%10)", enableChaos, scope);
                    }
                    else if (messageType == 2)
                    {
                        var id       = Guid.NewGuid();
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <TTransportInit>(queueConnection, false, messageCount, logProvider,
                                                               generateData,
                                                               verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <TTransportInit>(queueConnection,
                                                              false, logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id,
                                                              "second(*%10)", enableChaos, scope);
                    }
                    else if (messageType == 3)
                    {
                        var id       = Guid.NewGuid();
                        var producer = new ProducerMethodAsyncShared();
                        producer.RunTestAsync <TTransportInit>(queueConnection, false, messageCount, logProvider,
                                                               generateData,
                                                               verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                        var consumer = new ConsumerMethodAsyncShared {
                            Factory = Factory
                        };
                        consumer.RunConsumer <TTransportInit>(queueConnection,
                                                              false, logProvider,
                                                              runtime, messageCount,
                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id,
                                                              "second(*%10)", enableChaos, scope);
                    }

                    verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, 0, false, false);
                }
                finally
                {
                    oCreation.RemoveQueue();
                    oCreation.Dispose();
                    scope?.Dispose();
                }
            }
        }
示例#22
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int runTime, int messageCount,
                                                 int workerCount, int timeOut,
                                                 TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime,
                                                 string route, bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer-expired"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorConsumer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                    }

                    var processedCount = new IncrementWrapper();
                    using (
                        var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider,
                                                                                 metrics, false, enableChaos, scope, trace.Source)
                        )
                    {
                        using (
                            var queue =
                                creator.CreateConsumer(queueConnection))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, route);
                            queue.Configuration.MessageExpiration.Enabled     = true;
                            queue.Configuration.MessageExpiration.MonitorTime = TimeSpan.FromSeconds(8);
                            var waitForFinish = new ManualResetEventSlim(false);
                            waitForFinish.Reset();
                            //start looking for work
                            queue.Start <TMessage>((message, notifications) =>
                            {
                                MessageHandlingShared.HandleFakeMessages <TMessage>(null, runTime, processedCount,
                                                                                    messageCount,
                                                                                    waitForFinish);
                            });

                            for (var i = 0; i < timeOut; i++)
                            {
                                if (VerifyMetrics.GetExpiredMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                {
                                    break;
                                }

                                Thread.Sleep(1000);
                            }
                        }

                        Assert.Equal(0, processedCount.ProcessedCount);
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(), 0);
                        VerifyMetrics.VerifyExpiredMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                                messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
        void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                          bool addInterceptors,
                                          ILogger logProvider,
                                          int runTime,
                                          int messageCount,
                                          int timeOut,
                                          int readerCount,
                                          TimeSpan heartBeatTime,
                                          TimeSpan heartBeatMonitorTime,
                                          Guid id,
                                          string updateTime,
                                          bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorConsumer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                    }

                    using (
                        var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider,
                                                                                 metrics, false, enableChaos, scope, trace.Source)
                        )
                    {
                        using (
                            var queue =
                                creator
                                .CreateConsumerMethodQueueScheduler(
                                    queueConnection, Factory))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);
                            queue.Start();
                            var counter = 0;
                            while (counter < timeOut)
                            {
                                if (MethodIncrementWrapper.Count(id) >= messageCount)
                                {
                                    break;
                                }

                                Thread.Sleep(1000);
                                counter++;
                            }
                        }

                        Assert.Equal(messageCount, MethodIncrementWrapper.Count(id));
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                           messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }
        public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize,
                        int messageType, bool inMemoryDb)
        {
            SchedulerContainer schedulerContainer = null;

            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, queueSize, out schedulerContainer);
            }


            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);

                            if (messageType == 1)
                            {
                                var producer = new ProducerAsyncShared();
                                producer.RunTestAsync <SqLiteMessageQueueInit, FakeMessage>(queueName,
                                                                                            connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                            Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000);

                                var consumer = new ConsumerAsyncShared <FakeMessage> {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)");
                            }
                            else if (messageType == 2)
                            {
                                var producer = new ProducerAsyncShared();
                                producer.RunTestAsync <SqLiteMessageQueueInit, FakeMessageA>(queueName,
                                                                                             connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                             Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000);

                                var consumer = new ConsumerAsyncShared <FakeMessageA> {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)");
                            }
                            else if (messageType == 3)
                            {
                                var producer = new ProducerAsyncShared();
                                producer.RunTestAsync <SqLiteMessageQueueInit, FakeMessageB>(queueName,
                                                                                             connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                                             Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000);

                                var consumer = new ConsumerAsyncShared <FakeMessageB> {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount,
                                                                              TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)");
                            }

                            new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options).Verify(0, false, false);
                        }
                    }
                    finally
                    {
                        schedulerContainer?.Dispose();
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public void Run(int messageCount, int timeOut,
                        int workerCount, ConnectionInfoTypes type, LinqMethodTypes linqMethodTypes)
        {
            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 id       = Guid.NewGuid();
                    var producer = new ProducerMethodShared();
                    if (linqMethodTypes == LinqMethodTypes.Compiled)
                    {
                        producer.RunTestCompiled <RedisQueueInit>(queueName,
                                                                  connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                  Helpers.Verify, false, id, GenerateMethod.CreateErrorCompiled, 0, null, false);
                    }
#if NETFULL
                    else
                    {
                        producer.RunTestDynamic <RedisQueueInit>(queueName,
                                                                 connectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                 Helpers.Verify, false, id, GenerateMethod.CreateErrorDynamic, 0, null, false);
                    }
#endif
                    //process data
                    var consumer = new ConsumerMethodErrorShared();
                    consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false,
                                                          logProvider,
                                                          workerCount, timeOut, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)", 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);
                    ValidateErrorCounts(queueName, connectionString, messageCount);

                    //purge error messages and verify that count is 0
                    consumer.PurgeErrorMessages <RedisQueueInit>(queueName, connectionString,
                                                                 false, logProvider, true);
                    ValidateErrorCounts(queueName, connectionString, 0);
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <RedisQueueCreation>(queueName,
                                                                               connectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
        public void Run(
            int messageCount,
            bool interceptors,
            bool enableDelayedProcessing,
            bool enableHeartBeat,
            bool enableHoldTransactionUntilMessageCommitted,
            bool enableMessageExpiration,
            bool enablePriority,
            bool enableStatus,
            bool enableStatusTable,
            bool additionalColumn,
            LinqMethodTypes linqMethodTypes,
            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 = enableDelayedProcessing;
                        oCreation.Options.EnableHeartBeat         = enableHeartBeat;
                        oCreation.Options.EnableMessageExpiration = enableMessageExpiration;
                        oCreation.Options.EnableHoldTransactionUntilMessageCommitted =
                            enableHoldTransactionUntilMessageCommitted;
                        oCreation.Options.EnablePriority    = enablePriority;
                        oCreation.Options.EnableStatus      = enableStatus;
                        oCreation.Options.EnableStatusTable = enableStatusTable;

                        if (additionalColumn)
                        {
                            oCreation.Options.AdditionalColumns.Add(new Column("OrderID", ColumnTypes.Integer, true));
                        }

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

                        var producer = new ProducerMethodShared();
                        if (linqMethodTypes == LinqMethodTypes.Compiled)
                        {
                            producer.RunTestCompiled <PostgreSqlMessageQueueInit>(queueName,
                                                                                  ConnectionInfo.ConnectionString, interceptors, messageCount, logProvider,
                                                                                  Helpers.GenerateData,
                                                                                  Helpers.Verify, false, Guid.NewGuid(), GenerateMethod.CreateCompiled, 0, oCreation.Scope, enableChaos);
                        }
#if NETFULL
                        else
                        {
                            producer.RunTestDynamic <PostgreSqlMessageQueueInit>(queueName,
                                                                                 ConnectionInfo.ConnectionString, interceptors, messageCount, logProvider,
                                                                                 Helpers.GenerateData,
                                                                                 Helpers.Verify, false, Guid.NewGuid(), GenerateMethod.CreateDynamic, 0, oCreation.Scope, enableChaos);
                        }
#endif
                    }
                }
                finally
                {
                    using (
                        var oCreation =
                            queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName,
                                                                                           ConnectionInfo.ConnectionString)
                        )
                    {
                        oCreation.RemoveQueue();
                    }
                }
            }
        }
示例#28
0
        public void Run(int messageCount, int runtime, int timeOut,
                        int workerCount, int readerCount, int queueSize,
                        int messageType, LinqMethodTypes linqMethodTypes)
        {
            if (Factory == null)
            {
                Factory = CreateFactory(workerCount, 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);

                            if (messageType == 1)
                            {
                                var id       = Guid.NewGuid();
                                var producer = new ProducerMethodAsyncShared();
                                producer.RunTestAsync <MemoryMessageQueueInit>(queueName,
                                                                               connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                                var consumer = new ConsumerMethodAsyncShared {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, "second(*%10)", false);
                            }
                            else if (messageType == 2)
                            {
                                var id       = Guid.NewGuid();
                                var producer = new ProducerMethodAsyncShared();
                                producer.RunTestAsync <MemoryMessageQueueInit>(queueName,
                                                                               connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                                var consumer = new ConsumerMethodAsyncShared {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, "second(*%10)", false);
                            }
                            else if (messageType == 3)
                            {
                                var id       = Guid.NewGuid();
                                var producer = new ProducerMethodAsyncShared();
                                producer.RunTestAsync <MemoryMessageQueueInit>(queueName,
                                                                               connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData,
                                                                               Helpers.Verify, false, runtime, id, linqMethodTypes, oCreation.Scope, false).Wait(timeOut);

                                var consumer = new ConsumerMethodAsyncShared {
                                    Factory = Factory
                                };
                                consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString,
                                                                              false, logProvider,
                                                                              runtime, messageCount,
                                                                              timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), id, "second(*%10)", false);
                            }

                            new VerifyQueueRecordCount().Verify(oCreation.Scope, 0, true);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <MessageQueueCreation>(queueName,
                                                                                     connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
        public async void Run(
            int messageCount,
            bool interceptors,
            bool enableDelayedProcessing,
            bool enableHeartBeat,
            bool enableMessageExpiration,
            bool enablePriority,
            bool enableStatus,
            bool enableStatusTable,
            bool additionalColumn,
            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 = enableDelayedProcessing;
                            oCreation.Options.EnableHeartBeat         = enableHeartBeat;
                            oCreation.Options.EnableMessageExpiration = enableMessageExpiration;
                            oCreation.Options.EnablePriority          = enablePriority;
                            oCreation.Options.EnableStatus            = enableStatus;
                            oCreation.Options.EnableStatusTable       = enableStatusTable;

                            if (additionalColumn)
                            {
                                oCreation.Options.AdditionalColumns.Add(new Column("OrderID", ColumnTypes.Integer, false, null));
                            }

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

                            var producer = new ProducerAsyncShared();
                            await producer.RunTestAsync <SqLiteMessageQueueInit, FakeMessage>(queueName,
                                                                                              connectionInfo.ConnectionString, interceptors, messageCount, logProvider,
                                                                                              Helpers.GenerateData,
                                                                                              Helpers.Verify, true, oCreation.Scope).ConfigureAwait(false);
                        }
                    }
                    finally
                    {
                        using (
                            var oCreation =
                                queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName,
                                                                                           connectionInfo.ConnectionString)
                            )
                        {
                            oCreation.RemoveQueue();
                        }
                    }
                }
            }
        }
示例#30
0
        public void RunConsumer <TTransportInit>(string queueName,
                                                 string connectionString,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogProvider logProvider,
                                                 int timeOut,
                                                 int runTime,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 string route, bool enableChaos)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var metrics = new Metrics.Metrics(queueName))
            {
                var addInterceptorConsumer = InterceptorAdding.No;
                if (addInterceptors)
                {
                    addInterceptorConsumer = InterceptorAdding.ConfigurationOnly;
                }

                var processedCount          = new IncrementWrapper();
                var haveIProcessedYouBefore = new ConcurrentDictionary <string, int>();
                using (
                    var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos)
                    )
                {
                    using (
                        var queue =
                            creator.CreateConsumer(queueName,
                                                   connectionString))
                    {
                        SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                              heartBeatMonitorTime, updateTime, route);
                        var waitForFinish = new ManualResetEventSlim(false);
                        waitForFinish.Reset();

                        //start looking for work
                        queue.Start <TMessage>((message, notifications) =>
                        {
                            MessageHandlingShared.HandleFakeMessagesRollback(message, runTime, processedCount,
                                                                             messageCount,
                                                                             waitForFinish, haveIProcessedYouBefore);
                        });

                        waitForFinish.Wait(timeOut * 1000);
                    }
                    Assert.Equal(messageCount, processedCount.ProcessedCount);
                    VerifyMetrics.VerifyProcessedCount(queueName, metrics.GetCurrentMetrics(), messageCount);
                    VerifyMetrics.VerifyRollBackCount(queueName, metrics.GetCurrentMetrics(), messageCount, 1, 0);
                    LoggerShared.CheckForErrors(queueName);
                    haveIProcessedYouBefore.Clear();
                }
            }
        }