use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method test_ignore.
@Test
public void test_ignore() {
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
listener.setIgnoredServices(singleton("service"));
listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
assertEquals(0, registry.getApplications().size());
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method test_register_and_convert.
@Test
public void test_register_and_convert() {
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
assertEquals(1, registry.getApplications().size());
Application application = registry.getApplications().iterator().next();
assertEquals("http://localhost:80/health", application.getHealthUrl());
assertEquals("http://localhost:80", application.getManagementUrl());
assertEquals("http://localhost:80", application.getServiceUrl());
assertEquals("service", application.getName());
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method test_ignore_pattern.
@Test
public void test_ignore_pattern() {
when(discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
listener.setIgnoredServices(singleton("rabbit-*"));
listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
Collection<Application> applications = registry.getApplications();
assertEquals(1, applications.size());
assertEquals("service", applications.iterator().next().getName());
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method single_discovery_for_same_heartbeat.
@Test
public void single_discovery_for_same_heartbeat() {
Object heartbeat = new Object();
listener.onParentHeartbeat(new ParentHeartbeatEvent(new Object(), heartbeat));
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
listener.onApplicationEvent(new HeartbeatEvent(new Object(), heartbeat));
assertEquals(0, registry.getApplications().size());
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(1, registry.getApplications().size());
}
use of org.springframework.cloud.client.DefaultServiceInstance in project spring-boot-admin by codecentric.
the class ApplicationDiscoveryListenerTest method deregister_removed_app.
@Test
public void deregister_removed_app() {
registry.register(Application.create("ignored").withHealthUrl("http://health").withId("abcdef").build());
registry.register(Application.create("different-source").withHealthUrl("http://health2").withId("abcdef").withSource("http-api").build());
listener.setIgnoredServices(singleton("ignored"));
List<ServiceInstance> instances = new ArrayList<>();
instances.add(new DefaultServiceInstance("service", "localhost", 80, false));
instances.add(new DefaultServiceInstance("service", "example.net", 80, false));
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(instances);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(2, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
assertEquals(1, registry.getApplicationsByName("different-source").size());
instances.remove(0);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(1, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
assertEquals(1, registry.getApplicationsByName("different-source").size());
}
Aggregations