public void Run <TTransportInit, TTransportCreate>( QueueConnection queueConnection, int messageCount, int queueCount, LinqMethodTypes linqMethodTypes, bool enableChaos, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, string> 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 { var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); scope = oCreation.Scope; RunTest <TTransportInit>(queueConnection, messageCount, queueCount, logProvider, linqMethodTypes, oCreation.Scope, enableChaos, generateData); LoggerShared.CheckForErrors(queueConnection.Queue); verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, messageCount * queueCount, null); } finally { oCreation.RemoveQueue(); oCreation.Dispose(); scope?.Dispose(); } } }
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); } } }
public void Run(string queueNameReceive, string queueNameSend, string connectionStringReceive, string connectionStringSend, ILogProvider logProviderReceive, ILogProvider logProviderSend, int runtime, int messageCount, int workerCount, int timeOut, bool async, TTConnectionSettings rpcConnection, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime) { using (_creator = new QueueContainer <TTransportInit>()) { _queues = new ConcurrentDictionary <IConnectionInformation, IProducerQueueRpc <TTResponse> >(); var processedCount = new IncrementWrapper(); var waitForFinish = new ManualResetEventSlim(false); var task1 = Task.Factory.StartNew(() => RunRpcReceive(queueNameSend, connectionStringSend, logProviderSend, runtime, processedCount, messageCount, waitForFinish, workerCount, timeOut, heartBeatTime, heartBeatMonitorTime, updateTime)); RunRpcSend(logProviderSend, messageCount, async, rpcConnection); Task.WaitAll(task1); LoggerShared.CheckForErrors(queueNameSend); LoggerShared.CheckForErrors(queueNameReceive); foreach (var queue in _queues) { queue.Value.Dispose(); } _queues.Clear(); } }
public void RunConsumer <TTransportInit>(string queueName, string connectionString, bool addInterceptors, ILogProvider logProvider, int runTime, int messageCount, int workerCount, int timeOut, 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(); 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); 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(queueName, metrics.GetCurrentMetrics(), 0); VerifyMetrics.VerifyExpiredMessageCount(queueName, metrics.GetCurrentMetrics(), messageCount); 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); } } } }
public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors, int workerCount, ILogger logProvider, int timeOut, int runTime, long messageCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, string route, 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; } var processedCount = new IncrementWrapper(); var haveIProcessedYouBefore = new ConcurrentDictionary <string, int>(); using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, false, enableChaos, scope) ) { 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.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); LoggerShared.CheckForErrors(queueConnection.Queue); haveIProcessedYouBefore.Clear(); } } }
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 Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, bool inMemoryDb, bool enableChaos) { using (var connectionInfo = new IntegrationConnectionInfo(inMemoryDb)) { var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); using (var queueCreator = new QueueCreationContainer <SqLiteMessageQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { using ( var oCreation = queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { oCreation.Options.EnableDelayedProcessing = true; oCreation.Options.EnableHeartBeat = true; oCreation.Options.EnableStatus = true; oCreation.Options.EnableStatusTable = true; var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); //create data var producer = new ProducerShared(); producer.RunTest <SqLiteMessageQueueInit, FakeMessage>(queueName, connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope, false); //process data var consumer = new ConsumerAsyncRollBackShared <FakeMessage>(); consumer.RunConsumer <SqLiteMessageQueueInit>(queueName, connectionInfo.ConnectionString, false, workerCount, logProvider, timeOut, readerCount, queueSize, runtime, messageCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", null, enableChaos); LoggerShared.CheckForErrors(queueName); new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options).Verify(0, false, false); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, 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.CreateRollBackCompiled, runtime, null); } #if NETFULL else { producer.RunTestDynamic <RedisQueueInit>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, id, GenerateMethod.CreateRollBackDynamic, runtime, null); } #endif //process data var consumer = new ConsumerMethodAsyncRollBackShared(); consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false, workerCount, logProvider, timeOut, readerCount, queueSize, runtime, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)"); LoggerShared.CheckForErrors(queueName); using (var count = new VerifyQueueRecordCount(queueName, connectionString)) { count.Verify(0, false, -1); } GenerateMethod.ClearRollback(id); } finally { using ( var oCreation = queueCreator.GetQueueCreation <RedisQueueCreation>(queueName, connectionString) ) { oCreation.RemoveQueue(); } } } }
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); } } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, ConnectionInfoTypes type, bool route) { var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); var connectionString = new ConnectionInfo(type).ConnectionString; using ( var queueCreator = new QueueCreationContainer <RedisQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { //create data if (route) { var producer = new ProducerShared(); producer.RunTest <RedisQueueInit, FakeMessage>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateRouteData, Helpers.Verify, false, null); } else { var producer = new ProducerShared(); producer.RunTest <RedisQueueInit, FakeMessage>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, null); } //process data var defaultRoute = route ? Helpers.DefaultRoute : null; var consumer = new ConsumerAsyncRollBackShared <FakeMessage>(); consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false, workerCount, logProvider, timeOut, readerCount, queueSize, runtime, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)", defaultRoute); LoggerShared.CheckForErrors(queueName); using (var count = new VerifyQueueRecordCount(queueName, connectionString)) { count.Verify(0, false, -1); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <RedisQueueCreation>(queueName, connectionString) ) { oCreation.RemoveQueue(); } } } }
private void RunProducerDynamic( IProducerMethodQueue queue, QueueConnection queueConnection, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, Guid id, Func <Guid, int, LinqExpressionToRun> generateTestMethod, int runTime, ICreationScope scope) { RunProducerDynamicInternal(queue, messageCount, generateData, sendViaBatch, id, generateTestMethod, runTime); LoggerShared.CheckForErrors(queueConnection.Queue); verify(queueConnection, queue.Configuration, messageCount, scope); }
public void Run <TTransportInit, TMessage, TTransportCreate>( QueueConnection queueConnection, int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, bool enableChaos, Action <TTransportCreate> setOptions, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount) 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 ConsumerAsyncRollBackShared <TMessage>(); consumer.RunConsumer <TTransportInit>(queueConnection, false, workerCount, logProvider, timeOut, readerCount, queueSize, runtime, messageCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", null, enableChaos, scope); LoggerShared.CheckForErrors(queueConnection.Queue); verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, 0, false, false); } finally { oCreation?.RemoveQueue(); oCreation?.Dispose(); scope?.Dispose(); } } }
private void RunProducerCompiled( IProducerMethodQueue queue, QueueConnection queueConnection, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, Guid id, Func <Guid, int, Expression <Action <IReceivedMessage <MessageExpression>, IWorkerNotification> > > generateTestMethod, int runTime, ICreationScope scope) { RunProducerCompiledInternal(queue, messageCount, generateData, sendViaBatch, id, generateTestMethod, runTime); LoggerShared.CheckForErrors(queueConnection.Queue); verify(queueConnection, queue.Configuration, messageCount, scope); }
private async Task RunProducerAsync( IProducerMethodQueue queue, QueueConnection queueConnection, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, int runTime, Guid id, LinqMethodTypes type, ICreationScope scope) { await RunProducerInternalAsync(queue, messageCount, generateData, sendViaBatch, runTime, id, type) .ConfigureAwait(false); LoggerShared.CheckForErrors(queueConnection.Queue); verify(queueConnection, queue.Configuration, messageCount, scope); }
private async Task RunProducerAsync <TMessage>( IProducerQueue <TMessage> queue, string queueName, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <string, string, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, ICreationScope scope) where TMessage : class { await RunProducerInternalAsync(queue, messageCount, generateData, sendViaBatch).ConfigureAwait(false); LoggerShared.CheckForErrors(queueName); verify(queueName, queue.Configuration.TransportConfiguration.ConnectionInfo.ConnectionString, queue.Configuration, messageCount, scope); }
private void RunProducer <TMessage>( IProducerQueue <TMessage> queue, QueueConnection queueConnection, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, ICreationScope scope) where TMessage : class { RunProducerInternal(queue, messageCount, generateData, sendViaBatch); LoggerShared.CheckForErrors(queueConnection.Queue); verify(queueConnection, queue.Configuration, messageCount, scope); }
public void Run(string queueNameReceive, string queueNameSend, string connectionStringReceive, string connectionStringSend, ILogProvider logProviderReceive, ILogProvider logProviderSend, int runtime, int messageCount, int workerCount, int timeOut, bool async, TTConnectionSettings rpcConnection, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, Guid id, LinqMethodTypes linqMethodTypes, string updateTime) { var task1 = Task.Factory.StartNew(() => RunRpcReceive(queueNameSend, connectionStringSend, logProviderSend, runtime, messageCount, workerCount, timeOut, heartBeatTime, heartBeatMonitorTime, updateTime, id)); RunRpcSend(logProviderSend, messageCount, async, rpcConnection, runtime, id, linqMethodTypes); Task.WaitAll(task1); LoggerShared.CheckForErrors(queueNameSend); LoggerShared.CheckForErrors(queueNameReceive); }
public void RunConsumer <TTransportInit>(string queueName, string connectionString, bool addInterceptors, ILogProvider logProvider, int runTime, int messageCount, int workerCount, int timeOut, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime) where TTransportInit : ITransportInit, new() { using (var metrics = new Metrics.Metrics(queueName)) { var addInterceptorConsumer = InterceptorAdding.No; if (addInterceptors) { addInterceptorConsumer = InterceptorAdding.ConfigurationOnly; } var processedCount = new IncrementWrapper(); using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics) ) { using ( var queue = creator.CreateConsumer(queueName, connectionString)) { 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(queueName, metrics.GetCurrentMetrics(), messageCount); LoggerShared.CheckForErrors(queueName); } } }
public void Run(int messageCount, 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) ) { var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); RunTest(queueName, messageCount, 10, logProvider, connectionInfo.ConnectionString, linqMethodTypes, oCreation.Scope, enableChaos); LoggerShared.CheckForErrors(queueName); new VerifyQueueData(queueName, connectionInfo.ConnectionString, oCreation.Options).Verify(messageCount * 10, null); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <SqLiteMessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } } }
public void Run() { 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); RunTest(queueName, 100, 10, logProvider, connectionInfo.ConnectionString, oCreation.Scope); LoggerShared.CheckForErrors(queueName); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <MessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } } }
public void Run() { 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) ) { var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); RunTest(queueName, 1000, 10, logProvider, oCreation.Scope); LoggerShared.CheckForErrors(queueName); new VerifyQueueData(queueName, oCreation.Options).Verify(1000 * 10, null); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName, ConnectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, 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); //create data var id = Guid.NewGuid(); var producer = new ProducerMethodShared(); if (linqMethodTypes == LinqMethodTypes.Compiled) { producer.RunTestCompiled <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, id, GenerateMethod.CreateRollBackCompiled, runtime, oCreation.Scope); } #if NETFULL else { producer.RunTestDynamic <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, id, GenerateMethod.CreateRollBackDynamic, runtime, oCreation.Scope); } #endif //process data var consumer = new ConsumerMethodAsyncRollBackShared(); consumer.RunConsumer <PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, workerCount, logProvider, timeOut, readerCount, queueSize, runtime, messageCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), id, "second(*%3)"); LoggerShared.CheckForErrors(queueName); new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(0, false, false); GenerateMethod.ClearRollback(id); } } finally { using ( var oCreation = queueCreator.GetQueueCreation <PostgreSqlMessageQueueCreation>(queueName, ConnectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } }
void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors, ILogger logProvider, int runTime, int messageCount, int timeOut, int readerCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, bool enableChaos, ICreationScope scope, string route, Action <QueueConsumerConfiguration> setQueueOptions = null) where TTransportInit : ITransportInit, new() { if (enableChaos) { timeOut *= 2; } var metricName = queueConnection.Queue; if (!string.IsNullOrEmpty(route)) { metricName = queueConnection.Queue + "|-|" + route; } using (var trace = SharedSetup.CreateTrace("consumer")) { 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, scope, trace.Source) ) { using ( var queue = creator .CreateConsumerQueueScheduler( queueConnection, Factory)) { SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, readerCount, heartBeatTime, heartBeatMonitorTime, updateTime, route); if (!string.IsNullOrWhiteSpace(route)) { queue.Configuration.Routes.Add(route); } setQueueOptions?.Invoke(queue.Configuration); 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); } } } }
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, List <string> routes = null) where TTransportInit : ITransportInit, new() { 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) ) { 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); } } }