public void Initialize_PerformsExpectedRegistrations() { var host = new HostBuilder() .ConfigureDefaultTestHost(builder => { builder.AddEventHubs(); }) .ConfigureServices(c => { c.AddSingleton <INameResolver>(new RandomNameResolver()); }) .Build(); IExtensionRegistry extensions = host.Services.GetService <IExtensionRegistry>(); // ensure the EventHubTriggerAttributeBindingProvider was registered var triggerBindingProviders = extensions.GetExtensions <ITriggerBindingProvider>().ToArray(); EventHubTriggerAttributeBindingProvider triggerBindingProvider = triggerBindingProviders.OfType <EventHubTriggerAttributeBindingProvider>().Single(); Assert.NotNull(triggerBindingProvider); // ensure the EventProcessorOptions ExceptionReceived event is wired up var options = host.Services.GetService <IOptions <EventHubOptions> >().Value; var eventProcessorOptions = options.EventProcessorOptions; var ex = new EventHubsException(false, "Kaboom!"); var ctor = typeof(ExceptionReceivedEventArgs).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single(); var args = (ExceptionReceivedEventArgs)ctor.Invoke(new object[] { "TestHostName", "TestPartitionId", ex, "TestAction" }); var handler = (Action <ExceptionReceivedEventArgs>)eventProcessorOptions.GetType().GetField("exceptionHandler", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(eventProcessorOptions); handler.Method.Invoke(handler.Target, new object[] { args }); string expectedMessage = "EventProcessorHost error (Action='TestAction', HostName='TestHostName', PartitionId='TestPartitionId')."; var logMessage = host.GetTestLoggerProvider().GetAllLogMessages().Single(); Assert.Equal(LogLevel.Error, logMessage.Level); Assert.Equal(expectedMessage, logMessage.FormattedMessage); Assert.Same(ex, logMessage.Exception); }
private EventHubsException RetryWrapper(Action action) { EventHubsException lastException = null; for (int i = 0; i < Constants.RetryCount; i++) { this.linkedCancellationToken.ThrowIfCancellationRequested(); try { action.Invoke(); break; } catch (EventHubsException e) { if (!e.IsTransient) { throw e; } lastException = e; } } return(lastException); }
public void DerrivedExceptionsHaveTheCorrectTransientValues(EventHubsException exception, bool expectedTransient) { Assert.That(exception.IsTransient, Is.EqualTo(expectedTransient), $"The { exception.GetType().Name } has an incorrect IsTransient value."); }
/// <summary> /// Sets the failed operation name related to the exception. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// <param name="operationName">The failed operation name.</param> /// public static void SetFailureOperation(this EventHubsException instance, string operationName) => instance.Data[FailureOperationKey] = operationName;
/// <summary> /// Sets the data value related to the exception. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// <param name="data">The value to store in the Exception Data.</param> /// public static void SetFailureData <T>(this EventHubsException instance, T data) where T : class => instance.Data[FailureDataKey] = data;
/// <summary> /// Gets the failed operation name related to the exception. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// /// <returns>The failed operation name.</returns> /// public static string GetFailureOperation(this EventHubsException instance) => instance.Data.Contains(FailureOperationKey) ? instance.Data[FailureOperationKey] as string : string.Empty;
/// <summary> /// Gets the data value related to the exception <see cref="EventHubsException.FailureReason" />. /// </summary> /// /// <param name="instance">The instance that this method was invoked on.</param> /// /// <returns>The Data value or null.</returns> /// public static T GetFailureData <T>(this EventHubsException instance) where T : class => instance.Data.Contains(FailureDataKey) ? instance.Data[FailureDataKey] as T : null;
/// <summary> /// Verifies functionality of the <see cref="ExceptionExtensions.IsFatalException" /> /// method. /// </summary> /// public void IsFatalExceptionRecognizesEventHubsExceptionIsNotFatal() { var instance = new EventHubsException(true, "hub"); Assert.That(instance.IsFatalException(), Is.False); }