CheckExecutor { public void check(Executor executor) { String response; try { response = restClient.check(executor); if (!executor.isAlive()) { onExecutorIsAlive(executor); } } catch (Exception ex) { onHttpCheckFail(executor, ex); return; } if (response == null) { onExecutorWithoutExecution(executor); return; } JsonNode overview; try { overview = toJson(response); } catch (MonitorException ex) { LOG.error("Invalid response from executor: {}\n{}", executor.getAddress(), response, ex); return; } Execution execution; try { execution = getExecution(executor, overview); } catch (MonitorException ex) { LOG.error("Can't get execution for: {}\n{}", executor.getAddress(), response, ex); return; } reportExecutorHasExecution(executor, execution); if (execution == null) { LOG.error("Executor ({}) is running unknown execution.\n{}", executor.getAddress(), response); return; } updateFromOverview(execution, overview); } @Autowired  CheckExecutor(
            ExecutorEventListener listener,
            ExecutorRestClient restClient,
            ExecutionSource executions); void check(Executor executor);  }
@Test public void executorRemainsOffline() { ExecutorEventListener listener = null; ExecutorRestClient client = Mockito.mock(ExecutorRestClient.class); Executor executor = new Executor(null); executor.setAlive(false); Mockito.when(client.check(executor)).thenThrow(new RuntimeException()); (new CheckExecutor(listener, client, null)).check(executor); Assert.assertFalse(executor.isAlive()); }
@Test public void executorBecomesOffline() { ExecutorEventListener listener = Mockito.mock(ExecutorEventListener.class); ExecutorRestClient client = Mockito.mock(ExecutorRestClient.class); Executor executor = new Executor(null); executor.setAlive(true); Mockito.when(client.check(executor)).thenThrow(new RuntimeException()); (new CheckExecutor(listener, client, null)).check(executor); Assert.assertFalse(executor.isAlive()); Mockito.verify(listener, Mockito.times(1)) .onExecutorUnavailable(executor); }