AutonomicClusterManagementService { @Transactional(readOnly = false) @Scheduled(initialDelay = ONE_MINUTE_IN_MILLISECONDS, fixedDelay = ONE_MINUTE_IN_MILLISECONDS * NUMBER_OF_MINUTES_BETWEEN_CHECKS) public void removeClusterStuckProcessing() { List<ClusterVO> allClusters = clusterDao.listAll(); if (CollectionUtils.isEmpty(allClusters)) { return; } for (ClusterVO cluster : allClusters) { final long clusterId = cluster.getId(); if (!ClusterAdministrationStatus.isClusterBeingManaged(clusterDaoJdbc.getClusterAdministrationStatus(clusterId))) { continue; } Date lastAdministration = clusterDaoJdbc.getClusterLastAdminstration(clusterId); if (lastAdministration == null) { markAdministrationStatusInClusterAsDone(clusterId); continue; } Calendar cal = Calendar.getInstance(); cal.setTime(lastAdministration); cal.add(Calendar.HOUR_OF_DAY, 6); Date now = new Date(); if (cal.getTime().before(now)) { markAdministrationStatusInClusterAsDone(clusterId); } } }  boolean isClusterBeingAdministrated(long id); boolean canProcessCluster(long clusterId, ClusterAdministrationHeuristicAlgorithm algorithm); @Transactional(readOnly = false) void setClusterWorkInProgress(long clusterId); @Transactional(readOnly = false) void markAdministrationStatusInClusterAsDone(long clusterId); @Transactional(readOnly = false) @Scheduled(initialDelay = ONE_MINUTE_IN_MILLISECONDS, fixedDelay = ONE_MINUTE_IN_MILLISECONDS * NUMBER_OF_MINUTES_BETWEEN_CHECKS) void removeClusterStuckProcessing();  }
@Test @PrepareForTest(AutonomicClusterManagementService.class) public void removeClusterStuckProcessingTestListOfClustersNull() throws Exception { Date lastAdministrated = getLastAdministrationDate(); setRemoveClusterStuckProcessing(lastAdministrated, null, ClusterAdministrationStatus.InProgress); PowerMockito.whenNew(Date.class).withNoArguments().thenReturn(lastAdministrated); autonomicClusterManagementService.removeClusterStuckProcessing(); verifyRemoveClusterStuckProcessingCalledMethods(0, 0, 0); }
@Test @PrepareForTest(AutonomicClusterManagementService.class) public void removeClusterStuckProcessingTestClusterAdministrationStatusDone() throws Exception { List<ClusterVO> allClusters = new ArrayList<>(); ClusterVO cluster = new ClusterVO(0l); allClusters.add(cluster); setRemoveClusterStuckProcessing(new Date(), allClusters, ClusterAdministrationStatus.Done); autonomicClusterManagementService.removeClusterStuckProcessing(); verifyRemoveClusterStuckProcessingCalledMethods(1, 0, 0); }
@Test @PrepareForTest(AutonomicClusterManagementService.class) public void removeClusterStuckProcessingTestSixHoursInProgress() throws Exception { List<ClusterVO> allClusters = createClusters(); Date lastAdministrated = getLastAdministrationDate(); Date current = setCurrentDate(lastAdministrated, 7); PowerMockito.whenNew(Date.class).withNoArguments().thenReturn(current); setRemoveClusterStuckProcessing(lastAdministrated, allClusters, ClusterAdministrationStatus.InProgress); autonomicClusterManagementService.removeClusterStuckProcessing(); verifyRemoveClusterStuckProcessingCalledMethods(1, 1, 1); }
@Test @PrepareForTest(AutonomicClusterManagementService.class) public void removeClusterStuckProcessingTestLessThanSixHoursInProgress() throws Exception { List<ClusterVO> allClusters = createClusters(); Date lastAdministrated = getLastAdministrationDate(); Date current = setCurrentDate(lastAdministrated, 5); PowerMockito.whenNew(Date.class).withNoArguments().thenReturn(current); setRemoveClusterStuckProcessing(lastAdministrated, allClusters, ClusterAdministrationStatus.InProgress); autonomicClusterManagementService.removeClusterStuckProcessing(); verifyRemoveClusterStuckProcessingCalledMethods(1, 1, 0); }