AdministrationAgent implements InitializingBean { protected ClusterVO getClusterToManageFromZone(ClusterAdministrationHeuristicAlgorithm algorithm, Long zoneId) { List<ClusterVO> clusters = clusterService.listAllClustersOnZone(zoneId); for (ClusterVO cluster : clusters) { if (cluster.getRemoved() != null) { continue; } if (autonomicClusterManagementService.isClusterBeingAdministrated(cluster.getId())) { continue; } if (autonomicClusterManagementService.canProcessCluster(cluster.getId(), algorithm)) { autonomicClusterManagementService.setClusterWorkInProgress(cluster.getId()); return cluster; } } return null; }  void receiveClusterToBeManaged(Long clusterId); Long searchClusterToBeManaged(); List<ClusterResourcesUp> createAllClustersResourcesUp(); @Override void afterPropertiesSet();  }
@Test public void getClusterToManageFromZoneTestListOfClustersEmpty() { List<ClusterVO> clusters = new ArrayList<>(); Mockito.doReturn(clusters).when(clusterService).listAllClustersOnZone(Mockito.anyLong()); ClusterVO result = administrationAgent.getClusterToManageFromZone(clusterAdministrationHeuristicAlgorithm, null); Assert.assertNull(result); verifyGetClusterToManageFromZoneCalledMethods(0, 0, 0); }
@Test public void getClusterToManageFromZoneTestListOfClustersNotEmptyAndClusterIsNotAdministrated() { List<ClusterVO> clusters = createClusters(null); getClusterToManageFromZoneReturnedValuesSetup(clusters, false, true); ClusterVO result = administrationAgent.getClusterToManageFromZone(clusterAdministrationHeuristicAlgorithm, null); Assert.assertNotNull(result); verifyGetClusterToManageFromZoneCalledMethods(1, 1, 1); }
@Test public void getClusterToManageFromZoneTestListOfClustersNotEmptyAndCannotProcess() { List<ClusterVO> clusters = createClusters(null); getClusterToManageFromZoneReturnedValuesSetup(clusters, false, false); ClusterVO result = administrationAgent.getClusterToManageFromZone(clusterAdministrationHeuristicAlgorithm, null); Assert.assertNull(result); verifyGetClusterToManageFromZoneCalledMethods(1, 1, 0); }
@Test public void getClusterToManageFromZoneTestClusterIsRemoved() { List<ClusterVO> clusters = createClusters(new Date()); getClusterToManageFromZoneReturnedValuesSetup(clusters, true, true); ClusterVO result = administrationAgent.getClusterToManageFromZone(clusterAdministrationHeuristicAlgorithm, null); Assert.assertNull(result); verifyGetClusterToManageFromZoneCalledMethods(0, 0, 0); }