Commit ee13bc20 by Johannes Edmeier

Respect ignored services when detecting stale apps

When having registered some applications via discovery and some via http you can now add the appication names of the non-discovery to the ignored services so that they won't considered as stale an be removed from the registry by the ApplicationDiscoveryListener. fixes #244
parent 4c6aa2be
......@@ -96,7 +96,9 @@ public class ApplicationDiscoveryListener {
protected final Set<String> getAllApplicationIdsFromRegistry() {
Set<String> result = new HashSet<>();
for (Application application : registry.getApplications()) {
result.add(application.getId());
if (!ignoredServices.contains(application.getName())) {
result.add(application.getId());
}
}
return result;
}
......
......@@ -99,7 +99,9 @@ public class ApplicationDiscoveryListenerTest {
@Test
public void deregister_removed_app() {
Object heartbeat = new Object();
registry.register(Application.create("ignored").withHealthUrl("http://health")
.withId("abcdef").build());
listener.setIgnoredServices(Collections.singleton("ignored"));
List<ServiceInstance> instances = new ArrayList<>();
instances.add(new DefaultServiceInstance("service", "localhost", 80, false));
......@@ -108,13 +110,15 @@ public class ApplicationDiscoveryListenerTest {
when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
when(discovery.getInstances("service")).thenReturn(instances);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), heartbeat));
assertEquals(2, registry.getApplications().size());
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(2, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
instances.remove(0);
listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
assertEquals(1, registry.getApplications().size());
assertEquals(1, registry.getApplicationsByName("service").size());
assertEquals(1, registry.getApplicationsByName("ignored").size());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment