ServerService { public void persistServerOnline() { jobNodeStorage.fillJobNodeIfNullOrOverwrite(ServerNode.getHostNameNode(localHostService.getIp()), localHostService.getHostName()); persistDisabled(); jobNodeStorage.fillEphemeralJobNode(ServerNode.getStatusNode(localHostService.getIp()), ServerStatus.READY); jobNodeStorage.removeJobNodeIfExisted(ServerNode.getShutdownNode(localHostService.getIp())); } ServerService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void clearPreviousServerStatus(); void persistServerOnline(); void clearJobPausedStatus(); boolean isJobPausedManually(); void processServerShutdown(); void updateServerStatus(final ServerStatus status); void removeServerStatus(); List<String> getAllServers(); List<String> getAvailableServers(); boolean isAvailableServer(final String ip); boolean isLocalhostServerReady(); void persistProcessSuccessCount(final int processSuccessCount); void persistProcessFailureCount(final int processFailureCount);  }
@Test public void assertPersistServerOnlineWhenOverwriteDisabled() { jobConfig.setOverwrite(false); serverService.persistServerOnline(); verify(jobNodeStorage).fillJobNodeIfNullOrOverwrite("servers/mockedIP/hostName", "mockedHostName"); verify(localHostService, times(3)).getIp(); verify(localHostService).getHostName(); verify(jobNodeStorage).getJobConfiguration(); verify(jobNodeStorage).fillEphemeralJobNode("servers/mockedIP/status", ServerStatus.READY); verify(jobNodeStorage).removeJobNodeIfExisted("servers/mockedIP/shutdown"); }
@Test public void assertPersistServerOnlineForDisabledServerWithLeaderElecting() { jobConfig.setDisabled(true); serverService.persistServerOnline(); verify(jobNodeStorage).fillJobNodeIfNullOrOverwrite("servers/mockedIP/hostName", "mockedHostName"); verify(localHostService, times(4)).getIp(); verify(localHostService).getHostName(); verify(jobNodeStorage, times(2)).getJobConfiguration(); verify(jobNodeStorage).fillJobNodeIfNullOrOverwrite("servers/mockedIP/disabled", ""); verify(jobNodeStorage).fillEphemeralJobNode("servers/mockedIP/status", ServerStatus.READY); verify(jobNodeStorage).removeJobNodeIfExisted("servers/mockedIP/shutdown"); }
@Test public void assertPersistServerOnlineForEnabledServer() { serverService.persistServerOnline(); verify(jobNodeStorage).fillJobNodeIfNullOrOverwrite("servers/mockedIP/hostName", "mockedHostName"); verify(localHostService, times(4)).getIp(); verify(localHostService).getHostName(); verify(jobNodeStorage, times(2)).getJobConfiguration(); verify(jobNodeStorage).removeJobNodeIfExisted("servers/mockedIP/disabled"); verify(jobNodeStorage).fillEphemeralJobNode("servers/mockedIP/status", ServerStatus.READY); }