public void Receive_Retry() { var timer = new FakeSequentialThreadingTimer(); var options = RetryOptions.Retry(); var mockConsumer = new Mock <IConsumer <int> >(); var timerFactory = CreateTimerFactory(timer); var calls = 0; mockConsumer.Setup(c => c.Receive(It.IsAny <IEnumerable <int> >())) .Callback(() => { calls++; if (calls == 1) { throw new RpcException(Status.DefaultSuccess); } }); using (var retryConsumer = new RpcRetryConsumer <int>( mockConsumer.Object, options, Utils.ConstantSizer <int> .GetSize, timerFactory)) { int[] intArray = { 1, 2, 3, 4 }; retryConsumer.Receive(intArray); timer.Call(); // Extra call to ensure buffer is emptied. timer.Call(); mockConsumer.Verify(c => c.Receive(intArray), Times.Exactly(2)); } }
/// <summary> /// Sets up a test where all calls to the consumer passed to the <see cref="RpcRetryConsumer"/> will throw /// an <see cref="RpcException"/>. /// </summary> private void SetupTestReceiveThrows(Action <FakeSequentialThreadingTimer, Mock <IConsumer <int> >, RpcRetryConsumer <int> > action, RetryOptions options) { var timer = new FakeSequentialThreadingTimer(); var mockConsumer = new Mock <IConsumer <int> >(); var timerFactory = CreateTimerFactory(timer); mockConsumer.Setup(c => c.Receive(It.IsAny <IEnumerable <int> >())) .Throws(new RpcException(Status.DefaultSuccess)); using (var retryConsumer = new RpcRetryConsumer <int>( mockConsumer.Object, options, Utils.ConstantSizer <int> .GetSize, timerFactory)) { action(timer, mockConsumer, retryConsumer); } }
public void Receive() { var options = RetryOptions.NoRetry(ExceptionHandling.Propagate); var mockConsumer = new Mock <IConsumer <int> >(); Func <Action, RetryOptions, ISequentialThreadingTimer> timerFactory = (callback, retryOptions) => new SequentialThreadingTimer(); using (var retryConsumer = new RpcRetryConsumer <int>( mockConsumer.Object, options, Utils.ConstantSizer <int> .GetSize, timerFactory)) { int[] intArray = { 1, 2, 3, 4 }; retryConsumer.Receive(intArray); mockConsumer.Verify(c => c.Receive(intArray), Times.Once); } }