use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_service_with_uri_and_metadata_different_port.
@Test
public void should_convert_service_with_uri_and_metadata_different_port() {
Map<String, String> metadata = new HashMap<>();
metadata.put("health.path", "ping");
metadata.put("management.context-path", "mgmt");
metadata.put("management.port", "1234");
metadata.put("management.address", "127.0.0.1");
ServiceInstance service = new TestServiceInstance("test", URI.create("http://localhost/test"), metadata);
Registration registration = new DefaultServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost/test");
assertThat(registration.getManagementUrl()).isEqualTo("http://127.0.0.1:1234/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://127.0.0.1:1234/mgmt/ping");
assertThat(registration.getMetadata()).isEqualTo(metadata);
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_with_custom_defaults.
@Test
public void should_convert_with_custom_defaults() {
DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
converter.setHealthEndpointPath("ping");
converter.setManagementContextPath("mgmt");
ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
Registration registration = converter.convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}
use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.
the class InstanceDiscoveryListenerTest method should_remove_instances_when_they_are_no_longer_available_in_discovery.
@Test
public void should_remove_instances_when_they_are_no_longer_available_in_discovery() {
StepVerifier.create(this.registry.register(Registration.create("ignored", "http://health").build())).consumeNextWith((id) -> {
}).verifyComplete();
StepVerifier.create(this.registry.register(Registration.create("different-source", "http://health2").source("http-api").build())).consumeNextWith((id) -> {
}).verifyComplete();
this.listener.setIgnoredServices(singleton("ignored"));
List<ServiceInstance> instances = new ArrayList<>();
instances.add(new DefaultServiceInstance("test-1", "service", "localhost", 80, false));
instances.add(new DefaultServiceInstance("test-1", "service", "example.net", 80, false));
when(this.discovery.getServices()).thenReturn(singletonList("service"));
when(this.discovery.getInstances("service")).thenReturn(instances);
this.listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
StepVerifier.create(this.registry.getInstances("service")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
StepVerifier.create(this.registry.getInstances("ignored")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("ignored")).verifyComplete();
StepVerifier.create(this.registry.getInstances("different-source")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("different-source")).verifyComplete();
instances.remove(0);
this.listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
StepVerifier.create(this.registry.getInstances("service")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
StepVerifier.create(this.registry.getInstances("ignored")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("ignored")).verifyComplete();
StepVerifier.create(this.registry.getInstances("different-source")).assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("different-source")).verifyComplete();
// shouldn't deregister a second time
this.listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
verify(this.registry, times(1)).deregister(any(InstanceId.class));
}
Aggregations