WorkerRecoveryManagerImpl implements WorkerRecoveryManager { public void doRecovery(){ try { boolean toRestart = Boolean.getBoolean("cloudslang.worker.restart.on.recovery"); if(toRestart){ logger.warn("Worker is configured to restart on recovery and since internal recovery is needed the process is exiting..."); System.exit(EXIT_STATUS); } synchronized (this){ if(inRecovery){ return; } inRecovery = true; } syncManager.startRecovery(); logger.warn("Worker internal recovery started"); for (WorkerRecoveryListener listener : listeners){ try { listener.doRecovery(); } catch (Exception ex) { logger.error("Failed on worker internal recovery", ex); } } if (logger.isDebugEnabled()) logger.debug("Listeners recovery is done"); retryTemplate.retry(RetryTemplate.INFINITELY, 30*1000L, new RetryTemplate.RetryCallback() { @Override public void tryOnce() { if(logger.isDebugEnabled()) logger.debug("sending worker UP"); String newWrv = workerNodeService.up(System.getProperty("worker.uuid"), workerVersionService.getWorkerVersion(), workerVersionService.getWorkerVersionId()); setWRV(newWrv); if(logger.isDebugEnabled()) logger.debug("the worker is UP"); } }); inRecovery = false; logger.warn("Worker recovery is done"); } finally { syncManager.finishRecovery(); } }  void doRecovery(); boolean isInRecovery(); String getWRV(); void setWRV(String newWrv);  }
@Test public void testDoRecovery() throws Exception { Assert.assertEquals(2,workerRecoveryListeners.size()); workerRecoveryManager.doRecovery(); verify(workerRecoveryListeners.get(0),times(1)).doRecovery(); verify(workerRecoveryListeners.get(1),times(1)).doRecovery(); }