public Send ( Task>.Func | ||
send | Task>.Func | |
state | object | |
Результат | System.Threading.Tasks.Task |
public void OpenAfterErrorRunsQueue() { 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(_ => { 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); }
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); }
public void CloseWhileQueueRunsWithFailedTask() { 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); await TaskAsyncHelper.FromError(new Exception()); }, null); stream.Send(async _ => { await Task.Delay(50); x++; }, null); stream.Close(); Assert.Equal(1, x); }
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 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)); }
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 BufferAfterClosedEnqueueThrows() { var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager(); var stream = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters); stream.Close(); stream.SetError(new Exception()); Assert.Throws<Exception>(() => stream.Send(_ => TaskAsyncHelper.Empty, null)); }
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 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(); Assert.DoesNotThrow(() => sendTask.Wait()); }
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 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)); }
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); }
public void CloseWhileQueueRuns() { 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); x++; }, null); stream.Send(async _ => { await Task.Delay(50); x++; }, null); stream.Close(); Assert.Equal(3, 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 SendAfterCloseThenOpenRemainsClosed() { var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager(); var stream = new ScaleoutStream(new TraceSource("Queue"), "0", 1000, perfCounters); stream.Open(); stream.Send(_ => Task.Delay(50), null); stream.Close(); stream.Open(); Assert.Throws<InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null)); }
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); }
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); }
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 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); }
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); }
public void OpenAfterClosedEnqueueThrows() { var perfCounters = new Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager(); var stream = new ScaleoutStream(new TraceSource("Queue"), "0", QueuingBehavior.Always, 1000, perfCounters); stream.Close(); stream.Open(); Assert.Throws<InvalidOperationException>(() => stream.Send(_ => TaskAsyncHelper.Empty, null)); }
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 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 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(); // (Does not throw) sendTask.Wait(); }