@Test public void testMayBlockWaitingRunningItemEnd() throws Exception { long currentTime = System.currentTimeMillis(); long nextFireTime = currentTime - 1000L * 60L * 60L * 24L * 5L; long failoverMTime = currentTime - DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING; Class[] parameterTyps = {CuratorRepository.CuratorFrameworkOp.class, AbnormalJob.class, long.class, String.class}; AbnormalJob abnormalJob = new AbnormalJob(jobName, null, null, null); Object[] invokeParams = {curatorFrameworkOp, abnormalJob, nextFireTime, "2"}; String methodName = "mayBlockWaitingRunningItemEnd"; when(curatorFrameworkOp.getChildren(eq("/$Jobs/testJob/execution"))).thenReturn(Arrays.asList("0", "1", "2")); when(curatorFrameworkOp.checkExists(anyString())).thenReturn(false); Object result = MethodUtils .invokeMethod(outdatedNoRunningJobAnalyzer, true, methodName, invokeParams, parameterTyps); Assert.assertEquals(false, result); when(curatorFrameworkOp.checkExists("/$Jobs/testJob/execution/0/running")).thenReturn(true); when(curatorFrameworkOp.getMtime("/$Jobs/testJob/execution/2/failover")).thenReturn(failoverMTime); result = MethodUtils .invokeMethod(outdatedNoRunningJobAnalyzer, true, methodName, invokeParams, parameterTyps); Assert.assertEquals(false, result); when(curatorFrameworkOp.getMtime("/$Jobs/testJob/execution/2/failover")).thenReturn(failoverMTime + 1000); result = MethodUtils .invokeMethod(outdatedNoRunningJobAnalyzer, true, methodName, invokeParams, parameterTyps); Assert.assertEquals(true, result); }
private boolean mayBlockWaitingRunningItemEnd(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, AbnormalJob abnormalJob, long nextFireTime, String shardingItemStr) { List<String> executionItems = curatorFrameworkOp .getChildren(JobNodePath.getExecutionNodePath(abnormalJob.getJobName())); boolean hasRunningItem = false; if (!CollectionUtils.isEmpty(executionItems)) { for (String item : executionItems) { String runningNodePath = JobNodePath.getRunningNodePath(abnormalJob.getJobName(), item); if (curatorFrameworkOp.checkExists(runningNodePath)) { hasRunningItem = true; break; } } } if (!hasRunningItem) { return false; } long currentTime = System.currentTimeMillis(); long failoverMtime; String failoverNodePath = JobNodePath.getFailoverNodePath(abnormalJob.getJobName(), shardingItemStr); if ((failoverMtime = curatorFrameworkOp.getMtime(failoverNodePath)) <= 0) { String leaderFailoverItemPath = JobNodePath .getLeaderFailoverItemPath(abnormalJob.getJobName(), shardingItemStr); failoverMtime = curatorFrameworkOp.getMtime(leaderFailoverItemPath); } long nextFireTimeTmp = failoverMtime > nextFireTime ? failoverMtime : nextFireTime; return nextFireTimeTmp + DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING > currentTime; }
OutdatedNoRunningJobAnalyzer { private boolean mayBlockWaitingRunningItemEnd(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, AbnormalJob abnormalJob, long nextFireTime, String shardingItemStr) { List<String> executionItems = curatorFrameworkOp .getChildren(JobNodePath.getExecutionNodePath(abnormalJob.getJobName())); boolean hasRunningItem = false; if (!CollectionUtils.isEmpty(executionItems)) { for (String item : executionItems) { String runningNodePath = JobNodePath.getRunningNodePath(abnormalJob.getJobName(), item); if (curatorFrameworkOp.checkExists(runningNodePath)) { hasRunningItem = true; break; } } } if (!hasRunningItem) { return false; } long currentTime = System.currentTimeMillis(); long failoverMtime; String failoverNodePath = JobNodePath.getFailoverNodePath(abnormalJob.getJobName(), shardingItemStr); if ((failoverMtime = curatorFrameworkOp.getMtime(failoverNodePath)) <= 0) { String leaderFailoverItemPath = JobNodePath .getLeaderFailoverItemPath(abnormalJob.getJobName(), shardingItemStr); failoverMtime = curatorFrameworkOp.getMtime(leaderFailoverItemPath); } long nextFireTimeTmp = failoverMtime > nextFireTime ? failoverMtime : nextFireTime; return nextFireTimeTmp + DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING > currentTime; } }
OutdatedNoRunningJobAnalyzer { private boolean mayBlockWaitingRunningItemEnd(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, AbnormalJob abnormalJob, long nextFireTime, String shardingItemStr) { List<String> executionItems = curatorFrameworkOp .getChildren(JobNodePath.getExecutionNodePath(abnormalJob.getJobName())); boolean hasRunningItem = false; if (!CollectionUtils.isEmpty(executionItems)) { for (String item : executionItems) { String runningNodePath = JobNodePath.getRunningNodePath(abnormalJob.getJobName(), item); if (curatorFrameworkOp.checkExists(runningNodePath)) { hasRunningItem = true; break; } } } if (!hasRunningItem) { return false; } long currentTime = System.currentTimeMillis(); long failoverMtime; String failoverNodePath = JobNodePath.getFailoverNodePath(abnormalJob.getJobName(), shardingItemStr); if ((failoverMtime = curatorFrameworkOp.getMtime(failoverNodePath)) <= 0) { String leaderFailoverItemPath = JobNodePath .getLeaderFailoverItemPath(abnormalJob.getJobName(), shardingItemStr); failoverMtime = curatorFrameworkOp.getMtime(leaderFailoverItemPath); } long nextFireTimeTmp = failoverMtime > nextFireTime ? failoverMtime : nextFireTime; return nextFireTimeTmp + DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING > currentTime; }  }
OutdatedNoRunningJobAnalyzer { private boolean mayBlockWaitingRunningItemEnd(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, AbnormalJob abnormalJob, long nextFireTime, String shardingItemStr) { List<String> executionItems = curatorFrameworkOp .getChildren(JobNodePath.getExecutionNodePath(abnormalJob.getJobName())); boolean hasRunningItem = false; if (!CollectionUtils.isEmpty(executionItems)) { for (String item : executionItems) { String runningNodePath = JobNodePath.getRunningNodePath(abnormalJob.getJobName(), item); if (curatorFrameworkOp.checkExists(runningNodePath)) { hasRunningItem = true; break; } } } if (!hasRunningItem) { return false; } long currentTime = System.currentTimeMillis(); long failoverMtime; String failoverNodePath = JobNodePath.getFailoverNodePath(abnormalJob.getJobName(), shardingItemStr); if ((failoverMtime = curatorFrameworkOp.getMtime(failoverNodePath)) <= 0) { String leaderFailoverItemPath = JobNodePath .getLeaderFailoverItemPath(abnormalJob.getJobName(), shardingItemStr); failoverMtime = curatorFrameworkOp.getMtime(leaderFailoverItemPath); } long nextFireTimeTmp = failoverMtime > nextFireTime ? failoverMtime : nextFireTime; return nextFireTimeTmp + DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING > currentTime; }  void analyze(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, List<AbnormalJob> oldAbnormalJobs,
			String jobName, String jobDegree, RegistryCenterConfiguration config); void reportAlarmOutdatedNoRunningJobs(); List<AbnormalJob> getOutdatedNoRunningJobs(); void setAbnormalShardingStateCache(Map<String, AbnormalShardingState> abnormalShardingStateCache); void setReportAlarmService(ReportAlarmService reportAlarmService); void setJobService(JobService jobService); }
OutdatedNoRunningJobAnalyzer { private boolean mayBlockWaitingRunningItemEnd(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, AbnormalJob abnormalJob, long nextFireTime, String shardingItemStr) { List<String> executionItems = curatorFrameworkOp .getChildren(JobNodePath.getExecutionNodePath(abnormalJob.getJobName())); boolean hasRunningItem = false; if (!CollectionUtils.isEmpty(executionItems)) { for (String item : executionItems) { String runningNodePath = JobNodePath.getRunningNodePath(abnormalJob.getJobName(), item); if (curatorFrameworkOp.checkExists(runningNodePath)) { hasRunningItem = true; break; } } } if (!hasRunningItem) { return false; } long currentTime = System.currentTimeMillis(); long failoverMtime; String failoverNodePath = JobNodePath.getFailoverNodePath(abnormalJob.getJobName(), shardingItemStr); if ((failoverMtime = curatorFrameworkOp.getMtime(failoverNodePath)) <= 0) { String leaderFailoverItemPath = JobNodePath .getLeaderFailoverItemPath(abnormalJob.getJobName(), shardingItemStr); failoverMtime = curatorFrameworkOp.getMtime(leaderFailoverItemPath); } long nextFireTimeTmp = failoverMtime > nextFireTime ? failoverMtime : nextFireTime; return nextFireTimeTmp + DashboardConstants.NOT_RUNNING_WARN_DELAY_MS_WHEN_JOB_RUNNING > currentTime; }  void analyze(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, List<AbnormalJob> oldAbnormalJobs,
			String jobName, String jobDegree, RegistryCenterConfiguration config); void reportAlarmOutdatedNoRunningJobs(); List<AbnormalJob> getOutdatedNoRunningJobs(); void setAbnormalShardingStateCache(Map<String, AbnormalShardingState> abnormalShardingStateCache); void setReportAlarmService(ReportAlarmService reportAlarmService); void setJobService(JobService jobService);  }