/** * 加一分钟 */ public static Date addMinutes(@NotNull final Date date, int amount) { return DateUtils.addMinutes(date, amount); }
/** * 减一分钟 */ public static Date subMinutes(@NotNull final Date date, int amount) { return DateUtils.addMinutes(date, -amount); }
/** * 加一分钟 */ public static Date addMinutes(@NotNull final Date date, int amount) { return DateUtils.addMinutes(date, amount); }
/** * 减一分钟 */ public static Date subMinutes(@NotNull final Date date, int amount) { return DateUtils.addMinutes(date, -amount); }
@Test public void testAddMinutes() throws Exception { Date result = DateUtils.addMinutes(BASE_DATE, 0); assertNotSame(BASE_DATE, result); assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1); assertDate(result, 2000, 6, 5, 4, 3, 2, 1); result = DateUtils.addMinutes(BASE_DATE, 1); assertNotSame(BASE_DATE, result); assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1); assertDate(result, 2000, 6, 5, 4, 4, 2, 1); result = DateUtils.addMinutes(BASE_DATE, -1); assertNotSame(BASE_DATE, result); assertDate(BASE_DATE, 2000, 6, 5, 4, 3, 2, 1); assertDate(result, 2000, 6, 5, 4, 2, 2, 1); }
@Override public Date add(Date theInput, int theAmount) { return DateUtils.addMinutes(theInput, theAmount); } },
@Override public Date add(Date theInput, int theAmount) { return DateUtils.addMinutes(theInput, theAmount); } },
@Override public Date add(Date theInput, int theAmount) { return DateUtils.addMinutes(theInput, theAmount); }
/** * @return 精确到分钟的当前日期 */ public static Date getMinuteDate() { return DateUtils.addMinutes(DateUtils.setSeconds(DateUtils.setMilliseconds(getDate(), 0), 0), 1); }
/** * @return 精确到分钟的当前日期 */ public static Date getMinuteDate() { return DateUtils.addMinutes(DateUtils.setSeconds(DateUtils.setMilliseconds(getDate(), 0), 0), 1); }
@Override @Transactional(Transactional.TxType.REQUIRED) public Long markAllResourcesForReindexing(String theType) { String typeDesc; if (isNotBlank(theType)) { myReindexJobDao.markAllOfTypeAsDeleted(theType); typeDesc = theType; } else { myReindexJobDao.markAllOfTypeAsDeleted(); typeDesc = "(any)"; } ResourceReindexJobEntity job = new ResourceReindexJobEntity(); job.setResourceType(theType); job.setThresholdHigh(DateUtils.addMinutes(new Date(), 5)); job = myReindexJobDao.saveAndFlush(job); ourLog.info("Marking all resources of type {} for reindexing - Got job ID[{}]", typeDesc, job.getId()); return job.getId(); }
protected void lockUser(String userId, String invalidPassword) throws ParseException { Date now = ClockUtil.getCurrentTime(); try { for (int i = 0; i <= 11; i++) { assertFalse(identityService.checkPassword(userId, invalidPassword)); now = DateUtils.addMinutes(ClockUtil.getCurrentTime(), 1); ClockUtil.setCurrentTime(now); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception { SysApp entity = appService.getEntity(handler.getString("appKey")); if (null != entity) { if (entity.getAppSecret().equalsIgnoreCase(handler.getString("appSecret"))) { Date now = CommonUtils.getDate(); SysAppToken token = new SysAppToken(UUID.randomUUID().toString(), entity.getId(), now); if (null != entity.getExpiryMinutes()) { token.setExpiryDate(DateUtils.addMinutes(now, entity.getExpiryMinutes())); } appTokenService.save(token); handler.put("appToken", token.getAuthToken()); handler.put("expiryDate", token.getExpiryDate()); } else { handler.put("error", SECRET_ERROR); } } else { handler.put("error", KEY_NOT_EXISTS); } }
@Override public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception { SysApp entity = appService.getEntity(handler.getString("appKey")); if (null != entity) { if (entity.getAppSecret().equalsIgnoreCase(handler.getString("appSecret"))) { Date now = CommonUtils.getDate(); SysAppToken token = new SysAppToken(UUID.randomUUID().toString(), entity.getId(), now); if (null != entity.getExpiryMinutes()) { token.setExpiryDate(DateUtils.addMinutes(now, entity.getExpiryMinutes())); } appTokenService.save(token); handler.put("appToken", token.getAuthToken()); handler.put("expiryDate", token.getExpiryDate()); } else { handler.put("error", SECRET_ERROR); } } else { handler.put("error", KEY_NOT_EXISTS); } }
@Test public void testScheduleJobForBatchWindow() throws ParseException { ClockUtil.setCurrentTime(currentDate); processEngineConfiguration.initHistoryCleanup(); Job job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheck.after(job.getDuedate())); // job due date is not before start date assertTrue(endDateForCheck.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheck, -1)); job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheck.after(job.getDuedate())); assertTrue(endDateForCheck.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheck, 1)); job = historyService.cleanUpHistoryAsync(); assertTrue(endDateForCheck.before(job.getDuedate())); }
@Test public void testScheduleJobForBatchWindowWithDefaultWindowConfigured() throws ParseException { ClockUtil.setCurrentTime(currentDate); processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("00:00"); processEngineConfiguration.initHistoryCleanup(); Job job = historyService.cleanUpHistoryAsync(); if (startDateForCheckWithDefaultValues == null) { startDateForCheckWithDefaultValues = startDateForCheck; } if (endDateForCheckWithDefaultValues == null) { endDateForCheckWithDefaultValues = endDateForCheck; } assertFalse(startDateForCheckWithDefaultValues.after(job.getDuedate())); // job due date is not before start date assertTrue(endDateForCheckWithDefaultValues.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheckWithDefaultValues, -1)); job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheckWithDefaultValues.after(job.getDuedate())); assertTrue(endDateForCheckWithDefaultValues.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheckWithDefaultValues, 1)); job = historyService.cleanUpHistoryAsync(); assertTrue(endDateForCheckWithDefaultValues.before(job.getDuedate())); }
@Test public void testScheduleJobForBatchWindowWithShortcutConfiguration() throws ParseException { ClockUtil.setCurrentTime(currentDate); processEngineConfiguration.setThursdayHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setThursdayHistoryCleanupBatchWindowEndTime("00:00"); processEngineConfiguration.setSaturdayHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setSaturdayHistoryCleanupBatchWindowEndTime("00:00"); processEngineConfiguration.initHistoryCleanup(); Job job = historyService.cleanUpHistoryAsync(); if (startDateForCheckWithDefaultValues == null) { startDateForCheckWithDefaultValues = startDateForCheck; } if (endDateForCheckWithDefaultValues == null) { endDateForCheckWithDefaultValues = endDateForCheck; } assertFalse(startDateForCheckWithDefaultValues.after(job.getDuedate())); // job due date is not before start date assertTrue(endDateForCheckWithDefaultValues.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheckWithDefaultValues, -1)); job = historyService.cleanUpHistoryAsync(); assertFalse(startDateForCheckWithDefaultValues.after(job.getDuedate())); assertTrue(endDateForCheckWithDefaultValues.after(job.getDuedate())); ClockUtil.setCurrentTime(DateUtils.addMinutes(endDateForCheckWithDefaultValues, 1)); job = historyService.cleanUpHistoryAsync(); assertTrue(endDateForCheckWithDefaultValues.before(job.getDuedate())); }
@Test public void testUsuccessfulAttemptsResultInException() throws ParseException { User user = identityService.newUser("johndoe"); user.setPassword("xxx"); identityService.saveUser(user); thrown.expect(AuthenticationException.class); thrown.expectMessage("The user with id 'johndoe' is permanently locked. Please contact your admin to unlock the account."); Date now = sdf.parse("2000-01-24T13:00:00"); ClockUtil.setCurrentTime(now); for (int i = 0; i <= 11; i++) { assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); now = DateUtils.addMinutes(now, 1); ClockUtil.setCurrentTime(now); } }
@Test public void testRetryMixConfiguration() throws ParseException { // given BpmnModelInstance bpmnModelInstance = prepareProcessFailingServiceTaskWithRetryCycle("R3/PT1M"); testRule.deploy(bpmnModelInstance); ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00")); ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); assertNotNull(pi); Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00"); ClockUtil.setCurrentTime(currentTime); String processInstanceId = pi.getProcessInstanceId(); int jobRetries; for (int i = 0; i < 3; i++) { jobRetries = executeJob(processInstanceId); assertEquals(2 - i, jobRetries); currentTime = DateUtils.addMinutes(currentTime, 1); assertLockExpirationTime(currentTime); ClockUtil.setCurrentTime(currentTime); } }
@Test public void testSingleRetryInterval() throws ParseException { // given BpmnModelInstance bpmnModelInstance = prepareProcessFailingServiceTaskWithRetryCycle("PT8M "); testRule.deploy(bpmnModelInstance); ClockUtil.setCurrentTime(SIMPLE_DATE_FORMAT.parse("2017-01-01T09:55:00")); ProcessInstance pi = runtimeService.startProcessInstanceByKey(PROCESS_ID); assertNotNull(pi); Date currentTime = SIMPLE_DATE_FORMAT.parse("2017-01-01T10:00:00"); ClockUtil.setCurrentTime(currentTime); String processInstanceId = pi.getProcessInstanceId(); int jobRetries = executeJob(processInstanceId); assertEquals(1, jobRetries); currentTime = DateUtils.addMinutes(currentTime, 8); assertLockExpirationTime(currentTime); ClockUtil.setCurrentTime(currentTime); jobRetries = executeJob(processInstanceId); assertEquals(0, jobRetries); }