public void ValidateLeaseContructor() { var lease = Mock.Of <ILease>(); var ex = new LeaseLostException(lease); Assert.Equal(lease, ex.Lease); Assert.NotNull(ex.Message); }
public void ValidateLeaseContructor() { DocumentServiceLease lease = Mock.Of <DocumentServiceLease>(); LeaseLostException ex = new LeaseLostException(lease); Assert.AreEqual(lease, ex.Lease); Assert.IsNotNull(ex.Message); }
public void ValidateIsGoneConstructor() { DocumentServiceLease lease = Mock.Of <DocumentServiceLease>(); Exception innerException = new Exception(); LeaseLostException ex = new LeaseLostException(lease, innerException, true); Assert.IsNotNull(ex.Message); Assert.AreEqual(lease, ex.Lease); Assert.AreEqual(innerException, ex.InnerException); Assert.IsTrue(ex.IsGone); }
public void ValidateIsGoneConstructor() { var lease = Mock.Of <ILease>(); var innerException = new Exception(); var ex = new LeaseLostException(lease, innerException, true); Assert.NotNull(ex.Message); Assert.Equal(lease, ex.Lease); Assert.Equal(innerException, ex.InnerException); Assert.True(ex.IsGone); }
public void ValidateSerialization_NullFields() { LeaseLostException originalException = new LeaseLostException("message"); string serialized = JsonConvert.SerializeObject(originalException); LeaseLostException deserializedException = JsonConvert.DeserializeObject <LeaseLostException>(serialized); Assert.AreEqual(originalException.Message, deserializedException.Message); Assert.IsNull(deserializedException.InnerException); Assert.IsNull(deserializedException.Lease); Assert.IsFalse(deserializedException.IsGone); }
public void ValidateSerialization_AllFields() { DocumentServiceLeaseCore lease = new DocumentServiceLeaseCore() { LeaseId = "id" }; LeaseLostException originalException = new LeaseLostException(lease, new Exception("foo"), true); string serialized = JsonConvert.SerializeObject(originalException); LeaseLostException deserializedException = JsonConvert.DeserializeObject <LeaseLostException>(serialized); Assert.AreEqual(originalException.Message, deserializedException.Message); Assert.AreEqual(originalException.InnerException.Message, deserializedException.InnerException.Message); Assert.AreEqual(originalException.Lease.Id, deserializedException.Lease.Id); Assert.AreEqual(originalException.IsGone, deserializedException.IsGone); }
public void ValidateSerialization_NullFields() { var originalException = new LeaseLostException("message"); var buffer = new byte[4096]; var formatter = new BinaryFormatter(); var stream1 = new MemoryStream(buffer); var stream2 = new MemoryStream(buffer); formatter.Serialize(stream1, originalException); var deserializedException = (LeaseLostException)formatter.Deserialize(stream2); Assert.Equal(originalException.Message, deserializedException.Message); Assert.Null(deserializedException.InnerException); Assert.Null(deserializedException.Lease); Assert.False(deserializedException.IsGone); }
public async Task LogsLeaseLost() { MockedLogger mockedLogger = new MockedLogger(); LeaseLostException exception = new LeaseLostException(); MockedLease lease = new MockedLease(); CosmosDBTriggerHealthMonitor cosmosDBTriggerHealthMonitor = new CosmosDBTriggerHealthMonitor(mockedLogger); await cosmosDBTriggerHealthMonitor.InspectAsync(new HealthMonitoringRecord(HealthSeverity.Error, MonitoredOperation.AcquireLease, lease, exception)); Assert.Single(mockedLogger.Events); LogEvent loggedEvent = mockedLogger.Events[0]; Assert.Equal(LogLevel.Warning, loggedEvent.LogLevel); Assert.Equal(exception, loggedEvent.Exception); Assert.True(loggedEvent.Message.Contains(lease.ToString()) && loggedEvent.Message.Contains(MonitoredOperation.AcquireLease.ToString())); Assert.True(loggedEvent.Message.Contains("This is expected during scaling and briefly")); }
public void ValidateSerialization_AllFields() { var lease = new DocumentServiceLease { Id = "id" }; var originalException = new LeaseLostException(lease, new Exception("foo"), true); var buffer = new byte[4096]; var formatter = new BinaryFormatter(); var stream1 = new MemoryStream(buffer); var stream2 = new MemoryStream(buffer); formatter.Serialize(stream1, originalException); var deserializedException = (LeaseLostException)formatter.Deserialize(stream2); Assert.Equal(originalException.Message, deserializedException.Message); Assert.Equal(originalException.InnerException.Message, deserializedException.InnerException.Message); Assert.Equal(originalException.Lease.Id, deserializedException.Lease.Id); Assert.Equal(originalException.IsGone, deserializedException.IsGone); }
public void ValidateRecommendedConstructors() { // Default ctor. LeaseLostException ex = new LeaseLostException(); Assert.IsNotNull(ex.Message); // ctor(message). string message = "message"; ex = new LeaseLostException(message); Assert.AreEqual(message, ex.Message); // ctor() Exception innerException = new Exception(); ex = new LeaseLostException(message, innerException); Assert.AreEqual(message, ex.Message); Assert.AreEqual(innerException, ex.InnerException); }
/// <summary> /// Handles the Azure Storage exceptions /// </summary> /// <param name="partitionId">The partition id</param> /// <param name="exception">The storage exception that was raised</param> /// <param name="logger">The logger to write debugging and diagnostics information to</param> /// <returns>The exception that was generated or passed in</returns> public static Exception CheckForLeaseLostException(string partitionId, StorageException exception, ILogger logger) { Exception results = exception; if (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412) { logger.LogError(exception, "HandleStorageException (conflict or precondition failed) - HttpStatusCode: Partition Id: {partitionId}, HttpStatusCode: {status}, errorCode: {errorCode}, errorMessage: {errorMessage}", partitionId, exception.RequestInformation.HttpStatusCode, exception.RequestInformation.ErrorCode, exception.RequestInformation.ExtendedErrorInformation?.ErrorMessage); if (exception.RequestInformation.ErrorCode == null || exception.RequestInformation.ErrorCode == BlobErrorCodeStrings.LeaseLost || exception.RequestInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithLeaseOperation || exception.RequestInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithBlobOperation) { results = new LeaseLostException(partitionId, exception); } } else { logger.LogError(exception, "HandleStorageException - HttpStatusCode: Partition Id: {partitionId}, HttpStatusCode: {status}, errorCode: {errorCode}, errorMessage: {errorMessage}", partitionId, exception.RequestInformation.HttpStatusCode, exception.RequestInformation.ErrorCode, exception.RequestInformation.ExtendedErrorInformation?.ErrorMessage); } return(results); }
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); }