### Question:
ProbeEndpointsStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { return Flux.fromIterable(endpoints) .flatMap(endpoint -> detectEndpoint(instance, endpoint)) .collectList() .flatMap(this::convert); } ProbeEndpointsStrategy(InstanceWebClient instanceWebClient, String[] endpoints); @Override Mono<Endpoints> detectEndpoints(Instance instance);  }### Answer:
@Test public void should_return_detect_endpoints() { Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound())); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(instanceWebClient, new String[]{"metrics:stats", "metrics", "info", "non-exist"} ); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("metrics", wireMock.url("/mgmt/stats")) .withEndpoint("info", wireMock.url("/mgmt/info"))) .verifyComplete(); }
@Test public void should_return_empty() { Instance instance = Instance.create(InstanceId.of("id")) .register(Registration.create("test", wireMock.url("/mgmt/health")) .managementUrl(wireMock.url("/mgmt")) .build()); wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(aResponse().withStatus(HttpStatus.NOT_FOUND_404))); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(instanceWebClient, new String[]{"metrics:stats"}); StepVerifier.create(strategy.detectEndpoints(instance)) .verifyComplete(); }
@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()); wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry") .whenScenarioStateIs(STARTED) .willReturn(aResponse().withFixedDelay(5000)) .willSetStateTo("recovered")); wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry") .whenScenarioStateIs("recovered") .willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok())); wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound())); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(instanceWebClient, new String[]{"metrics:stats", "metrics", "info", "non-exist"} ); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("metrics", wireMock.url("/mgmt/stats")) .withEndpoint("info", wireMock.url("/mgmt/info"))) .verifyComplete(); }