Example #1
0
        public async Task ProcessErrorsAsync_RebalancingExceptions_LoggedAsInformation()
        {
            var partitionContext = EventHubTests.GetPartitionContext(partitionId: "123", eventHubPath: "abc", owner: "def");
            var options          = new EventHubOptions();
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var testLogger       = new TestLogger("Test");
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, testLogger, true);

            var disconnectedEx = new EventHubsException(true, "My ReceiverDisconnectedException!", EventHubsException.FailureReason.ConsumerDisconnected);

            await eventProcessor.ProcessErrorAsync(partitionContext, disconnectedEx);

            var msg = testLogger.GetLogMessages().Single();

            StringAssert.IsMatch("Processing error \\(Partition Id: '123', Owner: '[\\w\\d-]+', EventHubPath: 'abc'\\). An exception of type 'EventHubsException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.AreEqual(LogLevel.Information, msg.Level);

            testLogger.ClearLogMessages();

            var leaseLostEx = new EventHubsException(true, "My LeaseLostException!", EventHubsException.FailureReason.ConsumerDisconnected);

            await eventProcessor.ProcessErrorAsync(partitionContext, leaseLostEx);

            msg = testLogger.GetLogMessages().Single();
            StringAssert.IsMatch("Processing error \\(Partition Id: '123', Owner: '[\\w\\d-]+', EventHubPath: 'abc'\\). An exception of type 'EventHubsException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.AreEqual(LogLevel.Information, msg.Level);
        }
Example #2
0
        public async Task ProcessErrorsAsync_RebalancingExceptions_LoggedAsInformation()
        {
            var partitionContext = EventHubTests.GetPartitionContext(partitionId: "123", eventHubPath: "abc", owner: "def");
            var options          = new EventHubOptions();
            var checkpointer     = new Mock <EventHubListener.ICheckpointer>(MockBehavior.Strict);
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var testLogger       = new TestLogger("Test");
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, testLogger, true, checkpointer.Object);

            // ctor is private
            var constructor = typeof(ReceiverDisconnectedException)
                              .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string) }, null);
            ReceiverDisconnectedException disconnectedEx = (ReceiverDisconnectedException)constructor.Invoke(new[] { "My ReceiverDisconnectedException!" });

            await eventProcessor.ProcessErrorAsync(partitionContext, disconnectedEx);

            var msg = testLogger.GetLogMessages().Single();

            Assert.Equal("Processing error (Partition Id: '123', Owner: 'def', EventHubPath: 'abc'). An exception of type 'ReceiverDisconnectedException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.Equal(LogLevel.Information, msg.Level);

            testLogger.ClearLogMessages();

            // ctor is private
            constructor = typeof(LeaseLostException)
                          .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(Exception) }, null);
            LeaseLostException leaseLostEx = (LeaseLostException)constructor.Invoke(new object[] { "My LeaseLostException!", new Exception() });

            await eventProcessor.ProcessErrorAsync(partitionContext, leaseLostEx);

            msg = testLogger.GetLogMessages().Single();
            Assert.Equal("Processing error (Partition Id: '123', Owner: 'def', EventHubPath: 'abc'). An exception of type 'LeaseLostException' was thrown. This exception type is typically a result of Event Hub processor rebalancing or a transient error and can be safely ignored.", msg.FormattedMessage);
            Assert.NotNull(msg.Exception);
            Assert.Equal(LogLevel.Information, msg.Level);
        }
Example #3
0
        public async Task ProcessErrorsAsync_LoggedAsError()
        {
            var partitionContext = EventHubTests.GetPartitionContext(partitionId: "123", eventHubPath: "abc", owner: "def");
            var options          = new EventHubOptions();
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var testLogger       = new TestLogger("Test");
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, testLogger, true);

            var ex = new InvalidOperationException("My InvalidOperationException!");

            await eventProcessor.ProcessErrorAsync(partitionContext, ex);

            var msg = testLogger.GetLogMessages().Single();

            StringAssert.IsMatch("Processing error \\(Partition Id: '123', Owner: '[\\w\\d-]+', EventHubPath: 'abc'\\).", msg.FormattedMessage);
            Assert.IsInstanceOf <InvalidOperationException>(msg.Exception);
            Assert.AreEqual(LogLevel.Error, msg.Level);
        }
        public async Task ProcessErrorsAsync_LoggedAsError()
        {
            var partitionContext = EventHubTests.GetPartitionContext(partitionId: "123", eventHubPath: "abc", owner: "def");
            var options          = new EventHubOptions();
            var checkpointer     = new Mock <EventHubListener.ICheckpointer>(MockBehavior.Strict);
            var executor         = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);
            var testLogger       = new TestLogger("Test");
            var eventProcessor   = new EventHubListener.EventProcessor(options, executor.Object, testLogger, true, checkpointer.Object);

            var ex = new InvalidOperationException("My InvalidOperationException!");

            await eventProcessor.ProcessErrorAsync(partitionContext, ex);

            var msg = testLogger.GetLogMessages().Single();

            Assert.Equal("Error processing event from Partition Id: '123', Owner: 'def', EventHubPath: 'abc'", msg.FormattedMessage);
            Assert.IsType <InvalidOperationException>(msg.Exception);
            Assert.Equal(LogLevel.Error, msg.Level);
        }