示例#1
0
        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);
                    }
        }
示例#2
0
        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);
                    }
        }