public void RunTest <TTransportInit, TMessage>(string queueName, string connectionString, bool addInterceptors, int messageCount, ILogProvider logProvider, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <string, string, QueueProducerConfiguration, long, string, ICreationScope> verify, bool sendViaBatch, List <string> routes1, List <string> routes2, int runTime, int timeOut, int readerCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, ICreationScope scope, string updateTime, bool enableChaos) where TTransportInit : ITransportInit, new() where TMessage : class { //add data with routes - generate data per route passed in Parallel.ForEach(routes1, route => { RunTest <TTransportInit, TMessage>(queueName, connectionString, addInterceptors, messageCount, logProvider, generateData, verify, sendViaBatch, route, scope, false); }); Parallel.ForEach(routes2, route => { RunTest <TTransportInit, TMessage>(queueName, connectionString, addInterceptors, messageCount, logProvider, generateData, verify, sendViaBatch, route, scope, false); }); //run a consumer for each route using (var schedulerCreator = new SchedulerContainer()) { var taskScheduler = schedulerCreator.CreateTaskScheduler(); taskScheduler.Configuration.MaximumThreads = routes1.Count + routes2.Count; taskScheduler.Start(); var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler); //spin up and process each route var running = new List <List <string> > { routes1, routes2 }; Parallel.ForEach(running, route => { var consumer = new ConsumerAsyncShared <TMessage> { Factory = taskFactory }; consumer.RunConsumer <TTransportInit>(queueName, connectionString, addInterceptors, logProvider, runTime, messageCount, timeOut, readerCount, heartBeatTime, heartBeatMonitorTime, updateTime, enableChaos, route); }); } }
public void RunTest <TTransportInit, TMessage>(QueueConnection queueConnection, bool addInterceptors, int messageCount, ILogger logProvider, Func <QueueProducerConfiguration, int, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, int, ICreationScope> verify, bool sendViaBatch, List <int> userValues, int runTime, int timeOut, int readerCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, ICreationScope scope, string updateTime, bool enableChaos, Action <QueueConsumerConfiguration, int> setQueueOptions) where TTransportInit : ITransportInit, new() where TMessage : class { //add data with user column Parallel.ForEach(userValues, userColumn => { RunTest <TTransportInit, TMessage>(queueConnection, addInterceptors, messageCount, logProvider, generateData, verify, sendViaBatch, userColumn, scope, false); }); //run a consumer for each data value using (var schedulerCreator = new SchedulerContainer()) { var taskScheduler = schedulerCreator.CreateTaskScheduler(); taskScheduler.Configuration.MaximumThreads = userValues.Count * 2; taskScheduler.Start(); var taskFactory = schedulerCreator.CreateTaskFactory(taskScheduler); //spin up and process each value Parallel.ForEach(userValues, userColumn => { var consumer = new ConsumerAsyncShared <TMessage> { Factory = taskFactory }; consumer.RunConsumer <TTransportInit>(queueConnection, addInterceptors, logProvider, runTime, messageCount, timeOut, readerCount, heartBeatTime, heartBeatMonitorTime, updateTime, enableChaos, scope, null, (g) => setQueueOptions(g, userColumn)); }); } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, bool useTransactions, int messageType) { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); using (var queueCreator = new QueueCreationContainer <SqlServerMessageQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { using ( var oCreation = queueCreator.GetQueueCreation <SqlServerMessageQueueCreation>(queueName, ConnectionInfo.ConnectionString) ) { oCreation.Options.EnableDelayedProcessing = true; oCreation.Options.EnableHeartBeat = !useTransactions; oCreation.Options.EnableHoldTransactionUntilMessageCommitted = useTransactions; oCreation.Options.EnableStatus = !useTransactions; oCreation.Options.EnableStatusTable = true; var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); if (messageType == 1) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <SqlServerMessageQueueInit, FakeMessage>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessage> { Factory = Factory }; consumer.RunConsumer <SqlServerMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)"); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <SqlServerMessageQueueInit, FakeMessageA>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessageA> { Factory = Factory }; consumer.RunConsumer <SqlServerMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)"); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <SqlServerMessageQueueInit, FakeMessageB>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessageB> { Factory = Factory }; consumer.RunConsumer <SqlServerMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%10)"); } new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(0, false, false); } } finally { schedulerContainer?.Dispose(); using ( var oCreation = queueCreator.GetQueueCreation <SqlServerMessageQueueCreation>(queueName, ConnectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } }
public async Task Run <TTransportInit, TTransportCreate>( QueueConnection queueConnection, int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, int messageType, bool enableChaos, Action <TTransportCreate> setOptions, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount) where TTransportInit : ITransportInit, new() where TTransportCreate : class, IQueueCreation { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } 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); var time = runtime * 1000 / 2; try { setOptions(oCreation); var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); scope = oCreation.Scope; if (messageType == 1) { var producer = new ProducerAsyncShared(); await producer.RunTestAsync <TTransportInit, FakeMessage>(queueConnection, false, messageCount, logProvider, generateData, verify, false, scope, false).ConfigureAwait(false); Thread.Sleep(time); var consumer = new ConsumerAsyncShared <FakeMessage> { Factory = Factory }; consumer.RunConsumer <TTransportInit>(queueConnection, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", enableChaos, scope, null); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); await producer.RunTestAsync <TTransportInit, FakeMessageA>(queueConnection, false, messageCount, logProvider, generateData, verify, false, scope, false).ConfigureAwait(false); Thread.Sleep(time); var consumer = new ConsumerAsyncShared <FakeMessageA> { Factory = Factory }; consumer.RunConsumer <TTransportInit>(queueConnection, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", enableChaos, scope, null); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); await producer.RunTestAsync <TTransportInit, FakeMessageB>(queueConnection, false, messageCount, logProvider, generateData, verify, false, oCreation.Scope, false).ConfigureAwait(false); Thread.Sleep(time); var consumer = new ConsumerAsyncShared <FakeMessageB> { Factory = Factory }; consumer.RunConsumer <TTransportInit>(queueConnection, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", enableChaos, scope, null); } verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, 0, false, false); } finally { schedulerContainer?.Dispose(); oCreation?.RemoveQueue(); oCreation?.Dispose(); scope?.Dispose(); } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, int messageType, ConnectionInfoTypes type) { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); var connectionString = new ConnectionInfo(type).ConnectionString; using (var queueCreator = new QueueCreationContainer <RedisQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { if (messageType == 1) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <RedisQueueInit, FakeMessage>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, null).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared <FakeMessage> { Factory = Factory }; consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)"); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <RedisQueueInit, FakeMessageA>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, null).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared <FakeMessageA> { Factory = Factory }; consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)"); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <RedisQueueInit, FakeMessageB>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, null).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared <FakeMessageB> { Factory = Factory }; consumer.RunConsumer <RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), "second(*%3)"); } using (var count = new VerifyQueueRecordCount(queueName, connectionString)) { count.Verify(0, false, -1); } } finally { schedulerContainer?.Dispose(); using ( var oCreation = queueCreator.GetQueueCreation <RedisQueueCreation>(queueName, connectionString) ) { oCreation.RemoveQueue(); } } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, bool useTransactions, int messageType) { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } 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.EnableHoldTransactionUntilMessageCommited = useTransactions; oCreation.Options.EnableStatus = !useTransactions; oCreation.Options.EnableStatusTable = true; var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); if (messageType == 1) { var producer = new ProducerAsyncShared(); producer.RunTest<PostgreSqlMessageQueueInit, FakeMessage>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared<FakeMessage> {Factory = Factory}; consumer.RunConsumer<PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); producer.RunTest<PostgreSqlMessageQueueInit, FakeMessageA>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared<FakeMessageA> {Factory = Factory}; consumer.RunConsumer<PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); producer.RunTest<PostgreSqlMessageQueueInit, FakeMessageB>(queueName, ConnectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared<FakeMessageB> {Factory = Factory}; consumer.RunConsumer<PostgreSqlMessageQueueInit>(queueName, ConnectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } new VerifyQueueRecordCount(queueName, oCreation.Options).Verify(0, false, false); } } finally { schedulerContainer?.Dispose(); 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, int messageType, ConnectionInfoTypes type) { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); var connectionString = new ConnectionInfo(type).ConnectionString; using (var queueCreator = new QueueCreationContainer<RedisQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { if (messageType == 1) { var producer = new ProducerAsyncShared(); producer.RunTest<RedisQueueInit, FakeMessage>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared<FakeMessage> {Factory = Factory}; consumer.RunConsumer<RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); producer.RunTest<RedisQueueInit, FakeMessageA>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared<FakeMessageA> {Factory = Factory}; consumer.RunConsumer<RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); producer.RunTest<RedisQueueInit, FakeMessageB>(queueName, connectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false).Wait(timeOut * 1000 / 2); var consumer = new ConsumerAsyncShared<FakeMessageB> {Factory = Factory}; consumer.RunConsumer<RedisQueueInit>(queueName, connectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12)); } using (var count = new VerifyQueueRecordCount(queueName, connectionString)) { count.Verify(0, false, -1); } } finally { schedulerContainer?.Dispose(); using ( var oCreation = queueCreator.GetQueueCreation<RedisQueueCreation>(queueName, connectionString) ) { oCreation.RemoveQueue(); } } } }
public void Run(int messageCount, int runtime, int timeOut, int workerCount, int readerCount, int queueSize, int messageType) { SchedulerContainer schedulerContainer = null; if (Factory == null) { Factory = CreateFactory(workerCount, queueSize, out schedulerContainer); } using (var connectionInfo = new IntegrationConnectionInfo()) { var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); using (var queueCreator = new QueueCreationContainer <MemoryMessageQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { try { using ( var oCreation = queueCreator.GetQueueCreation <MessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); if (messageType == 1) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <MemoryMessageQueueInit, FakeMessage>(queueName, connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessage> { Factory = Factory }; consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", false); } else if (messageType == 2) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <MemoryMessageQueueInit, FakeMessageA>(queueName, connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessageA> { Factory = Factory }; consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", false); } else if (messageType == 3) { var producer = new ProducerAsyncShared(); producer.RunTestAsync <MemoryMessageQueueInit, FakeMessageB>(queueName, connectionInfo.ConnectionString, false, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, oCreation.Scope, false).Wait(timeOut / 2 * 1000); var consumer = new ConsumerAsyncShared <FakeMessageB> { Factory = Factory }; consumer.RunConsumer <MemoryMessageQueueInit>(queueName, connectionInfo.ConnectionString, false, logProvider, runtime, messageCount, timeOut, readerCount, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", false); } new VerifyQueueRecordCount().Verify(oCreation.Scope, 0, true); } } finally { schedulerContainer?.Dispose(); using ( var oCreation = queueCreator.GetQueueCreation <MessageQueueCreation>(queueName, connectionInfo.ConnectionString) ) { oCreation.RemoveQueue(); } } } } }