use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method test_convert_with_custom_defaults.
@Test
public void test_convert_with_custom_defaults() {
DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
converter.setHealthEndpointPath("ping");
converter.setManagementContextPath("mgmt");
ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
Application application = converter.convert(service);
assertThat(application.getId(), nullValue());
assertThat(application.getName(), is("test"));
assertThat(application.getServiceUrl(), is("http://localhost:80"));
assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method test_convert_with_defaults.
@Test
public void test_convert_with_defaults() {
ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
Application application = new DefaultServiceInstanceConverter().convert(service);
assertThat(application.getId(), nullValue());
assertThat(application.getName(), is("test"));
assertThat(application.getServiceUrl(), is("http://localhost:80"));
assertThat(application.getManagementUrl(), is("http://localhost:80"));
assertThat(application.getHealthUrl(), is("http://localhost:80/health"));
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class TurbineRouteLocatorTest method test_route_service_location.
@Test
public void test_route_service_location() {
ZuulRoute route = new ZuulRoute("/path/**", "turbine");
DiscoveryClient discovery = mock(DiscoveryClient.class);
when(discovery.getInstances("turbine")).thenReturn(Arrays.<ServiceInstance>asList(new DefaultServiceInstance("turbine", "example.com", 80, false)));
TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), discovery);
Route matchingRoute = locator.getMatchingRoute("/path/foo");
assertThat(matchingRoute.getLocation(), is("http://example.com:80"));
assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
}
use of org.springframework.cloud.client.DefaultServiceInstance in project java-chassis by ServiceComb.
the class CseDiscoveryClient method getInstances.
@Override
public List<ServiceInstance> getInstances(final String serviceId) {
List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
String versionRule = referenceConfig.getMicroserviceVersionRule();
String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
if (null != cseServices && !cseServices.isEmpty()) {
for (MicroserviceInstance instance : cseServices) {
List<String> eps = instance.getEndpoints();
for (String ep : eps) {
URIEndpointObject uri = new URIEndpointObject(ep);
instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
}
}
}
return instances;
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method test_matching_and_ignore_pattern.
@Test
public void test_matching_and_ignore_pattern() {
when(discovery.getServices()).thenReturn(asList("service-1", "service", "rabbit-1", "rabbit-2"));
when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
when(discovery.getInstances("service-1")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service-1", "localhost", 80, false)));
listener.setServices(singleton("ser*"));
listener.setIgnoredServices(singleton("service-*"));
listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
Collection<Application> applications = registry.getApplications();
assertEquals(1, applications.size());
assertEquals("service", applications.iterator().next().getName());
}
Aggregations