public async Task CanCallRouterHealthCheck() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/myservice3"; fixture.AddService(serviceName1, route1); fixture.AddRouter(); fixture.StartAll(); await fixture.WaitForRegistrationAsync(); var responseService = await fixture.CallRouterAsync("/myservice3"); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); var routerResponse = await fixture.CallRouterAsync("/admin/condenser/health"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); routerResponse = await fixture.CallRouterAsync("/admin/condenser/healthstats"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); var content = await routerResponse.Content.ReadAsStringAsync(); var health = JsonConvert.DeserializeObject <HealthResponse>(content); Assert.Equal(1, health.Stats.Http200Responses); } }
public async Task CanCallRouterStatisticsForRegisteredService() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/customer"; fixture.AddService(serviceName1, route1); fixture.AddRouter(); fixture.StartAll(); await fixture.WaitForRegistrationAsync(); await Task.Delay(1500); var responseService = await fixture.CallRouterAsync(route1); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); var routerResponse = await fixture.CallRouterAsync("/admin/condenser/server/" + serviceName1); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); var content = await routerResponse.Content.GetObject <ServerStats[]>(); var server = content[0]; Assert.Equal(1, server.Calls); Assert.Equal(1, server.Summary.Http200Responses); Assert.Equal(DateTime.Now.Date, server.LastRequest.Date); Assert.True(server.LastRequestTime > 0, "last request time not recorded"); Assert.True(server.AverageRequestTime > 0, "average request time not recorded"); } }
public async Task CanCallRouterTreeForRegisteredService() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/myservice2"; fixture.AddService(serviceName1, route1); fixture.AddRouter(); fixture.StartAll(); await fixture.WaitForRegistrationAsync(); var responseService = await fixture.CallRouterAsync("/myservice2"); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); var routerResponse = await fixture.CallRouterAsync("/admin/condenser/tree"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); var content = await routerResponse.Content.ReadAsStringAsync(); var node = JsonConvert.DeserializeObject <Node>(content); Assert.NotNull(node); } }
public async Task CanWeRunRegisteredServicesThroughRouter() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/test1"; var serviceName2 = fixture.GetNewServiceName(); var route2 = "/test2"; fixture.AddService(serviceName1, route1) .AddService(serviceName2, route2); fixture.AddRouter(); fixture.StartAll(); if (!fixture.AreAllRegistered()) { await fixture.WaitForRegistrationAsync(); } var response = await fixture.CallRouterAsync(route1); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var content = await response.Content.ReadAsStringAsync(); Assert.Equal("Called me " + serviceName1, content); response = await fixture.CallRouterAsync(route2); Assert.Equal(HttpStatusCode.OK, response.StatusCode); content = await response.Content.ReadAsStringAsync(); Assert.Equal("Called me " + serviceName2, content); } }
public async Task CanCallRouterSummaryForRegisteredService() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/otherroute"; fixture.AddService(serviceName1, route1); fixture.AddRouter(); fixture.StartAll(); await fixture.WaitForRegistrationAsync(); var responseService = await fixture.CallRouterAsync(route1); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); var routerResponse = await fixture.CallRouterAsync("/admin/condenser/routes/summmary"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); var content = await routerResponse.Content.ReadAsStringAsync(); /*Error on travis at the moment on deserialise * var items = JsonConvert.DeserializeObject<List<Summary>>(content); * * var registration = items.SingleOrDefault(x => x.Service == serviceName1); * * Assert.NotNull(registration); * * Assert.Equal(1, registration.Nodes.Length); * * Assert.Equal(Environment.MachineName.ToLower(), registration.Nodes[0].NodeId.ToLower()); * Assert.Equal((serviceName1 + ":" + Environment.MachineName).ToLower(), * registration.Nodes[0].ServiceId.ToLower()); * Assert.Equal(new[] { route1 }, registration.Nodes[0].Routes); * Assert.Equal(new[] { "urlprefix-" + route1 }, registration.Nodes[0].Tags);*/ } }
public async Task CanCallRouterWithDifferentRouterStrategies() { using (var fixture = new RoutingFixture()) { var serviceName1 = fixture.GetNewServiceName(); var route1 = "/data"; var strategyOne = new StrategyOne(); var strategyTwo = new StrategyTwo(); fixture.AddService(serviceName1, route1); fixture.AddRouter(strategyOne, strategyTwo); fixture.StartAll(); await fixture.WaitForRegistrationAsync(); var routerResponse = await fixture.CallRouterAsync("/admin/condenser/router/replace?strategy=One"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); var responseService = await fixture.CallRouterAsync(route1); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); Assert.True(strategyOne.Called, "strategy one was not called"); routerResponse = await fixture.CallRouterAsync("/admin/condenser/router/replace?strategy=Two"); Assert.Equal(HttpStatusCode.OK, routerResponse.StatusCode); responseService = await fixture.CallRouterAsync(route1); Assert.Equal(HttpStatusCode.OK, responseService.StatusCode); Assert.True(strategyTwo.Called, "strategy two was not called"); } }