Example #1
0
        public void Dequeue_with_events_traces_event_on_error()
        {
            InputQueueStub <string> inner       = new InputQueueStub <string>();
            QueueEventSource        eventSource = QueueEventSource.Instance;
            Guid id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
            InputQueueWithEvents <string> queue = new InputQueueWithEvents <string>(inner, id, eventSource);

            using (QueueEventListener listener = new QueueEventListener(eventSource, EventLevel.Informational, EventKeywords.None))
            {
                Task <string> task = queue.DequeueAsync();

                Assert.False(task.IsCompleted);

                listener.VerifyEvent(QueueEventId.Dequeue, EventLevel.Informational, EventKeywords.None, id);
                listener.Events.Clear();

                InvalidTimeZoneException expectedException = new InvalidTimeZoneException("Expected.");
                inner.PendingDequeue.SetException(expectedException);

                Assert.Equal(TaskStatus.Faulted, task.Status);
                Assert.NotNull(task.Exception);
                AggregateException ae = task.Exception;
                Assert.Equal(1, ae.InnerExceptions.Count);
                Assert.Same(expectedException, ae.InnerExceptions[0]);

                listener.VerifyEvent(QueueEventId.DequeueCompleted, EventLevel.Informational, EventKeywords.None, id);
            }
        }
Example #2
0
        public void Dispose_with_events_traces_event()
        {
            InputQueueStub <string> inner       = new InputQueueStub <string>();
            QueueEventSource        eventSource = QueueEventSource.Instance;
            Guid id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
            InputQueueWithEvents <string> queue = new InputQueueWithEvents <string>(inner, id, eventSource);

            using (QueueEventListener listener = new QueueEventListener(eventSource, EventLevel.Informational, EventKeywords.None))
            {
                queue.Dispose();

                Assert.True(inner.Disposed);
                listener.VerifyEvent(QueueEventId.QueueDispose, EventLevel.Informational, EventKeywords.None, id);
            }
        }
Example #3
0
        private static void Main(string[] args)
        {
            IInputQueue<int> queue = new InputQueueWithEvents<int>(new InputQueue<int>(), Guid.NewGuid(), QueueEventSource.Instance);
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                Task enqueueTask = PrintException(EnqueueLoopAsync(queue, cts.Token));
                Task dequeueTask = PrintException(DequeueLoopAsync(queue, cts.Token));

                Console.WriteLine("Press ENTER to cancel.");
                Console.ReadLine();
                cts.Cancel();
                queue.Dispose();

                Task.WaitAll(enqueueTask, dequeueTask);
            }
        }
Example #4
0
        public void Enqueue_with_events_traces_event()
        {
            InputQueueStub <string> inner       = new InputQueueStub <string>();
            QueueEventSource        eventSource = QueueEventSource.Instance;
            Guid id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
            InputQueueWithEvents <string> queue = new InputQueueWithEvents <string>(inner, id, eventSource);

            using (QueueEventListener listener = new QueueEventListener(eventSource, EventLevel.Informational, EventKeywords.None))
            {
                inner.Enqueued += delegate(object sender, EventArgs e)
                {
                    listener.VerifyEvent(QueueEventId.Enqueue, EventLevel.Informational, EventKeywords.None, id);
                    listener.Events.Clear();
                };

                queue.Enqueue("a");

                Assert.Equal("a", inner.Item);
                listener.VerifyEvent(QueueEventId.EnqueueCompleted, EventLevel.Informational, EventKeywords.None, id);
            }
        }
Example #5
0
        public void Dequeue_with_events_traces_event()
        {
            InputQueueStub <string> inner       = new InputQueueStub <string>();
            QueueEventSource        eventSource = QueueEventSource.Instance;
            Guid id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
            InputQueueWithEvents <string> queue = new InputQueueWithEvents <string>(inner, id, eventSource);

            using (QueueEventListener listener = new QueueEventListener(eventSource, EventLevel.Informational, EventKeywords.None))
            {
                Task <string> task = queue.DequeueAsync();

                Assert.False(task.IsCompleted);

                listener.VerifyEvent(QueueEventId.Dequeue, EventLevel.Informational, EventKeywords.None, id);
                listener.Events.Clear();

                inner.PendingDequeue.SetResult("a");

                Assert.Equal(TaskStatus.RanToCompletion, task.Status);
                Assert.Equal("a", task.Result);
                listener.VerifyEvent(QueueEventId.DequeueCompleted, EventLevel.Informational, EventKeywords.None, id);
            }
        }
Example #6
0
        public void Enqueue_with_events_traces_event_on_error()
        {
            InputQueueStub <string> inner       = new InputQueueStub <string>();
            QueueEventSource        eventSource = QueueEventSource.Instance;
            Guid id = new Guid(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
            InputQueueWithEvents <string> queue = new InputQueueWithEvents <string>(inner, id, eventSource);

            using (QueueEventListener listener = new QueueEventListener(eventSource, EventLevel.Informational, EventKeywords.None))
            {
                InvalidProgramException expectedException = new InvalidProgramException("Expected.");
                inner.Enqueued += delegate(object sender, EventArgs e)
                {
                    listener.VerifyEvent(QueueEventId.Enqueue, EventLevel.Informational, EventKeywords.None, id);
                    listener.Events.Clear();
                    throw expectedException;
                };

                InvalidProgramException ipe = Assert.Throws <InvalidProgramException>(() => queue.Enqueue("a"));
                Assert.Same(expectedException, ipe);

                listener.VerifyEvent(QueueEventId.EnqueueCompleted, EventLevel.Informational, EventKeywords.None, id);
            }
        }