/// <summary> /// The set of test cases for the well-known types derived from the <see cref="EventHubsException" /> /// and their expected transient status. /// </summary> /// public static IEnumerable <object[]> ExceptionMappingTestCases() { TrackOne.EventHubsException exception; exception = new TrackOne.EventHubsCommunicationException("One") { EventHubsNamespace = "test_thing" }; yield return(new object[] { exception, typeof(Errors.EventHubsCommunicationException) }); exception = new TrackOne.EventHubsTimeoutException("Two") { EventHubsNamespace = "OMG!-Thing!" }; yield return(new object[] { exception, typeof(Errors.EventHubsTimeoutException) }); yield return(new object[] { new TrackOne.MessagingEntityNotFoundException("Three"), typeof(Errors.EventHubsResourceNotFoundException) }); yield return(new object[] { new TrackOne.MessageSizeExceededException("Four"), typeof(Errors.MessageSizeExceededException) }); yield return(new object[] { new TrackOne.QuotaExceededException("Five"), typeof(Errors.QuotaExceededException) }); yield return(new object[] { new TrackOne.ReceiverDisconnectedException("Six"), typeof(Errors.ConsumerDisconnectedException) }); yield return(new object[] { new TrackOne.ServerBusyException("Seven"), typeof(Errors.ServiceBusyException) }); yield return(new object[] { new TrackOne.EventHubsException(true, "Eight"), typeof(Errors.EventHubsException) }); }
public void RetryIsInvokedForRetriableTrackOneEventHubsException() { var retryCount = 99; var lastException = new TrackOne.EventHubsTimeoutException("RETRY!"); EventHubsException mappedException = lastException.MapToTrackTwoException(); var expectedInterval = TimeSpan.FromMinutes(65); var mockRetryPolicy = new Mock <EventHubRetryPolicy>(); var retryPolicy = new TrackOneRetryPolicy(mockRetryPolicy.Object); mockRetryPolicy .Setup(policy => policy.CalculateRetryDelay(It.Is <EventHubsException>(value => value.GetType() == mappedException.GetType()), It.Is <int>(value => value == retryCount))) .Returns(expectedInterval); Assert.That(TrackOne.RetryPolicy.IsRetryableException(lastException), Is.True, "The timeout exception should be considered as retriable by the TrackOne.RetryPolicy."); Assert.That(retryPolicy.GetNextRetryInterval(lastException, TimeSpan.FromHours(4), retryCount), Is.EqualTo(expectedInterval)); }
/// <summary> /// Maps a <see cref="TrackOne.EventHubsException" /> or a child of it to the equivalent /// exception for the new API surface. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// /// <returns>The equivalent exception type for the new API, wrapping the <paramref name="instance" /> as the inner exception.</returns> /// public static Errors.EventHubsException MapToTrackTwoException(this TrackOne.EventHubsException instance) { Argument.AssertNotNull(instance, nameof(instance)); return(instance switch { TrackOne.EventHubsCommunicationException ex => new Errors.EventHubsCommunicationException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.EventHubsTimeoutException ex => new Errors.EventHubsTimeoutException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.MessagingEntityNotFoundException ex => new Errors.EventHubsResourceNotFoundException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.MessageSizeExceededException ex => new Errors.MessageSizeExceededException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.QuotaExceededException ex => new Errors.QuotaExceededException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.ReceiverDisconnectedException ex => new Errors.ConsumerDisconnectedException(ex.EventHubsNamespace, ex.RawMessage, ex), TrackOne.ServerBusyException ex => new Errors.ServiceBusyException(ex.EventHubsNamespace, ex.RawMessage, ex), _ => new Errors.EventHubsException(instance.IsTransient, instance.EventHubsNamespace, instance.RawMessage, instance), });