public async Task TestCancellation() { var cts = new CancellationTokenSource(); var retryPolicy = new RetryPolicy(new ErrorDetectionStrategy(_ => true), new FixedInterval(2, TimeSpan.FromMilliseconds(10))); var items = new[] { 1, 2, 3, 4, 5, 6 }; var testSink = new FailedSink <int>(new Exception()); var sink = new RetryingSink <int>(testSink, retryPolicy); Task <ISinkResult <int> > task = sink.ProcessAsync(items, cts.Token); cts.Cancel(); ISinkResult <int> result = await task; Assert.False(result.IsSuccessful); Assert.Equal(new List <int>(), result.Succeeded); Assert.Equal(new List <int> { 1, 2, 3, 4, 5, 6 }, result.Failed); Assert.Equal(new List <InvalidDetails <int> >(), result.InvalidDetailsList); Assert.True(result.SendFailureDetails.HasValue); result.SendFailureDetails.ForEach(sfd => Assert.IsType <TaskCanceledException>(sfd.RawException)); }
public async Task TestNonTransient() { var retryPolicy = new RetryPolicy(new ErrorDetectionStrategy(_ => false), new FixedInterval(int.MaxValue, TimeSpan.FromMilliseconds(10))); var items = new[] { 1, 2, 3, 4, 5, 6 }; var testSink = new FailedSink <int>(new Exception("non-transient")); var sink = new RetryingSink <int>(testSink, retryPolicy); using (var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(500))) { ISinkResult <int> result = await sink.ProcessAsync(items, cts.Token); Assert.False(result.IsSuccessful); Assert.Equal(new List <int>(), result.Succeeded); Assert.Equal(new List <int> { 1, 2, 3, 4, 5, 6 }, result.Failed); Assert.Equal(new List <InvalidDetails <int> >(), result.InvalidDetailsList); Assert.True(result.SendFailureDetails.HasValue); result.SendFailureDetails.ForEach(sfd => Assert.IsType <Exception>(sfd.RawException)); result.SendFailureDetails.ForEach(sfd => Assert.Equal("non-transient", sfd.RawException.Message)); } }
public Task <ISink <T> > CreateAsync(string hubName) { ISink <T> sink = new FailedSink <T>(this.exception); return(Task.FromResult(sink)); }