Beispiel #1
0
        public void OperationQueueTest_OperationStreamGetterIsInvokedOncePerDrain()
        {
            var list = new OperationList();

            list.AddOperation(null);

            int invokeCount = 0;
            Func <IOperationStream> streamGetter = () =>
            {
                invokeCount++;
                return(list);
            };

            var queue = new OperationFetcher.OperationQueue(streamGetter, new OperationProcessorInfo
            {
                Callback = new TrackingOperationProcessor().Process
            });

            var task1 = queue.DrainAsync();

            Assert.AreEqual(1, invokeCount);

            var task2 = queue.DrainAsync();

            Assert.AreEqual(2, invokeCount);
        }
Beispiel #2
0
        public void OperationQueueTest_ParallelDrain()
        {
            var operations = new List <IOperation> {
                new OperationStub(), new OperationStub(), null
            };

            var opList = new OperationList();

            foreach (var item in operations)
            {
                opList.AddOperation(item);
            }

            var processor = new TrackingOperationProcessor();

            var opQueue = new OperationFetcher.OperationQueue(() => opList, new OperationProcessorInfo
            {
                SupportsConcurrentProcessing = true,
                Callback = processor.Process
            });

            var task = opQueue.DrainAsync();

            for (int i = 0; i < operations.Count; i++)
            {
                // we are processing asynchronously
                // tell the list to provide an operation to the queue
                opList.CompleteOperation();

                if (i == operations.Count - 1)
                {
                    // the last null is not received
                    continue;
                }

                // the operation has been sent to the callback
                // the callback has not completed the task
                // the queue will continue (this loop will run)
                Assert.IsTrue(MiscUtility.WaitUntil(() => processor.GetOperations().Count == i + 1, TimeSpan.FromSeconds(1), 50));
                Assert.AreSame(operations[i], processor.GetOperations()[i].Item2);
            }

            // the task should be complete
            task.AssertWaitCompletes(500);
        }
Beispiel #3
0
        public void OperationQueueTest_DrainTaskIsCompletedWhenNullOperationIsReceived()
        {
            var opList = new OperationList();

            opList.AddOperation(null);

            var processor = new TrackingOperationProcessor();

            var opQueue = new OperationFetcher.OperationQueue(() => opList, new OperationProcessorInfo
            {
                SupportsConcurrentProcessing = false,
                Callback = processor.Process
            });

            var task = opQueue.DrainAsync();

            opList.CompleteOperation();

            // the task should be complete
            task.AssertWaitCompletes(500);
        }
Beispiel #4
0
        public void OperationQueueTest_FailingOperationStreamGetterReturnsException()
        {
            var ex = new InvalidOperationException();

            Func <IOperationStream> streamGetter = () => { throw ex; };

            var queue = new OperationFetcher.OperationQueue(streamGetter, new OperationProcessorInfo
            {
                Callback = new TrackingOperationProcessor().Process
            });

            var task = queue.DrainAsync();

            try
            {
                task.Wait();
                Assert.Fail("expceted ex");
            }
            catch (AggregateException aex)
            {
                Assert.AreSame(ex, aex.InnerException);
            }
        }
Beispiel #5
0
        private void ExceptionFromOperationFetchingIsThrownTestHelper(ThrowingOperationList list)
        {
            var ex = new InvalidOperationException();

            list.ExceptionToThrow = ex;

            var queue = new OperationFetcher.OperationQueue(() => list, new OperationProcessorInfo
            {
                Callback = new TrackingOperationProcessor().Process
            });

            var task = queue.DrainAsync();

            try
            {
                task.Wait();
                Assert.Fail("expceted ex");
            }
            catch (AggregateException aex)
            {
                Assert.AreSame(ex, aex.InnerException);
            }
        }