public async Task Test_CanStartStop() { TaskProcessingOptions processingOpts = TestOptions.GetDefaultTaskProcessingOptions(); Mock <ITaskBuffer> bufferMock = new Mock <ITaskBuffer>(MockBehavior.Loose); Mock <ITaskExecutorRegistry> executorRegistryMock = new Mock <ITaskExecutorRegistry>(MockBehavior.Loose); Mock <IExecutionPerformanceMonitor> executionPerformanceMonitorMock = new Mock <IExecutionPerformanceMonitor>(MockBehavior.Loose); Mock <ITaskQueueProducer> producerMock = new Mock <ITaskQueueProducer>(MockBehavior.Loose); Mock <ITaskResultQueue> resultQueueMock = new Mock <ITaskResultQueue>(MockBehavior.Loose); using (StandardTaskWorker worker = new StandardTaskWorker(processingOpts, bufferMock.Object, executorRegistryMock.Object, executionPerformanceMonitorMock.Object, producerMock.Object, resultQueueMock.Object)) { await worker.StartAsync(); Assert.IsTrue(worker.IsRunning); await worker.StopAync(); Assert.IsFalse(worker.IsRunning); } }
public async Task Test_CanPoll(int bufferCapacity, int numberOfTasks) { TaskProcessingOptions processingOpts = TestOptions.GetDefaultTaskProcessingOptions(); using (StandardTaskBuffer taskBuffer = new StandardTaskBuffer(bufferCapacity)) using (MockTaskQueueConsumer taskQueue = new MockTaskQueueConsumer(numberOfTasks, new UtcNowTimestampProvider())) using (StandardTaskPoller poller = new StandardTaskPoller(processingOpts, taskQueue, taskBuffer)) { TestBufferConsumer consumer = new TestBufferConsumer(taskBuffer); await poller.StartAsync(); //Poller is filling up the buffer. //We need to check the buffer to see whether // the poller produced the appropriate data consumer.ConsumeBuffer(); taskQueue.WaitForQueueToBeDepleted(); await poller.StopAync(); consumer.WaitForBufferToBeConsumed(); Assert.IsFalse(taskBuffer.HasTasks); Assert.IsTrue(taskBuffer.IsCompleted); consumer.AssertMatchesProducedTasks(taskQueue .DequeuedTasksHistory); } }
public WorkingTests() { mTimestampProvider = new UtcNowTimestampProvider(); mTaskProcessingOptions = TestOptions .GetDefaultTaskProcessingOptions(); mProducerAndResultOptions = TestOptions .GetDefaultTaskQueueProducerAndResultOptions(CommonConnectionString); mTaskQueueConsumerOptions = TestOptions .GetDefaultTaskQueueConsumerOptions(BaseConsumerConnectionString); mPostgreSqlExecutionPerformanceMonitorWriterOptions = TestOptions .GetDefaultPostgreSqlExecutionPerformanceMonitorWriterOptions(CommonConnectionString); mOperations = new PostgreSqlTaskQueueDbOperations(CommonConnectionString, TestOptions.DefaultMapping); }
public async Task Test_CanStartStop() { TaskProcessingOptions processingOpts = TestOptions.GetDefaultTaskProcessingOptions(); using (StandardTaskBuffer taskBuffer = new StandardTaskBuffer(100)) using (MockTaskQueueConsumer taskQueue = new MockTaskQueueConsumer(0, new UtcNowTimestampProvider())) using (StandardTaskPoller poller = new StandardTaskPoller(processingOpts, taskQueue, taskBuffer)) { await poller.StartAsync(); Assert.IsTrue(poller.IsRunning); Assert.IsTrue(taskQueue.IsReceivingNewTaskUpdates); await poller.StopAync(); Assert.IsFalse(poller.IsRunning); Assert.IsFalse(taskQueue.IsReceivingNewTaskUpdates); } }
public async Task Test_CanWork(int bufferCapacity, int workerCount, int numberOfTasks) { ConcurrentBag <IQueuedTaskToken> processedTaskTokens = new ConcurrentBag <IQueuedTaskToken>(); TaskProcessingOptions processingOpts = TestOptions.GetDefaultTaskProcessingOptions(); Mock <IExecutionPerformanceMonitor> executionPerformanceMonitorMock = new Mock <IExecutionPerformanceMonitor>(); Mock <ITaskQueueProducer> producerMock = new Mock <ITaskQueueProducer>(MockBehavior.Loose); Mock <ITaskResultQueue> resultQueueMock = new Mock <ITaskResultQueue>(MockBehavior.Loose); List <StandardTaskWorker> workers = new List <StandardTaskWorker>(); executionPerformanceMonitorMock.Setup(m => m.ReportExecutionTimeAsync( It.IsIn(mPayloadTypes.Select(t => t.FullName).ToArray()), It.IsAny <long>(), It.IsAny <int>())); resultQueueMock.Setup(rq => rq.PostResultAsync(It.IsAny <IQueuedTaskToken>())) .Callback <IQueuedTaskToken>(t => processedTaskTokens.Add(t)); //TODO: must also test that, for failed tasks that can be re-posted, // the tasks is actually reposted using (StandardTaskBuffer taskBuffer = new StandardTaskBuffer(bufferCapacity)) { TestBufferProducer producer = new TestBufferProducer(taskBuffer, mPayloadTypes); for (int i = 0; i < workerCount; i++) { workers.Add(new StandardTaskWorker(processingOpts, taskBuffer, CreateTaskExecutorRegistry(), executionPerformanceMonitorMock.Object, producerMock.Object, resultQueueMock.Object)); } foreach (StandardTaskWorker w in workers) { await w.StartAsync(); } await producer.ProduceTasksAsync(numberOfTasks); while (!taskBuffer.IsCompleted) { await Task.Delay(50); } await Task.Delay(250); foreach (StandardTaskWorker w in workers) { await w.StopAync(); } foreach (StandardTaskWorker w in workers) { w.Dispose(); } producer.AssertMatchesProcessedTasks(processedTaskTokens); executionPerformanceMonitorMock.VerifyAll(); } }