@Test public void testPingAndUpdateJvmStateHttpStatusWithRuntimeException() throws IOException, ExecutionException, InterruptedException { when(mockJvm.getState()).thenReturn(JvmState.JVM_STOPPED); when(Config.mockClientFactoryHelper.requestGet(any(URI.class))).thenThrow(new RuntimeException()); final RemoteCommandReturnInfo remoteCommandReturnInfo = new RemoteCommandReturnInfo(-1, "STOPPED", ""); when(Config.mockJvmStateService.getServiceStatus(eq(mockJvm))).thenReturn(remoteCommandReturnInfo); Future<CurrentState<Jvm, JvmState>> future = jvmStateResolverWorker.pingAndUpdateJvmState(mockJvm, Config.mockJvmStateService); assertNull(future.get()); }
@Async("jvmTaskExecutor") public Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) { LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.", jvm.getJvmName(), jvm.getHostName()); LOGGER.debug("+++ pingAndUpdateJvmState"); ClientHttpResponse response = null; CurrentState<Jvm, JvmState> currentState = null; if (jvm.getState().equals(JvmState.JVM_NEW)){ return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM)); } try { response = clientFactoryHelper.requestGet(jvm.getStatusUri()); LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName()); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM); } catch (final IOException ioe) { LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM); } catch (final RuntimeException rte) { LOGGER.error(rte.getMessage(), rte); } finally { if (response != null) { response.close(); LOGGER.debug("response closed"); } LOGGER.debug("--- pingAndUpdateJvmState"); } return new AsyncResult<>(currentState); }
JvmStateResolverWorker { @Async("jvmTaskExecutor") public Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) { LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.", jvm.getJvmName(), jvm.getHostName()); LOGGER.debug("+++ pingAndUpdateJvmState"); ClientHttpResponse response = null; CurrentState<Jvm, JvmState> currentState = null; if (jvm.getState().equals(JvmState.JVM_NEW)){ return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM)); } try { response = clientFactoryHelper.requestGet(jvm.getStatusUri()); LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName()); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM); } catch (final IOException ioe) { LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM); } catch (final RuntimeException rte) { LOGGER.error(rte.getMessage(), rte); } finally { if (response != null) { response.close(); LOGGER.debug("response closed"); } LOGGER.debug("--- pingAndUpdateJvmState"); } return new AsyncResult<>(currentState); } }
JvmStateResolverWorker { @Async("jvmTaskExecutor") public Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) { LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.", jvm.getJvmName(), jvm.getHostName()); LOGGER.debug("+++ pingAndUpdateJvmState"); ClientHttpResponse response = null; CurrentState<Jvm, JvmState> currentState = null; if (jvm.getState().equals(JvmState.JVM_NEW)){ return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM)); } try { response = clientFactoryHelper.requestGet(jvm.getStatusUri()); LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName()); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM); } catch (final IOException ioe) { LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM); } catch (final RuntimeException rte) { LOGGER.error(rte.getMessage(), rte); } finally { if (response != null) { response.close(); LOGGER.debug("response closed"); } LOGGER.debug("--- pingAndUpdateJvmState"); } return new AsyncResult<>(currentState); }  }
JvmStateResolverWorker { @Async("jvmTaskExecutor") public Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) { LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.", jvm.getJvmName(), jvm.getHostName()); LOGGER.debug("+++ pingAndUpdateJvmState"); ClientHttpResponse response = null; CurrentState<Jvm, JvmState> currentState = null; if (jvm.getState().equals(JvmState.JVM_NEW)){ return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM)); } try { response = clientFactoryHelper.requestGet(jvm.getStatusUri()); LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName()); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM); } catch (final IOException ioe) { LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM); } catch (final RuntimeException rte) { LOGGER.error(rte.getMessage(), rte); } finally { if (response != null) { response.close(); LOGGER.debug("response closed"); } LOGGER.debug("--- pingAndUpdateJvmState"); } return new AsyncResult<>(currentState); }  @Async("jvmTaskExecutor") Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService); }
JvmStateResolverWorker { @Async("jvmTaskExecutor") public Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) { LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.", jvm.getJvmName(), jvm.getHostName()); LOGGER.debug("+++ pingAndUpdateJvmState"); ClientHttpResponse response = null; CurrentState<Jvm, JvmState> currentState = null; if (jvm.getState().equals(JvmState.JVM_NEW)){ return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM)); } try { response = clientFactoryHelper.requestGet(jvm.getStatusUri()); LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName()); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM); } catch (final IOException ioe) { LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe); jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY); currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM); } catch (final RuntimeException rte) { LOGGER.error(rte.getMessage(), rte); } finally { if (response != null) { response.close(); LOGGER.debug("response closed"); } LOGGER.debug("--- pingAndUpdateJvmState"); } return new AsyncResult<>(currentState); }  @Async("jvmTaskExecutor") Future<CurrentState<Jvm, JvmState>> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService);  }