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));
            }
        }
Example #2
0
        public void Retry_Invalid_Parameters()
        {
            RetryOptions.Retry(bufferSizeBytes: 0);
            Assert.Throws <ArgumentOutOfRangeException>(() => RetryOptions.Retry(bufferSizeBytes: -1));

            RetryOptions.Retry(retryAttempts: 0);
            Assert.Throws <ArgumentOutOfRangeException>(() => RetryOptions.Retry(retryAttempts: -1));

            RetryOptions.Retry(retryInterval: TimeSpan.FromMilliseconds(1));
            Assert.Throws <ArgumentException>(() => RetryOptions.Retry(retryInterval: TimeSpan.Zero));
        }
        public void Receive_Retry_BufferFull_Throw()
        {
            SetupTestReceiveThrows((timer, mockConsumer, retryConsumer) =>
            {
                int[] intArray = { 1, 2, 3, 4 };
                Assert.Throws <InvalidOperationException>(() => { retryConsumer.Receive(intArray); });

                mockConsumer.Verify(c => c.Receive(intArray), Times.Once);
                timer.Call();
                mockConsumer.Verify(c => c.Receive(intArray), Times.Once);
            }, RetryOptions.Retry(bufferSizeBytes: 1, bufferOverflow: BufferOverflow.ThrowException));
        }
        public void Receive_Retry_BufferFull_Ignore()
        {
            SetupTestReceiveThrows((timer, mockConsumer, retryConsumer) =>
            {
                int[] intArray = { 1, 2, 3, 4 };
                retryConsumer.Receive(intArray);

                mockConsumer.Verify(c => c.Receive(intArray), Times.Once);
                timer.Call();
                mockConsumer.Verify(c => c.Receive(intArray), Times.Once);
            }, RetryOptions.Retry(bufferSizeBytes: 1));
        }
        public void Receive_Retry_MaxRetries_Throw()
        {
            SetupTestReceiveThrows((timer, mockConsumer, retryConsumer) =>
            {
                int[] intArray = { 1, 2, 3, 4 };
                retryConsumer.Receive(intArray);

                timer.Call();
                Assert.Throws <InvalidOperationException>(() => { timer.Call(); });
                // Extra call to ensure buffer is emptied.
                timer.Call();
                mockConsumer.Verify(c => c.Receive(intArray), Times.Exactly(3));
            }, RetryOptions.Retry(exceptionHandling: ExceptionHandling.Propagate, retryAttempts: 2));
        }
        public void Receive_Retry_MaxRetries_Ignore()
        {
            SetupTestReceiveThrows((timer, mockConsumer, retryConsumer) =>
            {
                int[] intArray = { 1, 2, 3, 4 };
                retryConsumer.Receive(intArray);

                timer.Call();
                timer.Call();
                // Extra call to ensure buffer is emptied.
                timer.Call();
                mockConsumer.Verify(c => c.Receive(intArray), Times.Exactly(3));
            }, RetryOptions.Retry(retryAttempts: 2));
        }
Example #7
0
        public void Retry()
        {
            int          size          = 100;
            int          retryAttempts = 12;
            TimeSpan     retryInterval = TimeSpan.FromSeconds(5);
            RetryOptions options       = RetryOptions.Retry(
                bufferSizeBytes: size, retryInterval: retryInterval, retryAttempts: retryAttempts);

            Assert.Equal(RetryType.Retry, options.RetryType);
            Assert.Equal(ExceptionHandling.Ignore, options.ExceptionHandling);
            Assert.Equal(BufferOverflow.IgnoreNewEntries, options.BufferOverflow);
            Assert.Equal(size, options.BufferSizeBytes);
            Assert.Equal(retryAttempts, options.RetryAttempts);
            Assert.Equal(retryInterval, options.RetryInterval);
        }