@Test public void should_retry() { Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}"; wireMock.stubFor(get("/mgmt").inScenario("retry") .whenScenarioStateIs(STARTED) .willReturn(aResponse().withFixedDelay(5000)) .willSetStateTo("recovered")); wireMock.stubFor(get("/mgmt").inScenario("retry") .whenScenarioStateIs("recovered") .willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON) .withHeader("Content-Length", Integer.toString(body.length()) ))); QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info")) .verifyComplete(); }
@Override public Mono<Endpoints> detectEndpoints(Instance instance) { Registration registration = instance.getRegistration(); String managementUrl = registration.getManagementUrl(); if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) { return Mono.empty(); } return instanceWebClient.instance(instance) .get() .uri(managementUrl) .exchange() .flatMap(response -> { if (response.statusCode().is2xxSuccessful() && response.headers() .contentType() .map(actuatorMediaType::isCompatibleWith) .orElse(false)) { return response.bodyToMono(Response.class); } else { return response.bodyToMono(Void.class).then(Mono.empty()); } }) .flatMap(this::convert); }
QueryIndexEndpointStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { Registration registration = instance.getRegistration(); String managementUrl = registration.getManagementUrl(); if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) { return Mono.empty(); } return instanceWebClient.instance(instance) .get() .uri(managementUrl) .exchange() .flatMap(response -> { if (response.statusCode().is2xxSuccessful() && response.headers() .contentType() .map(actuatorMediaType::isCompatibleWith) .orElse(false)) { return response.bodyToMono(Response.class); } else { return response.bodyToMono(Void.class).then(Mono.empty()); } }) .flatMap(this::convert); } }
QueryIndexEndpointStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { Registration registration = instance.getRegistration(); String managementUrl = registration.getManagementUrl(); if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) { return Mono.empty(); } return instanceWebClient.instance(instance) .get() .uri(managementUrl) .exchange() .flatMap(response -> { if (response.statusCode().is2xxSuccessful() && response.headers() .contentType() .map(actuatorMediaType::isCompatibleWith) .orElse(false)) { return response.bodyToMono(Response.class); } else { return response.bodyToMono(Void.class).then(Mono.empty()); } }) .flatMap(this::convert); } QueryIndexEndpointStrategy(InstanceWebClient instanceWebClient); }
QueryIndexEndpointStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { Registration registration = instance.getRegistration(); String managementUrl = registration.getManagementUrl(); if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) { return Mono.empty(); } return instanceWebClient.instance(instance) .get() .uri(managementUrl) .exchange() .flatMap(response -> { if (response.statusCode().is2xxSuccessful() && response.headers() .contentType() .map(actuatorMediaType::isCompatibleWith) .orElse(false)) { return response.bodyToMono(Response.class); } else { return response.bodyToMono(Void.class).then(Mono.empty()); } }) .flatMap(this::convert); } QueryIndexEndpointStrategy(InstanceWebClient instanceWebClient); @Override Mono<Endpoints> detectEndpoints(Instance instance); }
QueryIndexEndpointStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { Registration registration = instance.getRegistration(); String managementUrl = registration.getManagementUrl(); if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) { return Mono.empty(); } return instanceWebClient.instance(instance) .get() .uri(managementUrl) .exchange() .flatMap(response -> { if (response.statusCode().is2xxSuccessful() && response.headers() .contentType() .map(actuatorMediaType::isCompatibleWith) .orElse(false)) { return response.bodyToMono(Response.class); } else { return response.bodyToMono(Void.class).then(Mono.empty()); } }) .flatMap(this::convert); } QueryIndexEndpointStrategy(InstanceWebClient instanceWebClient); @Override Mono<Endpoints> detectEndpoints(Instance instance);  }