HostRegistryImpl implements HostRegistry { @Override public boolean pingHost( String hostIp ) { WebClient webClient = null; Response response = null; try { webClient = getWebClient( hostIp, "ping" ); response = webClient.get(); if ( response.getStatus() == Response.Status.OK.getStatusCode() ) { return true; } } catch ( Exception e ) { LOG.error( "Error pinging host at ip {}: {}", hostIp, e.getMessage() ); } finally { RestUtil.close( response, webClient ); } return false; }  @Override void updateResourceHostEntryTimestamp( final String resourceHostId ); @Override ContainerHostInfo getContainerHostInfoById( final String id ); @Override ContainerHostInfo getContainerHostInfoByHostname( final String hostname ); @Override ContainerHostInfo getContainerHostInfoByContainerName( final String containerName ); @Override Set<ContainerHostInfo> getContainerHostsInfo(); @Override ResourceHostInfo getResourceHostInfoById( final String id ); @Override ResourceHostInfo getResourceHostInfoByHostname( final String hostname ); @Override Set<ResourceHostInfo> getResourceHostsInfo(); @Override ResourceHostInfo getResourceHostByContainerHost( final ContainerHostInfo containerHostInfo ); @Override HostInfo getHostInfoById( final String hostId ); @Override void removeResourceHost( final String id ); @Override void addHostListener( final HostListener listener ); @Override void removeHostListener( final HostListener listener ); void init(); void dispose(); @Override boolean pingHost( String hostIp );  }
@Test public void testPingHost() { registry.pingHost( HOST_IP ); verify( webClient ).get(); doReturn( Response.Status.OK.getStatusCode() ).when( response ).getStatus(); assertTrue( registry.pingHost( HOST_IP ) ); doReturn( Response.Status.SERVICE_UNAVAILABLE.getStatusCode() ).when( response ).getStatus(); assertFalse( registry.pingHost( HOST_IP ) ); doThrow( new RuntimeException() ).when( webClient ).get(); assertFalse( registry.pingHost( HOST_IP ) ); }