Example #1
0
        private void RunConsumerInternal(QueueConnection queueConnection, bool addInterceptors,
                                         ILogger logProvider,
                                         int runTime, int messageCount,
                                         int workerCount, int timeOut, IDisposable queueBad,
                                         TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, Guid id, string updateTime, bool enableChaos, ICreationScope scope)
        {
            using (var trace = SharedSetup.CreateTrace("consumer-cancel"))
            {
                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.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);
                            queue.Start();

                            var time = runTime * 1000 / 2;
                            Thread.Sleep(time);
                            queueBad.Dispose();
                            _badQueueContainer.Dispose();

                            var counter     = 0;
                            var counterLess = timeOut / 2;
                            while (counter < counterLess)
                            {
                                if (MethodIncrementWrapper.Count(id) >= messageCount)
                                {
                                    break;
                                }

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

                            //wait for commits in transport...
                            Thread.Sleep(3000);
                        }

                        var count = MethodIncrementWrapper.Count(id);
                        Assert.Equal(messageCount, count);
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                           messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
        public void PurgeErrorMessages <TTransportInit>(QueueConnection queueConnection,
                                                        bool addInterceptors, ILogger logProvider, bool actuallyPurge, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer-error"))
            {
                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, false, scope, trace.Source)
                        )
                    {
                        using (
                            var queue =
                                creator.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueueErrorPurge(queue.Configuration, actuallyPurge);
                            SharedSetup.SetupDefaultErrorRetry(queue.Configuration);
                            queue.Start();
                            Thread.Sleep(15000);
                        }
                    }
                }
            }
        }
Example #3
0
 public void Run <TTransportInit, TJobQueueCreator, TTransportCreate>(
     QueueConnection queueConnection,
     int producerCount)
     where TTransportInit : ITransportInit, new()
     where TJobQueueCreator : class, IJobQueueCreation
     where TTransportCreate : class, IQueueCreation
 {
     using (var trace = SharedSetup.CreateTrace("jobscheduler"))
     {
         using (var queueCreator =
                    new QueueCreationContainer <TTransportInit>(x => x.RegisterNonScopedSingleton(trace.Source)))
         {
             var oCreation = queueCreator.GetQueueCreation <TTransportCreate>(queueConnection);
             var scope     = oCreation.Scope;
             using (var queueContainer =
                        new QueueContainer <TTransportInit>(x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
             {
                 try
                 {
                     var tests = new JobSchedulerTestsShared();
                     tests.RunTestMultipleProducers <TTransportInit, TJobQueueCreator>(
                         queueConnection, true, producerCount,
                         queueContainer.CreateTimeSync(queueConnection.Connection),
                         LoggerShared.Create(queueConnection.Queue, GetType().Name), scope);
                 }
                 finally
                 {
                     oCreation.RemoveQueue();
                     oCreation.Dispose();
                     scope?.Dispose();
                 }
             }
         }
     }
 }
Example #4
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer-poison"))
            {
                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,
                                                                                 true, enableChaos, scope, trace.Source))
                    {
                        using (
                            var queue =
                                creator.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);

                            var waitForFinish = new ManualResetEventSlim(false);
                            waitForFinish.Reset();
                            queue.Start();
                            for (var i = 0; i < timeOut; i++)
                            {
                                if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                {
                                    break;
                                }

                                Thread.Sleep(1000);
                            }
                        }

                        VerifyMetrics.VerifyPoisonMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                               messageCount);
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int runTime, int messageCount,
                                                 int workerCount, int timeOut,
                                                 TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 Guid id, bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer-expired"))
            {
                if (enableChaos)
                {
                    timeOut *= 2;
                }

                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.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);
                            queue.Configuration.MessageExpiration.Enabled     = true;
                            queue.Configuration.MessageExpiration.MonitorTime = TimeSpan.FromSeconds(8);
                            queue.Start();
                            for (var i = 0; i < timeOut; i++)
                            {
                                if (VerifyMetrics.GetExpiredMessageCount(metrics.GetCurrentMetrics()) == messageCount)
                                {
                                    break;
                                }

                                Thread.Sleep(1000);
                            }
                        }

                        Assert.Equal(0, MethodIncrementWrapper.Count(id));
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(), 0);
                        VerifyMetrics.VerifyExpiredMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                                messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
Example #6
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, bool enableChaos,
                                                 ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer"))
            {
                if (enableChaos)
                {
                    timeOut *= 2;
                }

                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, null);
                            var waitForFinish = new ManualResetEventSlim(false);
                            waitForFinish.Reset();
                            //start looking for work
                            queue.Start <TMessage>((message, notifications) =>
                            {
                                MessageHandlingShared.HandleFakeMessages(message, runTime, processedCount, messageCount,
                                                                         waitForFinish);
                            });

                            waitForFinish.Wait(timeOut * 1000);
                        }

                        Assert.Null(processedCount.IdError);
                        Assert.Equal(messageCount, processedCount.ProcessedCount);
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                           messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
Example #7
0
        public void PurgeErrorMessages <TTransportInit>(QueueConnection queueConnection,
                                                        bool addInterceptors, ILogger logProvider, bool actuallyPurge, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer-error"))
            {
                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, false, scope, trace.Source)
                        )
                    {
                        using (var schedulerCreator =
                                   new SchedulerContainer(
                                       // ReSharper disable once AccessToDisposedClosure
                                       serviceRegister => serviceRegister.Register(() => metrics, LifeStyles.Singleton).RegisterNonScopedSingleton(trace.Source),
                                       options => SharedSetup.SetOptions(options, false)))
                        {
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    SharedSetup.SetupDefaultConsumerQueueErrorPurge(queue.Configuration, actuallyPurge);
                                    SharedSetup.SetupDefaultErrorRetry(queue.Configuration);

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

                                    //start looking for work
                                    queue.Start <TMessage>((message, notifications) =>
                                                           throw new Exception("There should have been no data to process"));

                                    //wait for 30 seconds
                                    waitForFinish.Wait(15000);
                                }
                            }
                        }
                    }
                }
            }
        }
        private void RunConsumerInternal(QueueConnection queueConnection, bool addInterceptors,
                                         ILogger logProvider,
                                         int runTime, int messageCount,
                                         int workerCount, int timeOut, IDisposable queueBad,
                                         TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, string route, bool enableChaos, ICreationScope scope)
        {
            using (var trace = SharedSetup.CreateTrace("consumer-cancel"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var processedCount         = new IncrementWrapper();
                    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.CreateConsumer(queueConnection))
                        {
                            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.HandleFakeMessages <TMessage>(null, runTime, processedCount,
                                                                                    messageCount,
                                                                                    waitForFinish);
                            });

                            var time = runTime * 1000 / 2;
                            waitForFinish.Wait(time);

                            queueBad.Dispose();
                            _badQueueContainer.Dispose();

                            waitForFinish.Wait(timeOut * 1000 - time);
                        }

                        Assert.Equal(messageCount, processedCount.ProcessedCount);
                        VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                           messageCount);
                        LoggerShared.CheckForErrors(queueConnection.Queue);
                    }
                }
            }
        }
Example #9
0
 public void Run <TTransportInit, TJobQueueCreator, TTransportCreate>(
     QueueConnection queueConnection,
     bool interceptors,
     bool dynamic,
     Action <QueueConnection, long, ICreationScope> verify,
     Action <QueueConnection, ICreationScope> setErrorFlag)
     where TTransportInit : ITransportInit, new()
     where TJobQueueCreator : class, IJobQueueCreation
     where TTransportCreate : class, IQueueCreation
 {
     using (var trace = SharedSetup.CreateTrace("jobscheduler"))
     {
         using (var queueCreator =
                    new QueueCreationContainer <TTransportInit>((x) => x.RegisterNonScopedSingleton(trace.Source)))
         {
             var            oCreation = queueCreator.GetQueueCreation <TTransportCreate>(queueConnection);
             ICreationScope scope     = oCreation.Scope;
             using (var queueContainer =
                        new QueueContainer <TTransportInit>(x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
             {
                 try
                 {
                     var tests = new JobSchedulerTestsShared();
                     if (!dynamic)
                     {
                         tests.RunEnqueueTestCompiled <TTransportInit, TJobQueueCreator>(
                             queueConnection, interceptors,
                             verify, setErrorFlag,
                             queueContainer.CreateTimeSync(queueConnection.Connection),
                             oCreation.Scope, LoggerShared.Create(queueConnection.Queue, GetType().Name));
                     }
                     else
                     {
                         tests.RunEnqueueTestDynamic <TTransportInit, TJobQueueCreator>(
                             queueConnection, interceptors,
                             verify, setErrorFlag,
                             queueContainer.CreateTimeSync(queueConnection.Connection),
                             oCreation.Scope, LoggerShared.Create(queueConnection.Queue, GetType().Name));
                     }
                 }
                 finally
                 {
                     oCreation.RemoveQueue();
                     oCreation.Dispose();
                     scope?.Dispose();
                 }
             }
         }
     }
 }
Example #10
0
        public void PurgeErrorMessages <TTransportInit>(QueueConnection queueConnection,
                                                        bool addInterceptors, ILogger logProvider, bool actuallyPurge, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer-error"))
            {
                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, false, scope, trace.Source)
                        )
                    {
                        using (var schedulerCreator =
                                   new SchedulerContainer(
                                       // ReSharper disable once AccessToDisposedClosure
                                       serviceRegister => serviceRegister.Register(() => metrics, LifeStyles.Singleton).RegisterNonScopedSingleton(trace.Source)))
                        {
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerMethodQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    SharedSetup.SetupDefaultConsumerQueueErrorPurge(queue.Configuration, actuallyPurge);
                                    SharedSetup.SetupDefaultErrorRetry(queue.Configuration);
                                    queue.Start();
                                    Thread.Sleep(15000);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #11
0
        public void RunTest <TTransportInit, TMessage>(QueueConnection queueConnection,
                                                       bool addInterceptors,
                                                       long messageCount,
                                                       ILogger logProvider,
                                                       Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
                                                       Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
                                                       bool sendViaBatch, bool validateMetricCounts,
                                                       ICreationScope scope, bool enableChaos)
            where TTransportInit : ITransportInit, new()
            where TMessage : class
        {
            using (var trace = SharedSetup.CreateTrace("producer"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorProducer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorProducer = InterceptorAdding.Yes;
                    }

                    using (
                        var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorProducer, logProvider,
                                                                                 metrics, false, enableChaos, scope, trace.Source)
                        )
                    {
                        //create the queue
                        using (var queue =
                                   creator
                                   .CreateProducer
                                   <TMessage>(queueConnection))
                        {
                            RunProducer(queue, queueConnection, messageCount, generateData, verify, sendViaBatch,
                                        scope);
                        }

                        if (validateMetricCounts)
                        {
                            VerifyMetrics.VerifyProducedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount);
                        }
                    }
                }
            }
        }
        public void RunTestCompiled <TTransportInit>(QueueConnection queueConnection,
                                                     bool addInterceptors,
                                                     long messageCount,
                                                     ILogger logProvider,
                                                     Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
                                                     Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
                                                     bool sendViaBatch, bool validateMetricCounts, Guid id,
                                                     Func <Guid, int, Expression <Action <IReceivedMessage <MessageExpression>, IWorkerNotification> > >
                                                     generateTestMethod, int runTime, ICreationScope scope, bool enableChaos)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("producer-method"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorProducer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorProducer = InterceptorAdding.Yes;
                    }

                    using (
                        var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorProducer, logProvider,
                                                                                 metrics, false, enableChaos, scope, trace.Source)
                        )
                    {
                        //create the queue
                        using (var queue =
                                   creator
                                   .CreateMethodProducer(queueConnection))
                        {
                            RunProducerCompiled(queue, queueConnection, messageCount, generateData, verify,
                                                sendViaBatch, id,
                                                generateTestMethod, runTime, scope);
                        }

                        if (validateMetricCounts)
                        {
                            VerifyMetrics.VerifyProducedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount);
                        }
                    }
                }
            }
        }
        public async Task RunTestAsync <TTransportInit>(QueueConnection queueConnection,
                                                        bool addInterceptors,
                                                        long messageCount,
                                                        ILogger logProvider,
                                                        Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
                                                        Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch,
                                                        int runTime, Guid id, LinqMethodTypes linqMethodTypes,
                                                        ICreationScope scope, bool enableChaos)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("producer"))
            {
                using (var metrics = new Metrics.Metrics(queueConnection.Queue))
                {
                    var addInterceptorProducer = InterceptorAdding.No;
                    if (addInterceptors)
                    {
                        addInterceptorProducer = InterceptorAdding.Yes;
                    }

                    using (
                        var creator =
                            SharedSetup.CreateCreator <TTransportInit>(addInterceptorProducer, logProvider, metrics, false,
                                                                       enableChaos, scope, trace.Source)
                        )
                    {
                        //create the queue
                        using (var queue =
                                   creator
                                   .CreateMethodProducer(queueConnection))
                        {
                            await
                            RunProducerAsync(queue, queueConnection, messageCount, generateData, verify,
                                             sendViaBatch,
                                             runTime, id,
                                             linqMethodTypes, scope).ConfigureAwait(false);
                        }

                        VerifyMetrics.VerifyProducedAsyncCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                               messageCount);
                    }
                }
            }
        }
        public void PurgeErrorMessages <TTransportInit>(QueueConnection queueConnection,
                                                        bool addInterceptors, ILogger logProvider, bool actuallyPurge, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            using (var trace = SharedSetup.CreateTrace("consumer-error"))
            {
                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, false, scope, trace.Source)
                        )
                    {
                        using (
                            var queue =
                                creator.CreateConsumer(queueConnection))
                        {
                            SharedSetup.SetupDefaultConsumerQueueErrorPurge(queue.Configuration, actuallyPurge);
                            SharedSetup.SetupDefaultErrorRetry(queue.Configuration);

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

                            //start looking for work
                            queue.Start <TMessage>((message, notifications) =>
                                                   throw new Exception("There should have been no data to process"));

                            //wait for 30 seconds
                            waitForFinish.Wait(15000);
                        }
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int workerCount, int timeOut, int messageCount,
                                                 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-error"))
            {
                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)
                        )
                    {
                        bool rollBacks;
                        using (
                            var queue =
                                creator.CreateConsumer(queueConnection))
                        {
                            rollBacks = queue.Configuration.TransportConfiguration.MessageRollbackSupported;

                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, route);
                            SharedSetup.SetupDefaultErrorRetry(queue.Configuration);

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

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

                            waitForFinish.Wait(timeOut * 1000);

                            //wait 3 more seconds before starting to shutdown
                            Thread.Sleep(3000);
                        }

                        if (rollBacks)
                        {
                            VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount, 2, 2);
                        }
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int workerCount, int timeOut, int messageCount,
                                                 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-error"))
            {
                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)
                        )
                    {
                        bool rollbacks;
                        using (
                            var queue =
                                creator.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope).RegisterNonScopedSingleton(trace.Source)))
                        {
                            SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime,
                                                                  heartBeatMonitorTime, updateTime, null);
                            SharedSetup.SetupDefaultErrorRetry(queue.Configuration);
                            rollbacks = queue.Configuration.TransportConfiguration.MessageRollbackSupported;
                            queue.Start();

                            var counter = 0;
                            while (counter < timeOut)
                            {
                                if (MethodIncrementWrapper.Count(id) >= messageCount * 3)
                                {
                                    break;
                                }

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

                            //wait 3 more seconds before starting to shutdown
                            Thread.Sleep(3000);
                        }

                        if (rollbacks)
                        {
                            VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount, 2, 2);
                        }
                    }
                }
            }
        }
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 int readerCount,
                                                 int queueSize,
                                                 long messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updatetime,
                                                 bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer-poison"))
            {
                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,
                                                                                 true, enableChaos, scope, trace.Source))
                    {
                        using (var schedulerCreator = new SchedulerContainer((x) => x.RegisterNonScopedSingleton(trace.Source)))
                        {
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Configuration.MaximumThreads = workerCount;

                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerMethodQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount,
                                                                          heartBeatTime,
                                                                          heartBeatMonitorTime, updatetime, null);
                                    queue.Start();
                                    for (var i = 0; i < timeOut; i++)
                                    {
                                        if (VerifyMetrics.GetPoisonMessageCount(metrics.GetCurrentMetrics()) ==
                                            messageCount)
                                        {
                                            break;
                                        }

                                        Thread.Sleep(1000);
                                    }

                                    //wait for last error to be saved if needed.
                                    Thread.Sleep(3000);
                                }
                            }

                            VerifyMetrics.VerifyPoisonMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                                   messageCount);
                        }
                    }
                }
            }
        }
Example #18
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 int readerCount,
                                                 int queueSize,
                                                 int runTime,
                                                 int messageCount,
                                                 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-rollback"))
            {
                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 schedulerCreator = new SchedulerContainer((x) => x.RegisterNonScopedSingleton(trace.Source)))
                        {
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Configuration.MaximumThreads = workerCount;

                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerMethodQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    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++;
                                    }

                                    //wait for queues to commit records
                                    Thread.Sleep(3000);
                                }
                            }

                            Assert.Equal(messageCount, MethodIncrementWrapper.Count(id));
                            VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                               messageCount);
                            VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount, 1, 0);
                        }
                    }
                }
            }
        }
Example #19
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int messageCount, int workerCount, int timeOut,
                                                 int queueSize, int readerCount,
                                                 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-error"))
            {
                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 schedulerCreator =
                                   new SchedulerContainer(
                                       // ReSharper disable once AccessToDisposedClosure
                                       serviceRegister => serviceRegister.Register(() => metrics, LifeStyles.Singleton).RegisterNonScopedSingleton(trace.Source),
                                       options => SharedSetup.SetOptions(options, enableChaos)))
                        {
                            bool rollBacks;
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Configuration.MaximumThreads = workerCount;

                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    rollBacks = queue.Configuration.TransportConfiguration.MessageRollbackSupported;
                                    SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount,
                                                                          heartBeatTime,
                                                                          heartBeatMonitorTime, updateTime, route);
                                    SharedSetup.SetupDefaultErrorRetry(queue.Configuration);

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

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

                                    waitForFinish.Wait(timeOut * 1000);

                                    //wait for last error to be saved if needed.
                                    Thread.Sleep(3000);
                                }
                            }

                            if (rollBacks)
                            {
                                VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                                  messageCount, 2, 2);
                            }
                        }
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Example #21
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection,
                                                 bool addInterceptors,
                                                 int workerCount,
                                                 ILogger logProvider,
                                                 int timeOut,
                                                 int readerCount,
                                                 int queueSize,
                                                 int runTime,
                                                 int messageCount,
                                                 TimeSpan heartBeatTime,
                                                 TimeSpan heartBeatMonitorTime,
                                                 string updateTime,
                                                 string route, bool enableChaos, ICreationScope scope)
            where TTransportInit : ITransportInit, new()
        {
            var processedCount          = new IncrementWrapper();
            var haveIProcessedYouBefore = new ConcurrentDictionary <string, int>();

            if (enableChaos)
            {
                timeOut *= 2;
            }

            using (var trace = SharedSetup.CreateTrace("consumer-rollback"))
            {
                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 schedulerCreator = new SchedulerContainer((x) => x.RegisterNonScopedSingleton(trace.Source)))
                        {
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Configuration.MaximumThreads = workerCount;

                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount,
                                                                          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(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                               messageCount);
                            VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                              messageCount, 1, 0);
                        }
                    }

                    haveIProcessedYouBefore.Clear();
                }
            }
        }
Example #22
0
        public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors,
                                                 ILogger logProvider,
                                                 int messageCount, int workerCount, int timeOut,
                                                 int queueSize, 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-error"))
            {
                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 schedulerCreator =
                                   new SchedulerContainer(
                                       // ReSharper disable once AccessToDisposedClosure
                                       serviceRegister => serviceRegister.Register(() => metrics, LifeStyles.Singleton).RegisterNonScopedSingleton(trace.Source)))
                        {
                            bool rollback;
                            using (var taskScheduler = schedulerCreator.CreateTaskScheduler())
                            {
                                taskScheduler.Configuration.MaximumThreads = workerCount;

                                taskScheduler.Start();
                                var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler);

                                using (
                                    var queue =
                                        creator
                                        .CreateConsumerMethodQueueScheduler(
                                            queueConnection, taskFactory))
                                {
                                    SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount,
                                                                          heartBeatTime,
                                                                          heartBeatMonitorTime, updateTime, null);
                                    SharedSetup.SetupDefaultErrorRetry(queue.Configuration);
                                    rollback = queue.Configuration.TransportConfiguration.MessageRollbackSupported;
                                    queue.Start();
                                    var counter = 0;
                                    while (counter < timeOut)
                                    {
                                        if (MethodIncrementWrapper.Count(id) >= messageCount * 3)
                                        {
                                            break;
                                        }

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

                                    //wait 3 more seconds before starting to shutdown
                                    Thread.Sleep(3000);
                                }
                            }

                            if (rollback)
                            {
                                VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(),
                                                                  messageCount, 2, 2);
                            }
                        }
                    }
                }
            }
        }