Esempio n. 1
0
        public void SendsBeforeOpenedRunOnceOpenedWhenQueuingBehaviorInitialOnly()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            int x = 0;

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

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

            stream.Open();

            task.Wait();

            Assert.Equal(2, x);
        }
        public void SendAfterOpenAndAfterErrorThrows()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            int x = 0;

            var firstSend = stream.Send(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                                        null);

            stream.Open();

            // Wait on the first send to drain
            firstSend.Wait();

            stream.SetError(new Exception("Failed"));

            Assert.Throws <Exception>(() =>
            {
                stream.Send(_ =>
                {
                    x++;
                    return(TaskAsyncHelper.Empty);
                },
                            null).Wait();
            });

            Assert.Equal(1, x);
        }
        public void SendsBeforeOpenedRunOnceOpenedWhenQueuingBehaviorInitialOnly()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            int x = 0;

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

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

            stream.Open();

            task.Wait();

            Assert.Equal(2, x);
        }
Esempio n. 4
0
        public void SendAfterOpenAndAfterErrorThrows()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            int x = 0;

            var firstSend = stream.Send(_ =>
            {
                x++;
                return(TaskAsyncHelper.Empty);
            },
                                        null);

            stream.Open();

            // Wait on the first send to drain
            firstSend.Wait();

            stream.SetError(new Exception("Failed"));

            Assert.Throws <Exception>(() =>
            {
                stream.Send(_ =>
                {
                    x++;
                    return(TaskAsyncHelper.Empty);
                },
                            null).Wait();
            });

            Assert.Equal(1, x);
        }
        public void CloseWhileQueueRunsWithFailedTask()
        {
            int x             = 0;
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                await TaskAsyncHelper.FromError(new Exception());
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Close();
            Assert.Equal(1, x);
        }
Esempio n. 6
0
        public void CloseWhileQueueRuns()
        {
            int x            = 0;
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters);

            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Close();
            Assert.Equal(3, x);
        }
Esempio n. 7
0
        public void CloseWhileQueueRunsWithFailedTask()
        {
            int x            = 0;
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                await TaskAsyncHelper.FromError(new Exception());
            },
                        null);
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);
            stream.Close();
            Assert.Equal(1, x);
        }
Esempio n. 8
0
        public void OpenAfterErrorRunsQueue()
        {
            int x            = 0;
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(_ => { throw new InvalidOperationException(); }, null);

            stream.Open();

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

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

            Assert.True(task.Wait(10000));

            Assert.Equal(2, x);
        }
Esempio n. 9
0
        public void EnqueueWithoutOpenRaisesOnError()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters);

            Assert.Throws <InvalidOperationException>(() => stream.Send(_ => { throw new InvalidOperationException(); }, null));
        }
        public void OpenAfterErrorRunsQueue()
        {
            int x             = 0;
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(_ => { throw new InvalidOperationException(); }, null);

            stream.Open();

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

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

            task.Wait();

            Assert.Equal(2, x);
        }
Esempio n. 11
0
        public void InitialToClosed()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Close();
        }
Esempio n. 12
0
        public async Task BufferAfterClosedEnqueueThrows()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Close();
            stream.SetError(new Exception());
            await Assert.ThrowsAsync <Exception>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
Esempio n. 13
0
        public void OpenAfterClosedEnqueueThrows()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters);

            stream.Close();
            stream.Open();
            Assert.Throws <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
        public void InitialToClosed()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Close();
        }
Esempio n. 15
0
        public void SendAfterCloseThenOpenRemainsClosed()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(_ => Task.Delay(50), null);
            stream.Close();
            stream.Open();
            Assert.Throws <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
Esempio n. 16
0
        public async Task SendBeforeOpenDoesNotThrowWhenQueuingBehaviorInitialOnly()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            var sendTask = stream.Send(_ => { return(TaskAsyncHelper.Empty); }, null);

            stream.Open();

            await sendTask.OrTimeout();
        }
        public void BufferAfterClosedEnqueueThrows()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Close();
            stream.SetError(new Exception());
            Assert.ThrowsAsync <Exception>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
        public void SendBeforeOpenDoesNotThrowWhenQueuingBehaviorInitialOnly()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.InitialOnly, 1000, perfCounters);

            var sendTask = stream.Send(_ => { return(TaskAsyncHelper.Empty); }, null);

            stream.Open();

            Assert.DoesNotThrow(() => sendTask.Wait());
        }
        public void SendAfterCloseThenOpenRemainsClosed()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(_ => Task.Delay(50), null);
            stream.Close();
            stream.Open();
            Assert.ThrowsAsync <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
Esempio n. 20
0
        public void ErrorOnSendThrowsNextTime()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters);

            stream.Open();

            Task task = stream.Send(_ =>
            {
                throw new InvalidOperationException();
            },
                                    null);

            Assert.Throws <AggregateException>(() => task.Wait());
            Assert.Throws <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
Esempio n. 21
0
        public async Task ErrorOnSendThrowsNextTime()
        {
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();

            Task task = stream.Send(_ =>
            {
                throw new InvalidOperationException();
            },
                                    null);

            await Assert.ThrowsAsync <InvalidOperationException>(() => task);

            await Assert.ThrowsAsync <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
Esempio n. 22
0
        public void InitialToBufferingToOpenToSend()
        {
            int x            = 0;
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.SetError(new Exception());
            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(20);
                x++;
            },
                        null).Wait();

            Assert.Equal(1, x);
        }
        public void ErrorOnSendThrowsNextTime()
        {
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();

            Task task = stream.Send(_ =>
            {
                throw new InvalidOperationException();
            },
                                    null);

            Assert.Throws <AggregateException>(() => task.Wait());
            Assert.ThrowsAsync <InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null));
        }
        public void InitialToBufferingToOpenToSend()
        {
            int x             = 0;
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.SetError(new Exception());
            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(20);
                x++;
            },
                        null).Wait();

            Assert.Equal(1, x);
        }
Esempio n. 25
0
        public void SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior(QueuingBehavior queuingBehavior, int expectedCounter)
        {
            var perfCounters          = new Mock <IPerformanceCounterManager>();
            var queueLengthCounter    = new Mock <IPerformanceCounter>();
            var counterIncrementCount = 0;

            queueLengthCounter.Setup(c => c.Increment()).Callback(() => counterIncrementCount++);
            perfCounters.DefaultValue = DefaultValue.Mock;
            perfCounters.SetReturnsDefault(new NoOpPerformanceCounter());
            perfCounters.SetupAllProperties();
            perfCounters.Setup(pc => pc.ScaleoutSendQueueLength).Returns(queueLengthCounter.Object);

            var stream = new ScaleoutStream(new TraceSource("Queue"), "0", queuingBehavior, 1000, perfCounters.Object);

            stream.Send(_ => TaskAsyncHelper.Empty, null);

            stream.Open();

            stream.Send(_ => TaskAsyncHelper.Empty, null).Wait();

            Assert.Equal(expectedCounter, counterIncrementCount);
        }
        public void OpenQueueErrorOpenQueue()
        {
            int x             = 0;
            var loggerFactory = new Mock <ILoggerFactory>();
            var perfCounters  = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var logger        = new Mock <ILogger>();
            var stream        = new ScaleoutStream(logger.Object, "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);

            Task t1 = stream.Send(async _ =>
            {
                await Task.Delay(50);
                await TaskAsyncHelper.FromError(new Exception());
            },
                                  null);

            Assert.Throws <AggregateException>(() => t1.Wait());

            stream.Open();

            Task t2 = stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                                  null);

            t2.Wait();

            Assert.Equal(2, x);
        }
Esempio n. 27
0
        public void OpenQueueErrorOpenQueue()
        {
            int x            = 0;
            var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager();
            var stream       = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters);

            stream.Open();
            stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                        null);

            Task t1 = stream.Send(async _ =>
            {
                await Task.Delay(50);
                await TaskAsyncHelper.FromError(new Exception());
            },
                                  null);

            Assert.Throws <AggregateException>(() => t1.Wait());

            stream.Open();

            Task t2 = stream.Send(async _ =>
            {
                await Task.Delay(50);
                x++;
            },
                                  null);

            t2.Wait();

            Assert.Equal(2, x);
        }