Exemplo n.º 1
0
        public void HighLoadNoData()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            // Act
            var actual = discrepancyService
                         .FindHighLoadInDataPoints(
                new List <NumericDataPoint>(),
                new Metric
            {
                Type   = Metrics.CpuLoad.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Empty(actual);
        }
Exemplo n.º 2
0
        public void MultipleHighLoadInData()
        {
            // Arrange
            var mockConfig = new Mock <IConfiguration>();

            mockConfig
            .SetupGet(conf => conf["ServiceManager:DiscrepancyService:Load:Threshold"])
            .Returns(90.ToString());
            mockConfig
            .SetupGet(conf => conf["ServiceManager:DiscrepancyService:Load:MaxFailures"])
            .Returns(2.ToString());                     // 3 is discrepancy

            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                mockConfig.Object
                );

            var input = new List <NumericDataPoint>()
            {
                new NumericDataPoint {                 // Good
                    Timestamp = DateTime.UtcNow.AddMinutes(0),
                    Value     = 68
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-1),
                    Value     = 91
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-2),
                    Value     = 99
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-3),
                    Value     = 95
                },
                new NumericDataPoint {                 // Good
                    Timestamp = DateTime.UtcNow.AddMinutes(-4),
                    Value     = 68
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-5),
                    Value     = 99
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-6),
                    Value     = 98
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-7),
                    Value     = 92
                },
                new NumericDataPoint {                 // Good
                    Timestamp = DateTime.UtcNow.AddMinutes(-8),
                    Value     = 68
                }
            };

            var expected = new List <Discrepancy> {
                new Discrepancy
                {
                    DateFirstOffense = input[3].Timestamp,
                    Type             = DiscrepancyType.HighLoad,
                    MetricType       = Metrics.CpuLoad,
                    MetricSource     = "the-source"
                },
                new Discrepancy
                {
                    DateFirstOffense = input[7].Timestamp,
                    Type             = DiscrepancyType.HighLoad,
                    MetricType       = Metrics.CpuLoad,
                    MetricSource     = "the-source"
                }
            };

            // Act
            var actual = discrepancyService
                         .FindHighLoadInDataPoints(
                input,
                new Metric
            {
                Type   = Metrics.CpuLoad.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void PermanentHighLoadInData()
        {
            // Arrange
            var mockConfig = new Mock <IConfiguration>();

            mockConfig
            .SetupGet(conf => conf["ServiceManager:DiscrepancyService:Load:Threshold"])
            .Returns(90.ToString());
            mockConfig
            .SetupGet(conf => conf["ServiceManager:DiscrepancyService:Load:MaxFailures"])
            .Returns(3.ToString());                     // 4 is discrepancy

            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                mockConfig.Object
                );

            var input = new List <NumericDataPoint>()
            {
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(0),
                    Value     = 93
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-1),
                    Value     = 91
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-2),
                    Value     = 99
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-3),
                    Value     = 95
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-4),
                    Value     = 98
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-5),
                    Value     = 99
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-6),
                    Value     = 98
                },
                new NumericDataPoint {                 // Bad
                    Timestamp = DateTime.UtcNow.AddMinutes(-7),
                    Value     = 90
                }
            };

            // Act
            var actual = discrepancyService
                         .FindHighLoadInDataPoints(
                input,
                new Metric
            {
                Type   = Metrics.CpuLoad.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Empty(actual);
        }