Пример #1
0
        public void ErrorOnSendBuffers()
        {
            int x     = 0;
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Open();
            queue.Enqueue(_ => { throw new InvalidOperationException(); }, null);
            queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                          null);

            queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                          null);

            Assert.Equal(0, x);
        }
Пример #2
0
        public void OpenAfterErrorRunsQueue()
        {
            int x     = 0;
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Open();
            queue.Enqueue(_ => { throw new InvalidOperationException(); }, null);
            queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                          null);

            var task = queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                                     null);

            queue.Open();

            task.Wait();

            Assert.Equal(2, x);
        }
Пример #3
0
        public void SendsBeforeBufferingShouldBeCaptured()
        {
            int x     = 0;
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                          null);

            queue.SetError(new Exception());

            Task task = queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                                      null);

            queue.Open();

            task.Wait();

            Assert.Equal(2, x);
        }
Пример #4
0
        public void ErrorOnSendThrowsNextTime()
        {
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration());

            queue.Open();
            queue.Enqueue(_ => { throw new InvalidOperationException(); }, null);
            Assert.Throws <InvalidOperationException>(() => queue.Enqueue(_ => TaskAsyncHelper.Empty, null));
        }
Пример #5
0
        public void SendAfterCloseThenOpenRemainsClosed()
        {
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Open();
            queue.Enqueue(_ => Task.Delay(50), null);
            queue.Close();
            queue.Open();
            Assert.Throws <InvalidOperationException>(() => queue.Enqueue(_ => TaskAsyncHelper.Empty, null));
        }
Пример #6
0
        public void CloseWhileQueueRuns()
        {
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Open();
            queue.Enqueue(_ => Task.Delay(50), null);
            queue.Enqueue(_ => Task.Delay(100), null);
            queue.Enqueue(_ => Task.Delay(150), null);
            queue.Close();
        }
Пример #7
0
        public void BufferAfterClosedEnqueueThrows()
        {
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.Close();
            queue.SetError(new Exception());
            Assert.Throws <InvalidOperationException>(() => queue.Enqueue(_ => TaskAsyncHelper.Empty, null));
        }
Пример #8
0
        public void EnqueueWithoutOpenRaisesOnError()
        {
            var tcs    = new TaskCompletionSource <object>();
            var config = new ScaleoutConfiguration()
            {
                RetryOnError = true,
                OnError      = ex => tcs.SetException(ex)
            };

            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", config);

            queue.Enqueue(_ => { throw new InvalidOperationException(); }, null);

            Assert.Throws <AggregateException>(() => tcs.Task.Wait());
        }
Пример #9
0
        public void InitialToBufferingToOpenToSend()
        {
            int x     = 0;
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            queue.SetError(new Exception());
            queue.Open();
            queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                          null).Wait();

            Assert.Equal(1, x);
        }
Пример #10
0
        public void SendsDuringInitialThenBufferingShouldNotSend()
        {
            int x     = 0;
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration()
            {
                RetryOnError = true
            });

            Task task = queue.Enqueue(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                                      null);

            queue.SetError(new Exception());

            task.Wait(TimeSpan.FromSeconds(0.5));

            Assert.Equal(0, x);
        }
Пример #11
0
        public void EnqueueWithoutOpenThrows()
        {
            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration());

            Assert.Throws <InvalidOperationException>(() => queue.Enqueue(_ => { throw new InvalidOperationException(); }, null));
        }