AutonomicClusterManagementService { public boolean canProcessCluster(long clusterId, ClusterAdministrationHeuristicAlgorithm algorithm) { Date lastAdministration = clusterDaoJdbc.getClusterLastAdminstration(clusterId); if (lastAdministration == null) { return true; } Calendar lastAdministrationCalendar = Calendar.getInstance(); lastAdministrationCalendar.setTime(lastAdministration); lastAdministrationCalendar.add(Calendar.SECOND, algorithm.getClusterIntervalBetweenConsolidation()); Calendar calendarNow = Calendar.getInstance(); return lastAdministrationCalendar.before(calendarNow); }  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 canProcessClusterTest() throws Exception { ClusterAdministrationHeuristicAlgorithm algorithm = Mockito.mock(ClusterAdministrationHeuristicAlgorithm.class); setCanProcessCluster(algorithm, getLastAdministrationDate(), 5, 1); boolean result = autonomicClusterManagementService.canProcessCluster(0l, algorithm); Assert.assertTrue(result); verifyCanProcessClusterCalledMethods(algorithm, 1); }
@Test @PrepareForTest(AutonomicClusterManagementService.class) public void canProcessClusterTestIsNotTimeYet() throws Exception { ClusterAdministrationHeuristicAlgorithm algorithm = Mockito.mock(ClusterAdministrationHeuristicAlgorithm.class); setCanProcessCluster(algorithm, getLastAdministrationDate(), 0, 1); boolean result = autonomicClusterManagementService.canProcessCluster(0l, algorithm); Assert.assertFalse(result); verifyCanProcessClusterCalledMethods(algorithm, 1); }
@Test public void canProcessClusterTestDateNull() throws Exception { ClusterAdministrationHeuristicAlgorithm algorithm = Mockito.mock(ClusterAdministrationHeuristicAlgorithm.class); setCanProcessCluster(algorithm, null, 1, 1); boolean result = autonomicClusterManagementService.canProcessCluster(0l, algorithm); Assert.assertTrue(result); verifyCanProcessClusterCalledMethods(algorithm, 0); }