Ejemplo n.º 1
0
        public void GetMetricsByPercentileFromAllCluster()
        {
            var fromTime   = new DateTime(2012, 11, 11);
            var toTime     = new DateTime(2013, 11, 11);
            var percentile = Percentile.P99;

            var result = _controller.GetMetricsByPercentileFromAllCluster(fromTime, toTime, percentile);

            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
Ejemplo n.º 2
0
        public void GetMetricsByPercentileFromAllCluster_ReturnsOk()
        {
            //Arrange
            var fromTime   = TimeSpan.FromSeconds(0);
            var toTime     = TimeSpan.FromSeconds(100);
            var percentile = Percentile.P95;

            //Act
            var result = _controller.GetMetricsByPercentileFromAllCluster(fromTime, toTime, percentile);

            // Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetMetricsByPercentileFromClusters__ShouldCall_From_Repository()
        {
            //Arrange
            var fromTime   = DateTimeOffset.MinValue;
            var toTime     = DateTimeOffset.Now;
            var percentile = Percentile.P90;

            mockAgentsRepository
            .Setup(repository => repository.GetAllAgentsInfo())
            .Returns(GetTestAgentsInfo().FindAll(m => (m.AgentId <= 2)));

            mockRepository.
            Setup(repository => repository.GetInTimePeriodPercentile(
                      It.Is <int>(agentId => agentId == 2),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <Percentile>())).
            Returns(GetTestMetric().FindAll(m => m.AgentId == 2)[1]);

            mockRepository.
            Setup(repository => repository.GetInTimePeriodPercentile(
                      It.Is <int>(agentId => agentId == 1),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <Percentile>())).
            Returns(GetTestMetric().FindAll(m => m.AgentId == 1)[0]);

            //Act
            var result = controller.GetMetricsByPercentileFromAllCluster(fromTime, toTime, percentile);

            // Assert
            var expected    = mapper.Map <HddMetricDto>(GetTestMetric()[1]);
            var response    = ((result as OkObjectResult).Value as AllHddMetricsResponse);
            var checkResult = false;

            for (int i = 0; i < response.Metrics.Count; i++)
            {
                if ((response.Metrics[i].Value != expected.Value) ||
                    (response.Metrics[i].Time != expected.Time) ||
                    (response.Metrics[i].AgentId != expected.AgentId))
                {
                    checkResult = true;
                    break;
                }
            }

            Assert.True(checkResult);
        }
        public void GetMetricsByPercentileFromAllCluster_ReturnsOk()
        {
            //Arrange
            var request = new HddMetricGetByIntervalForClusterRequest()
            {
                FromTime = DateTimeOffset.MinValue,
                ToTime   = DateTimeOffset.Now
            };
            var percentile = Percentile.P95;

            //фейковые данные об агентах
            var mockAgentsInfo = new AllAgentsInfo();

            mockAgentsInfo.Agents.Add(new AgentInfo()
            {
                AgentId = 1, AgentUri = "url1"
            });
            mockAgentsInfo.Agents.Add(new AgentInfo()
            {
                AgentId = 2, AgentUri = "url2"
            });

            mockAgentsRepository.
            Setup(repository => repository.GetAllAgentsInfo()).
            Returns(mockAgentsInfo);

            //фейковые метрики возвращаемые репозиторием для всех агентов
            var mockMetrics = new AllMetrics <HddMetric>();

            mockMetrics.Metrics.Add(new HddMetric()
            {
                AgentId = 1, Time = DateTimeOffset.MinValue, Value = 100
            });
            mockMetrics.Metrics.Add(new HddMetric()
            {
                AgentId = 2, Time = DateTimeOffset.UtcNow, Value = 122
            });

            //фейковые метрики возвращаемые репозиторием для первого агента
            var mockMetricsForAgent_1 = new AllMetrics <HddMetric>();

            mockMetricsForAgent_1.Metrics.Add(mockMetrics.Metrics[0]);
            //фейковые метрики возвращаемые репозиторием для второго агента
            var mockMetricsForAgent_2 = new AllMetrics <HddMetric>();

            mockMetricsForAgent_2.Metrics.Add(mockMetrics.Metrics[1]);

            mockRepository.
            Setup(repository => repository.GetByTimeIntervalPercentile(
                      It.Is <int>(agentId => agentId == 1),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <Percentile>())).
            Returns(mockMetricsForAgent_1);
            mockRepository.
            Setup(repository => repository.GetByTimeIntervalPercentile(
                      It.Is <int>(agentId => agentId == 2),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <Percentile>())).
            Returns(mockMetricsForAgent_2);

            //Act
            var result = controller.GetMetricsByPercentileFromAllCluster(request, percentile);

            // Assert
            Assert.True(CompareMetricsContainers(result, mockMetrics));
        }