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, Guid id, 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; } using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos) ) { using ( var queue = creator.CreateMethodConsumer(queueName, connectionString)) { SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, 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(queueName, metrics.GetCurrentMetrics(), messageCount); VerifyMetrics.VerifyRollBackCount(queueName, metrics.GetCurrentMetrics(), messageCount, 1, 0); LoggerShared.CheckForErrors(queueName); } } }
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); } } } }
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 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) ) { 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 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); } } } }
public void RunConsumer <TTransportInit>(string queueName, string connectionString, bool addInterceptors, ILogProvider logProvider, int workerCount, int timeOut, int messageCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, Guid id, string updateTime, 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; } using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos) ) { bool rollbacks; using ( var queue = creator.CreateMethodConsumer(queueName, connectionString)) { 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(queueName, metrics.GetCurrentMetrics(), messageCount, 2, 2); } } } }
private void RunRpcReceive(string queueName, string connectionString, ILogProvider logProvider, // ReSharper disable once UnusedParameter.Local int runTime, int messageCount, int workerCount, int timeOut, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, Guid id) { using (var metrics = new Metrics.Metrics(queueName)) { using ( var creator = SharedSetup.CreateCreator <TTransportInit>(InterceptorAdding.Yes, logProvider, metrics) ) { using ( var queue = creator.CreateMethodConsumer(queueName, connectionString)) { SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime, heartBeatMonitorTime, updateTime, null); queue.Configuration.TransportConfiguration.QueueDelayBehavior.Clear(); queue.Configuration.TransportConfiguration.QueueDelayBehavior.Add(TimeSpan.FromMilliseconds(100)); queue.Configuration.Worker.SingleWorkerWhenNoWorkFound = false; 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(queueName, metrics.GetCurrentMetrics(), messageCount); } } }
public void RunConsumer <TTransportInit>(string queueName, string connectionString, bool addInterceptors, ILogProvider logProvider, int messageCount, int workerCount, int timeOut, int queueSize, int readerCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, Guid id, string updateTime, 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; } using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos) ) { using (var schedulerCreator = new SchedulerContainer( // ReSharper disable once AccessToDisposedClosure serviceRegister => serviceRegister.Register(() => metrics, LifeStyles.Singleton))) { bool rollback; using (var taskScheduler = schedulerCreator.CreateTaskScheduler()) { taskScheduler.Configuration.MaximumThreads = workerCount; taskScheduler.Configuration.MaxQueueSize = queueSize; taskScheduler.Start(); var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler); using ( var queue = creator .CreateConsumerMethodQueueScheduler( queueName, connectionString, 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(queueName, metrics.GetCurrentMetrics(), messageCount, 2, 2); } } } } }
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); } } } } }