Exemplo n.º 1
0
        public async Task LogsTrace()
        {
            MockedLogger mockedLogger = new MockedLogger();
            MockedLease  lease        = new MockedLease();
            CosmosDBTriggerHealthMonitor cosmosDBTriggerHealthMonitor = new CosmosDBTriggerHealthMonitor(mockedLogger);

            await cosmosDBTriggerHealthMonitor.InspectAsync(new HealthMonitoringRecord(HealthSeverity.Informational, MonitoredOperation.AcquireLease, lease, null));

            Assert.Single(mockedLogger.Events);

            LogEvent loggedEvent = mockedLogger.Events[0];

            Assert.Equal(LogLevel.Trace, loggedEvent.LogLevel);
            Assert.True(loggedEvent.Message.Contains(lease.ToString()) && loggedEvent.Message.Contains(MonitoredOperation.AcquireLease.ToString()));
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        public async Task LogsError()
        {
            MockedLogger mockedLogger = new MockedLogger();
            Exception    exception    = new Exception();
            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.Error, 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("encountered an error"));
        }