AdministrationAgent implements InitializingBean { protected void putHostInMaintenance(long hostId) { try { resourceManager.maintain(hostId); } catch (Exception e) { throw new CloudRuntimeException(String.format("Problems while putting host [id=%d] on maintenance", hostId), e); } do { threadUtils.sleepThread(3); if (hostService.isHostInMaintenanceError(hostId)) { throw new CloudRuntimeException(String.format("Error while sending the maintenance command to host [id=%d]", hostId)); } } while (hostService.isHostInPreparedForMaintenance(hostId)); }  void receiveClusterToBeManaged(Long clusterId); Long searchClusterToBeManaged(); List<ClusterResourcesUp> createAllClustersResourcesUp(); @Override void afterPropertiesSet();  }
@Test public void putHostInMaintenanceTestSmoothExecution() throws AgentUnavailableException { setupPutHostInMaintenance(false); administrationAgent.putHostInMaintenance(0l); verifyPutHostInMaintenanceCalledMethods(1, 1); }
@Test(expected = CloudRuntimeException.class) public void putHostInMaintenanceTestExceptionThrownAtMaintain() throws AgentUnavailableException { setupPutHostInMaintenance(false); Mockito.doThrow(AgentUnavailableException.class).when(resourceManager).maintain(Mockito.anyLong()); administrationAgent.putHostInMaintenance(0l); verifyPutHostInMaintenanceCalledMethods(0, 0); }
@Test(expected = CloudRuntimeException.class) public void putHostInMaintenanceTestHostInMaintenanceError() throws AgentUnavailableException { setupPutHostInMaintenance(true); administrationAgent.putHostInMaintenance(0l); verifyPutHostInMaintenanceCalledMethods(1, 0); }