HostRegistryImpl implements HostRegistry { void updateHost( ResourceHostInfo resourceHostInfo ) { WebClient webClient = null; Response response = null; try { webClient = getWebClient( resourceHostInfo.getAddress(), "ping" ); response = webClient.get(); if ( response.getStatus() == Response.Status.OK.getStatusCode() ) { if ( resourceHostInfo instanceof ResourceHost ) { try { getResourceHostInfoById( resourceHostInfo.getId() ); } catch ( HostDisconnectedException e ) { requestHeartbeat( resourceHostInfo ); } } else { updateResourceHostEntryTimestamp( resourceHostInfo.getId() ); } } } catch ( Exception e ) { LOG.error( "Error checking host {}: {}", resourceHostInfo, e.getMessage() ); } finally { RestUtil.close( response, webClient ); } }  @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 testUpdateHost() throws Exception { WebClient webClient = mock( WebClient.class ); doReturn( webClient ).when( registry ).getWebClient( anyString(), anyString() ); Response response = mock( Response.class ); doReturn( response ).when( webClient ).get(); doReturn( Response.Status.OK.getStatusCode() ).when( response ).getStatus(); registry.updateHost( resourceHostInfo ); verify( registry ).updateResourceHostEntryTimestamp( HOST_ID ); ResourceHost resourceHost = mock( ResourceHost.class ); doReturn( HOST_ID ).when( resourceHost ).getId(); registry.updateHost( resourceHost ); verify( registry ).getResourceHostInfoById( HOST_ID ); doThrow( new HostDisconnectedException( null ) ).when( registry ).getResourceHostInfoById( HOST_ID ); registry.updateHost( resourceHost ); verify( registry ).requestHeartbeat( resourceHost ); }