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(); } } }
/// <summary>Initializes a new instance of the <see cref="LiteDbMessageQueueCreation"/> class.</summary> /// <param name="connectionInfo">The connection information.</param> /// <param name="queryTableExists">The query table exists.</param> /// <param name="options">The options.</param> /// <param name="createSchema">The create schema.</param> /// <param name="createCommand">The create command.</param> /// <param name="deleteCommand">The delete command.</param> /// <param name="creationScope">The creation scope.</param> /// <param name="connectionManager">DB Connection manager</param> public LiteDbMessageQueueCreation(IConnectionInformation connectionInfo, IQueryHandler <GetTableExistsQuery, bool> queryTableExists, ILiteDbMessageQueueTransportOptionsFactory options, LiteDbMessageQueueSchema createSchema, ICommandHandlerWithOutput <CreateQueueTablesAndSaveConfigurationCommand <ITable>, QueueCreationResult> createCommand, ICommandHandlerWithOutput <DeleteQueueTablesCommand, QueueRemoveResult> deleteCommand, ICreationScope creationScope, LiteDbConnectionManager connectionManager ) { Guard.NotNull(() => options, options); Guard.NotNull(() => createSchema, createSchema); Guard.NotNull(() => queryTableExists, queryTableExists); Guard.NotNull(() => createCommand, createCommand); Guard.NotNull(() => deleteCommand, deleteCommand); Guard.NotNull(() => creationScope, creationScope); Guard.NotNull(() => connectionManager, connectionManager); _options = new Lazy <LiteDbMessageQueueTransportOptions>(options.Create); _createSchema = createSchema; _queryTableExists = queryTableExists; _createCommand = createCommand; _deleteCommand = deleteCommand; ConnectionInfo = connectionInfo; Scope = creationScope; _connectionManager = connectionManager; }
private void ValidateErrorCounts(QueueConnection queueConnection, int arg3, ICreationScope arg4) { using (var error = new VerifyErrorCounts(queueConnection.Queue, queueConnection.Connection)) { error.Verify(arg3, 2); } }
public VerifyQueueData(QueueConnection queueConnection, LiteDbMessageQueueTransportOptions options, ICreationScope scope) { _options = options; _connection = new LiteDbConnectionInformation(queueConnection); _tableNameHelper = new TableNameHelper(_connection); _scope = scope; }
private void RunTest <TTransportInit, TMessage>(QueueConnection queueConnection, bool addInterceptors, long messageCount, ILogger logProvider, Func <QueueProducerConfiguration, int, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, int, ICreationScope> verify, bool sendViaBatch, int userValue, ICreationScope scope, bool enableChaos) where TTransportInit : ITransportInit, new() where TMessage : class { //generate the test data var producer = new ProducerShared(); producer.RunTest <TTransportInit, TMessage>(queueConnection, addInterceptors, messageCount, logProvider, g => generateData(g, userValue), (a, b, c, d) => verify(a, b, c, userValue, scope), sendViaBatch, false, scope, enableChaos); }
public VerifyQueueRecordCount(string queueName, string connectionString, LiteDbMessageQueueTransportOptions options, ICreationScope scope) { _options = options; _connection = new LiteDbConnectionInformation(new QueueConnection(queueName, connectionString)); _tableNameHelper = new TableNameHelper(_connection); _scope = scope; }
public static void SetError(QueueConnection queueConnection, ICreationScope scope) { var connection = new LiteDbConnectionInformation(queueConnection); var helper = new TableNameHelper(connection); var connScope = scope.GetDisposable <LiteDbConnectionManager>(); if (connScope == null) { using (var conn = new LiteDatabase(connection.ConnectionString)) { var col = conn.GetCollection <Schema.StatusTable>(helper.StatusName); var results = col.Query() .ToList(); foreach (var result in results) { result.Status = QueueStatuses.Error; col.Update(result); } } } else { using (var conn = connScope.GetDatabase()) { var col = conn.Database.GetCollection <Schema.StatusTable>(helper.StatusName); var results = col.Query() .ToList(); foreach (var result in results) { result.Status = QueueStatuses.Error; col.Update(result); } } } }
public async Task RunTestAsync <TTransportInit, TMessage>(QueueConnection queueConnection, bool addInterceptors, long messageCount, ILogger logProvider, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch, ICreationScope scope, bool enableChaos) where TTransportInit : ITransportInit, new() where TMessage : class { 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) ) { //create the queue using (var queue = creator .CreateProducer <TMessage>(queueConnection)) { await RunProducerAsync(queue, queueConnection, messageCount, generateData, verify, sendViaBatch, scope).ConfigureAwait(false); } VerifyMetrics.VerifyProducedAsyncCount(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount); } } }
private void RunTest <TTransportInit, TMessage>(string queueName, string connectionString, bool addInterceptors, long messageCount, ILogProvider logProvider, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <string, string, QueueProducerConfiguration, long, string, ICreationScope> verify, bool sendViaBatch, string route, ICreationScope scope, bool enableChaos) where TTransportInit : ITransportInit, new() where TMessage : class { //generate the test data var producer = new ProducerShared(); producer.RunTest <TTransportInit, TMessage>(queueName, connectionString, addInterceptors, messageCount, logProvider, g => GenerateDataWithRoute(generateData, g, route), (a, b, c, d, e) => VerifyRoutes(verify, a, b, c, d, route, scope), sendViaBatch, false, scope, enableChaos); }
private void ValidateErrorCounts(QueueConnection queueConnection, int arg3, ICreationScope arg4) { //poison messages are moved to the error queue right away //they don't update the tracking table, so specify 0 for the error count. //They still update the error table itself new VerifyErrorCounts(queueConnection.Queue).Verify(arg3, 0); }
public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors, int workerCount, ILogger logProvider, int timeOut, 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; } using ( var creator = SharedSetup.CreateCreator <TTransportInit>(addInterceptorConsumer, logProvider, metrics, true, 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.HandleFakeMessageNoOp(); }); 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, 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(); } } }
public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors, ILogger logProvider, int runTime, int messageCount, int workerCount, int timeOut, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, string route, bool enableChaos, ICreationScope scope) where TTransportInit : ITransportInit, new() { if (enableChaos) { timeOut *= 2; } using (var 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) ) { using ( var queue = creator.CreateConsumer(queueConnection)) { SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, workerCount, heartBeatTime, heartBeatMonitorTime, updateTime, route); queue.Configuration.MessageExpiration.Enabled = true; queue.Configuration.MessageExpiration.MonitorTime = TimeSpan.FromSeconds(8); var waitForFinish = new ManualResetEventSlim(false); waitForFinish.Reset(); //start looking for work queue.Start <TMessage>((message, notifications) => { MessageHandlingShared.HandleFakeMessages <TMessage>(null, runTime, processedCount, messageCount, waitForFinish); }); for (var i = 0; i < timeOut; i++) { if (VerifyMetrics.GetExpiredMessageCount(metrics.GetCurrentMetrics()) == messageCount) { break; } Thread.Sleep(1000); } } Assert.Equal(0, processedCount.ProcessedCount); VerifyMetrics.VerifyProcessedCount(queueConnection.Queue, metrics.GetCurrentMetrics(), 0); VerifyMetrics.VerifyExpiredMessageCount(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount); LoggerShared.CheckForErrors(queueConnection.Queue); } } }
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); } } } }
public void RunConsumer <TTransportInit>(QueueConnection queueConnection, bool addInterceptors, int workerCount, ILogger logProvider, int timeOut, int runTime, long messageCount, TimeSpan heartBeatTime, TimeSpan heartBeatMonitorTime, string updateTime, Guid id, 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.CreateMethodConsumer(queueConnection, x => x.RegisterNonScopedSingleton(scope))) { 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(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount); VerifyMetrics.VerifyRollBackCount(queueConnection.Queue, metrics.GetCurrentMetrics(), messageCount, 1, 0); LoggerShared.CheckForErrors(queueConnection.Queue); } } }
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); }); } }
private static void RegisterService(IContainer container, Logger log, ICreationScope scope) { Injectors.AddInjectors(new SerilogAdapter(log), SharedConfiguration.EnableTrace, SharedConfiguration.EnableMetrics, SharedConfiguration.EnableCompression, SharedConfiguration.EnableEncryption, "LiteDbProducerConsumer", container); //scope must be injected to share a direct or memory connection container.RegisterNonScopedSingleton(scope); }
private IConsumerMethodQueue CreateConsumerInternalThread(ICreationScope scope) { _badQueueContainer = SharedSetup.CreateCreator <TTransportInit>(_badQueueAdditions); var queue = _badQueueContainer.CreateMethodConsumer(_queueConnection, x => x.RegisterNonScopedSingleton(scope)); SharedSetup.SetupDefaultConsumerQueue(queue.Configuration, _workerCount, _heartBeatTime, _heartBeatMonitorTime, _updatetime, null); return(queue); }
public void Run <TTransportInit, TMessage, TTransportCreate>( QueueConnection queueConnection, int messageCount, int runtime, int timeOut, int workerCount, bool enableChaos, Action <TTransportCreate> setOptions, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, Action <QueueConnection, IBaseTransportOptions, ICreationScope, int, bool, bool> verifyQueueCount) 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; var producer = new ProducerShared(); producer.RunTest <TTransportInit, TMessage>(queueConnection, false, messageCount, logProvider, generateData, verify, false, scope, false); var consumer = new ConsumerShared <TMessage>(); consumer.RunConsumer <TTransportInit>(queueConnection, false, logProvider, runtime, messageCount, workerCount, timeOut, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(35), "second(*%10)", enableChaos, scope); verifyQueueCount(queueConnection, oCreation.BaseTransportOptions, scope, 0, false, false); } finally { oCreation?.RemoveQueue(); oCreation?.Dispose(); scope?.Dispose(); } } }
public void Run <TTransportInit, TTransportCreate>( QueueConnection queueConnection, int messageCount, LinqMethodTypes linqMethodTypes, bool interceptors, bool enableChaos, bool sendViaBatch, Action <TTransportCreate> setOptions, Func <QueueProducerConfiguration, AdditionalMessageData> generateData, Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify) where TTransportInit : ITransportInit, new() where TTransportCreate : class, IQueueCreation { var logProvider = LoggerShared.Create(queueConnection.Queue, GetType().Name); using (var queueCreator = new QueueCreationContainer <TTransportInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { ICreationScope scope = null; var oCreation = queueCreator.GetQueueCreation <TTransportCreate>(queueConnection); try { setOptions(oCreation); var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); scope = oCreation.Scope; var id = Guid.NewGuid(); var producer = new ProducerMethodShared(); if (linqMethodTypes == LinqMethodTypes.Compiled) { producer.RunTestCompiled <TTransportInit>(queueConnection, interceptors, messageCount, logProvider, generateData, verify, sendViaBatch, id, GenerateMethod.CreateCompiled, 0, oCreation.Scope, enableChaos); } else { producer.RunTestDynamic <TTransportInit>(queueConnection, interceptors, messageCount, logProvider, generateData, verify, sendViaBatch, id, GenerateMethod.CreateDynamic, 0, oCreation.Scope, enableChaos); } } finally { oCreation.RemoveQueue(); oCreation.Dispose(); scope?.Dispose(); } } }
private void ValidateNonFatalError(string queueName, string connectionString, Action <string, string, long, ICreationScope> verify, // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local long enqueued, Exception error, // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local long nonFatal, long inQueueCount, ICreationScope scope) { Assert.Equal(0, enqueued); error.Should().BeNull("no errors should occur"); Assert.Equal(1, nonFatal); verify(queueName, connectionString, inQueueCount, scope); }
public static void SetError(QueueConnection queueConnection, ICreationScope scope) { var connectionInfo = new BaseConnectionInformation(queueConnection); var conn = new RedisConnection(connectionInfo); var redisNames = new RedisNames(connectionInfo); var db = conn.Connection.GetDatabase(); var id = db.HashGet(redisNames.JobNames, "job1"); db.HashSet(redisNames.Status, id, "2"); }
public void Verify(ICreationScope scope, long messageCount, int errorCount) { var realScope = (CreationScope)scope; if (realScope.ContainedClears.TryPeek(out var dataStorage)) { var data = (IDataStorage)dataStorage; var errors = data.GetErrorCount(); Assert.Equal(messageCount, errors); } }
public static void SetError(string queueName, string connectionString, ICreationScope scope) { //no such thing as an error in the memory queue, as it's a FIFO queue with no rollbacks //delete the job instead var realScope = (CreationScope)scope; if (realScope.ContainedClears.TryPeek(out var dataStorage)) { var data = (IDataStorage)dataStorage; data.DeleteJob("job1"); } }
/// <summary> /// Initializes a new instance of the <see cref="MessageQueueCreation" /> class. /// </summary> /// <param name="connectionInfo">The connection information.</param> /// <param name="options">The options.</param> /// <param name="creationScope">The creation scope.</param> public MessageQueueCreation(IConnectionInformation connectionInfo, ITransportOptionsFactory options, ICreationScope creationScope) { Guard.NotNull(() => options, options); Guard.NotNull(() => creationScope, creationScope); Guard.NotNull(() => connectionInfo, connectionInfo); _options = new Lazy <TransportOptions>(options.Create); ConnectionInfo = connectionInfo; Scope = creationScope; }
public void Run(int messageCount, int runtime, int timeOut, int readerCount, int routeCount, bool enableChaos, IntegrationConnectionInfo.ConnectionTypes connectionType) { using (var connectionInfo = new IntegrationConnectionInfo(connectionType)) { var queueName = GenerateQueueName.Create(); var consumer = new DotNetWorkQueue.IntegrationTests.Shared.Route.Implementation.RouteMultiTests(); consumer.Run <LiteDbMessageQueueInit, LiteDbMessageQueueCreation>(new QueueConnection(queueName, connectionInfo.ConnectionString), messageCount, runtime, timeOut, readerCount, routeCount, enableChaos, x => { Helpers.SetOptions(x, false, false, true, true); }, Helpers.GenerateData, Helpers.Verify, Helpers.VerifyQueueCount); } using (var connectionInfo = new IntegrationConnectionInfo(connectionType)) { var queueName = GenerateQueueName.Create(); var logProvider = LoggerShared.Create(queueName, GetType().Name); using (var queueCreator = new QueueCreationContainer <LiteDbMessageQueueInit>( serviceRegister => serviceRegister.Register(() => logProvider, LifeStyles.Singleton))) { var queueConnection = new DotNetWorkQueue.Configuration.QueueConnection(queueName, connectionInfo.ConnectionString); ICreationScope scope = null; var oCreation = queueCreator.GetQueueCreation <LiteDbMessageQueueCreation>(queueConnection); try { oCreation.Options.EnableStatusTable = true; oCreation.Options.EnableRoute = true; var result = oCreation.CreateQueue(); Assert.True(result.Success, result.ErrorMessage); scope = oCreation.Scope; var routeTest = new RouteMultiTestsShared(); routeTest.RunTest <LiteDbMessageQueueInit, FakeMessageA>(queueConnection, true, messageCount, logProvider, Helpers.GenerateData, Helpers.Verify, false, GenerateRoutes(routeCount, 1), GenerateRoutes(routeCount, routeCount + 1), runtime, timeOut, readerCount, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(12), oCreation.Scope, "second(*%3)", enableChaos); new VerifyQueueRecordCount(queueName, connectionInfo.ConnectionString, oCreation.Options, scope) .Verify(0, false, false); } finally { oCreation?.RemoveQueue(); oCreation?.Dispose(); scope?.Dispose(); } } } }
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 static void SetError(QueueConnection queueConnection, ICreationScope scope) { var connection = new SqliteConnectionInformation(queueConnection, new DbDataSource()); var helper = new TableNameHelper(connection); using (var conn = new SQLiteConnection(queueConnection.Connection)) { conn.Open(); using (var command = conn.CreateCommand()) { command.CommandText = $"update {helper.StatusName} set status = 2"; command.ExecuteNonQuery(); } } }
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, ICreationScope scope, bool enableChaos) where TTransportInit : ITransportInit, new() where TMessage : class { RunTest <TTransportInit, TMessage>(queueConnection, addInterceptors, messageCount, logProvider, generateData, verify, sendViaBatch, true, scope, enableChaos); }
/// <summary> /// Initializes a new instance of the <see cref="RedisQueueCreation" /> class. /// </summary> /// <param name="connectionInfo">The connection information.</param> /// <param name="redisConnection">The redis connection.</param> /// <param name="redisNames">The redis names.</param> /// <param name="creationScope">The creation scope.</param> public RedisQueueCreation(IConnectionInformation connectionInfo, IRedisConnection redisConnection, RedisNames redisNames, ICreationScope creationScope) { Guard.NotNull(() => connectionInfo, connectionInfo); Guard.NotNull(() => redisConnection, redisConnection); Guard.NotNull(() => redisNames, redisNames); Guard.NotNull(() => creationScope, creationScope); _redisConnection = redisConnection; _redisNames = redisNames; ConnectionInfo = connectionInfo; Scope = creationScope; }
/// <summary> /// Initializes a new instance of the <see cref="SqlServerMessageQueueCreation" /> class. /// </summary> /// <param name="connectionInfo">The connection information.</param> /// <param name="queryTableExists">The query table exists.</param> /// <param name="options">The options.</param> /// <param name="createSchema">The create schema.</param> /// <param name="createCommand">The create command.</param> /// <param name="deleteCommand">The delete command.</param> /// <param name="creationScope">The creation scope.</param> public SqlServerMessageQueueCreation(IConnectionInformation connectionInfo, IQueryHandler<GetTableExistsQuery, bool> queryTableExists, ISqlServerMessageQueueTransportOptionsFactory options, SqlServerMessageQueueSchema createSchema, ICommandHandlerWithOutput<CreateQueueTablesAndSaveConfigurationCommand, QueueCreationResult> createCommand, ICommandHandlerWithOutput<DeleteQueueTablesCommand, QueueRemoveResult> deleteCommand, ICreationScope creationScope ) { Guard.NotNull(() => options, options); Guard.NotNull(() => createSchema, createSchema); Guard.NotNull(() => queryTableExists, queryTableExists); Guard.NotNull(() => createCommand, createCommand); Guard.NotNull(() => deleteCommand, deleteCommand); Guard.NotNull(() => creationScope, creationScope); _options = new Lazy<SqlServerMessageQueueTransportOptions>(options.Create); _createSchema = createSchema; _queryTableExists = queryTableExists; _createCommand = createCommand; _deleteCommand = deleteCommand; ConnectionInfo = connectionInfo; Scope = creationScope; }