diff --git a/service-discovery-ft/src/test/java/com/generoso/ft/sd/client/MetricsClientRequest.java b/service-discovery-ft/src/test/java/com/generoso/ft/sd/client/MetricsClientRequest.java index dc92ca3..5267f32 100644 --- a/service-discovery-ft/src/test/java/com/generoso/ft/sd/client/MetricsClientRequest.java +++ b/service-discovery-ft/src/test/java/com/generoso/ft/sd/client/MetricsClientRequest.java @@ -1,6 +1,5 @@ package com.generoso.ft.sd.client; -import org.hawkular.agent.prometheus.PrometheusMetricsProcessor; import org.hawkular.agent.prometheus.text.TextPrometheusMetricsProcessor; import org.hawkular.agent.prometheus.types.MetricFamily; import org.hawkular.agent.prometheus.walkers.CollectorPrometheusMetricsWalker; @@ -8,9 +7,6 @@ import org.springframework.stereotype.Component; import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.util.List; @@ -24,19 +20,15 @@ public class MetricsClientRequest { private Client client; public List collectMetrics() { - try { - HttpResponse response = client.execute(privateMetricsRequestTemplate); - return parsePrometheusMetrics(response.body()); - } catch (IOException e) { - throw new RuntimeException("Unable to gather metrics", e); - } + var response = client.execute(privateMetricsRequestTemplate); + return parsePrometheusMetrics(response.body()); } - private List parsePrometheusMetrics(String metricEndpointResponseBody) throws IOException { - InputStream inputStream = new ByteArrayInputStream(metricEndpointResponseBody.getBytes(StandardCharsets.UTF_8)); + private List parsePrometheusMetrics(String metricEndpointResponseBody) { + var inputStream = new ByteArrayInputStream(metricEndpointResponseBody.getBytes(StandardCharsets.UTF_8)); - CollectorPrometheusMetricsWalker collector = new CollectorPrometheusMetricsWalker(); - PrometheusMetricsProcessor processor = new TextPrometheusMetricsProcessor(inputStream, collector); + var collector = new CollectorPrometheusMetricsWalker(); + var processor = new TextPrometheusMetricsProcessor(inputStream, collector); processor.walk(); return collector.getAllMetricFamilies(); diff --git a/service-discovery-ft/src/test/java/com/generoso/ft/sd/config/TestConfiguration.java b/service-discovery-ft/src/test/java/com/generoso/ft/sd/config/TestConfiguration.java index ea92429..1e31edb 100644 --- a/service-discovery-ft/src/test/java/com/generoso/ft/sd/config/TestConfiguration.java +++ b/service-discovery-ft/src/test/java/com/generoso/ft/sd/config/TestConfiguration.java @@ -1,15 +1,15 @@ package com.generoso.ft.sd.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.generoso.ft.sd.client.model.Endpoint; import com.generoso.ft.sd.client.RequestTemplate; +import com.generoso.ft.sd.client.model.Endpoint; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import java.net.http.HttpClient; -import java.util.HashMap; +import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -29,16 +29,18 @@ public HttpClient httpClient() { @Bean public Map privateRequestTemplates( - @Qualifier("private") List templates) { - var map = new HashMap(templates.size()); - templates.forEach(t -> map.put(t.getEndpoint(), t)); - return map; + @Qualifier("private") List templates) { + return buildMap(templates); } @Bean public Map requestTemplates( - @Qualifier("service-request") List templates) { - var map = new HashMap(templates.size()); + @Qualifier("service-request") List templates) { + return buildMap(templates); + } + + private Map buildMap(@Qualifier("service-request") List templates) { + var map = new EnumMap(Endpoint.class); templates.forEach(t -> map.put(t.getEndpoint(), t)); return map; } diff --git a/service-discovery-ft/src/test/java/com/generoso/ft/sd/steps/RequestStepDefinitions.java b/service-discovery-ft/src/test/java/com/generoso/ft/sd/steps/RequestStepDefinitions.java index c5bd947..0e83dce 100644 --- a/service-discovery-ft/src/test/java/com/generoso/ft/sd/steps/RequestStepDefinitions.java +++ b/service-discovery-ft/src/test/java/com/generoso/ft/sd/steps/RequestStepDefinitions.java @@ -56,52 +56,54 @@ private RequestTemplate getRequestTemplate(Endpoint endpoint) { static { bodyMap = new HashMap<>(); - bodyMap.put("APP_NAME", "{\n" + - " \"instance\": {\n" + - " \"instanceId\": \"5784ed89d3cf:gateway:8080\",\n" + - " \"app\": \"APP_NAME\",\n" + - " \"appGroupName\": null,\n" + - " \"ipAddr\": \"172.20.0.3\",\n" + - " \"sid\": \"na\",\n" + - " \"homePageUrl\": \"http://172.20.0.3:8080/\",\n" + - " \"statusPageUrl\": \"http://172.20.0.3:8080/actuator/info\",\n" + - " \"healthCheckUrl\": \"http://172.20.0.3:8080/actuator/health\",\n" + - " \"secureHealthCheckUrl\": null,\n" + - " \"vipAddress\": \"app_name\",\n" + - " \"secureVipAddress\": \"app_name\",\n" + - " \"countryId\": 1,\n" + - " \"dataCenterInfo\": {\n" + - " \"@class\": \"com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo\",\n" + - " \"name\": \"MyOwn\"\n" + - " },\n" + - " \"hostName\": \"172.20.0.3\",\n" + - " \"status\": \"UP\",\n" + - " \"overriddenStatus\": \"UNKNOWN\",\n" + - " \"leaseInfo\": {\n" + - " \"renewalIntervalInSecs\": 30,\n" + - " \"durationInSecs\": 90,\n" + - " \"registrationTimestamp\": 0,\n" + - " \"lastRenewalTimestamp\": 0,\n" + - " \"evictionTimestamp\": 0,\n" + - " \"serviceUpTimestamp\": 0\n" + - " },\n" + - " \"isCoordinatingDiscoveryServer\": false,\n" + - " \"lastUpdatedTimestamp\": 1658954363496,\n" + - " \"lastDirtyTimestamp\": 1658954365828,\n" + - " \"actionType\": null,\n" + - " \"asgName\": null,\n" + - " \"port\": {\n" + - " \"$\": 8080,\n" + - " \"@enabled\": \"true\"\n" + - " },\n" + - " \"securePort\": {\n" + - " \"$\": 443,\n" + - " \"@enabled\": \"false\"\n" + - " },\n" + - " \"metadata\": {\n" + - " \"management.port\": \"8080\"\n" + - " }\n" + - " }\n" + - "}"); + bodyMap.put("APP_NAME", """ + { + "instance": { + "instanceId": "5784ed89d3cf:gateway:8080", + "app": "APP_NAME", + "appGroupName": null, + "ipAddr": "172.20.0.3", + "sid": "na", + "homePageUrl": "http://172.20.0.3:8080/", + "statusPageUrl": "http://172.20.0.3:8080/actuator/info", + "healthCheckUrl": "http://172.20.0.3:8080/actuator/health", + "secureHealthCheckUrl": null, + "vipAddress": "app_name", + "secureVipAddress": "app_name", + "countryId": 1, + "dataCenterInfo": { + "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", + "name": "MyOwn" + }, + "hostName": "172.20.0.3", + "status": "UP", + "overriddenStatus": "UNKNOWN", + "leaseInfo": { + "renewalIntervalInSecs": 30, + "durationInSecs": 90, + "registrationTimestamp": 0, + "lastRenewalTimestamp": 0, + "evictionTimestamp": 0, + "serviceUpTimestamp": 0 + }, + "isCoordinatingDiscoveryServer": false, + "lastUpdatedTimestamp": 1658954363496, + "lastDirtyTimestamp": 1658954365828, + "actionType": null, + "asgName": null, + "port": { + "$": 8080, + "@enabled": "true" + }, + "securePort": { + "$": 443, + "@enabled": "false" + }, + "metadata": { + "management.port": "8080" + } + } + } + """); } } diff --git a/service-discovery-ft/src/test/resources/test.yml b/service-discovery-ft/src/test/resources/test.yml index e54b851..193564a 100644 --- a/service-discovery-ft/src/test/resources/test.yml +++ b/service-discovery-ft/src/test/resources/test.yml @@ -1,6 +1,6 @@ spring: jmx: - enable: false + enabled: false application: name: sd-functional-tests profiles: