public void GetEndpoint_should_return_filtered_endpoints(string filterStatus, string filterTags, string filterGroup, string filterText, string expectedEndpointIds) { var endpoints = new[] { new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.Parse("11111111-1111-1111-1111-111111111111"), "monitorType1", "address1"), new EndpointMetadata("nam", "group11", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)) .UpdateHealth(new EndpointHealth(DateTime.MinValue, TimeSpan.Zero, EndpointStatus.Healthy)), new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.Parse("22222222-2222-2222-2222-222222222222"), "monitorType1", "address2"), new EndpointMetadata("name2", "group2", new[] { "t2", "t3" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)) .UpdateHealth(new EndpointHealth(DateTime.MinValue, TimeSpan.Zero, EndpointStatus.Unhealthy)), new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.Parse("33333333-3333-3333-3333-333333333333"), "monitorType2", "address123"), new EndpointMetadata("name3", "group2", new[] { "t1", "t2", "t3" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)) .UpdateHealth(new EndpointHealth(DateTime.MinValue, TimeSpan.Zero, EndpointStatus.Faulty)) }; _endpointRegistry.Setup(r => r.Endpoints).Returns(endpoints); var results = _controller.GetEndpoints(filterStatus?.Split(','), filterTags?.Split(','), filterGroup, filterText).ToArray(); var expected = expectedEndpointIds?.Split(',') ?? new string[0]; Assert.Equal( expected.OrderBy(e => e).ToArray(), results.Select(r => r.Id.ToString()).OrderBy(e => e).ToArray()); }
public EndpointMetricsForwarderCoordinatorTest() { var endpointId = Guid.NewGuid(); var health = new EndpointHealth(DateTime.UtcNow, TimeSpan.FromSeconds(1), EndpointStatus.Healthy); _endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(endpointId, "type", "Address"), new EndpointMetadata("Name", "Group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); _endpoint.UpdateHealth(health); _forwarder = new Mock <IEndpointMetricsForwarder>(); _duplicateForwarder = new Mock <IEndpointMetricsForwarder>(); }
public void GetEndpointsIdentities_should_return_all_registered_endpoints_if_no_monitor_tag_specified() { var endpoints = new[] { new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.NewGuid(), "monitor1", "address1"), new EndpointMetadata("name", "group", new string[0], EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)), new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.NewGuid(), "monitor2", "address2"), new EndpointMetadata("name", "group", new string[0], "monitorTag1", DateTime.UtcNow, DateTime.UtcNow)), new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.NewGuid(), "monitor3", "address3"), new EndpointMetadata("name", "group", new string[0], "monitorTag2", DateTime.UtcNow, DateTime.UtcNow)) }; _endpointRegistry.Setup(r => r.Endpoints).Returns(endpoints); var actual = _controller.GetEndpointsIdentities(); Assert.Equal(endpoints.Select(e => e.Identity), actual); }
public void GetEndpoints_should_return_all_endpoints() { var endpoints = new[] { new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.NewGuid(), "a", "b"), new EndpointMetadata("c", "d", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)), new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(Guid.NewGuid(), "e", "f"), new EndpointMetadata("g", "h", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)) }; _endpointRegistry.Setup(r => r.Endpoints).Returns(endpoints); var results = _controller.GetEndpoints().ToArray(); foreach (var endpoint in endpoints) { AssertEndpoint(endpoint, results.SingleOrDefault(r => r.Id == endpoint.Identity.Id)); } }
public void GetEndpoint_should_return_endpoint_information() { var id = Guid.NewGuid(); var endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(id, "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, _utcNow, _utcNow)); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult <EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(EndpointStatus.NotRun, result.Content.Status); Assert.Equal(null, result.Content.LastCheckUtc); Assert.Equal(null, result.Content.LastResponseTime); Assert.Equal(new Dictionary <string, string>(), result.Content.Details); Assert.Equal(endpoint.LastModifiedTimeUtc, result.Content.LastModifiedTime); }
public void RecordEndpointStatistics_should_save_statistics() { var repository = new Mock <IEndpointStatsRepository>(); var monitorSettings = new Mock <IMonitorSettings>(); var endpointMetricsCoordinator = new Mock <IEndpointMetricsForwarderCoordinator>(); var endpointHealth = new EndpointHealth(DateTime.UtcNow, TimeSpan.Zero, EndpointStatus.Offline); var endpointId = Guid.NewGuid(); var endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(endpointId, "type", "address"), new EndpointMetadata("name", "group", null, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); using (var manager = new EndpointStatsManager(repository.Object, monitorSettings.Object, TimeCoordinatorMock.Get().Object, endpointMetricsCoordinator.Object)) { manager.RecordEndpointStatistics(endpoint.Identity, endpoint.Metadata, endpointHealth); } repository.Verify(r => r.InsertEndpointStatistics(endpointId, endpointHealth)); }
public void GetEndpoint_should_return_endpoint_information_with_details(EndpointStatus status) { var id = Guid.NewGuid(); var endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(id, "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); var endpointHealth = new EndpointHealth(_utcNow, TimeSpan.FromSeconds(5), status, new Dictionary <string, string> { { "abc", "def" } }); endpoint.UpdateHealth(endpointHealth); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult <EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(status, result.Content.Status); Assert.Equal(endpointHealth.CheckTimeUtc, result.Content.LastCheckUtc); Assert.Equal(endpointHealth.ResponseTime, result.Content.LastResponseTime); Assert.Equal(endpointHealth.Details, result.Content.Details); }