EurekaAgentStatusMonitor implements AgentStatusMonitor, EurekaEventListener { @Override public AgentStatus getStatus(String agentInstanceId) { AgentInstance agentInstance = agentManagementService.getAgentInstance(agentInstanceId); Pair<InstanceStatus, AgentStatus> current = statusByInstanceId.get(agentInstance.getId()); if (current == null) { return AgentStatus.unhealthy(SOURCE_ID, agentInstance, "Not registered with Eureka", System.currentTimeMillis()); } return current.getRight(); } @Inject  EurekaAgentStatusMonitor(EurekaClient eurekaClient, AgentManagementService agentManagementService, Registry registry); @Activator void enterActiveMode(); @Override AgentStatus getStatus(String agentInstanceId); @Override boolean isHealthy(String agentInstanceId); @Override Observable<AgentStatus> monitor(); @Override void onEvent(EurekaEvent event);  }
@Test public void testInstanceUpInEurekaIsHealthy() { mockStatusInEureka(instance, InstanceStatus.UP); AgentStatus status = monitor.getStatus(instance.getId()); assertThat(status.getStatusCode()).isEqualTo(AgentStatusCode.Healthy); }
@Test public void testInstanceNotUpInEurekaIsUnhealthy() { for (InstanceStatus status : asList(InstanceStatus.DOWN, InstanceStatus.STARTING, InstanceStatus.OUT_OF_SERVICE, InstanceStatus.UNKNOWN)) { mockStatusInEureka(instance, status); AgentStatus agentStatus = monitor.getStatus(instance.getId()); assertThat(agentStatus.getStatusCode()).isEqualTo(AgentStatusCode.Unhealthy); } }
@Test public void testInstanceNotRegisteredWithEurekaIsUnhealthy() { AgentStatus status = monitor.getStatus(instance.getId()); assertThat(status.getStatusCode()).isEqualTo(AgentStatusCode.Unhealthy); }