コード例 #1
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));
 }
コード例 #2
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();
 }
コード例 #3
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());
        }
コード例 #4
0
        public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                                     Action <int, ulong, IList <Message> > receive,
                                     int streamCount,
                                     ScaleoutConfiguration configuration,
                                     TraceSource trace)
        {
            _sendQueues = new ScaleoutTaskQueue[streamCount];
            _send       = send;
            _receive    = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            for (int i = 0; i < streamCount; i++)
            {
                _sendQueues[i]    = new ScaleoutTaskQueue(trace, "Stream(" + i + ")", configuration);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection <ScaleoutMappingStore>(receiveMapping);
        }
コード例 #5
0
        public ScaleoutStreamManager(Func<int, IList<Message>, Task> send,
                                     Action<int, ulong, IList<Message>> receive,
                                     int streamCount,
                                     ScaleoutConfiguration configuration,
                                     TraceSource trace)
        {
            _sendQueues = new ScaleoutTaskQueue[streamCount];
            _send = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            for (int i = 0; i < streamCount; i++)
            {
                _sendQueues[i] = new ScaleoutTaskQueue(trace, "Stream(" + i + ")", configuration);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection<ScaleoutMappingStore>(receiveMapping);
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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));
 }
コード例 #9
0
 public void EnqueueWithoutOpenThrows()
 {
     var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration());
     Assert.Throws<InvalidOperationException>(() => queue.Enqueue(_ => { throw new InvalidOperationException(); }, null));
 }
コード例 #10
0
        public void ThrowingFromErrorCallbackIsCaught()
        {
            var config = new ScaleoutConfiguration()
            {
                RetryOnError = true,
                OnError = ex =>
                {
                    throw new Exception();
                }
            };

            var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", config);
            queue.SetError(new Exception());
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
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));
 }
コード例 #14
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);
        }
コード例 #15
0
 public void InitialToClosed()
 {
     var queue = new ScaleoutTaskQueue(new TraceSource("Queue"), "0", new ScaleoutConfiguration() { RetryOnError = true });
     queue.Close();
 }