ConfigurationService { public void checkMaxTimeDiffSecondsTolerable() { int maxTimeDiffSeconds = Integer.parseInt(jobNodeStorage.getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS)); if (-1 == maxTimeDiffSeconds) { return; } long timeDiff = Math.abs(System.currentTimeMillis() - jobNodeStorage.getRegistryCenterTime()); if (timeDiff > maxTimeDiffSeconds * 1000L) { throw new TimeDiffIntolerableException(Long.valueOf(timeDiff / 1000).intValue(), maxTimeDiffSeconds); } } ConfigurationService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void persistJobConfiguration(); int getShardingTotalCount(); Map<Integer, String> getShardingItemParameters(); String getJobParameter(); String getCron(); boolean isMonitorExecution(); int getProcessCountIntervalSeconds(); int getConcurrentDataProcessThreadCount(); int getFetchDataCount(); void checkMaxTimeDiffSecondsTolerable(); boolean isFailover(); boolean isMisfire(); String getJobShardingStrategyClass(); int getMonitorPort(); String getJobName(); boolean inSkipTime(Date now);  }
@Test public void assertIsMaxTimeDiffSecondsTolerableWithDefaultValue() { when(jobNodeStorage.getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS)).thenReturn("-1"); configService.checkMaxTimeDiffSecondsTolerable(); verify(jobNodeStorage).getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS); }
@Test public void assertIsMaxTimeDiffSecondsTolerable() { when(jobNodeStorage.getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS)).thenReturn("60"); when(jobNodeStorage.getRegistryCenterTime()).thenReturn(System.currentTimeMillis()); configService.checkMaxTimeDiffSecondsTolerable(); verify(jobNodeStorage).getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS); verify(jobNodeStorage).getRegistryCenterTime(); }
@Test(expected = TimeDiffIntolerableException.class) public void assertIsNotMaxTimeDiffSecondsTolerable() { when(jobNodeStorage.getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS)).thenReturn("60"); when(jobNodeStorage.getRegistryCenterTime()).thenReturn(0L); try { configService.checkMaxTimeDiffSecondsTolerable(); } finally { verify(jobNodeStorage).getJobNodeData(ConfigurationNode.MAX_TIME_DIFF_SECONDS); verify(jobNodeStorage).getRegistryCenterTime(); } }