/** * Sets the clock to a date without milliseconds. Older mysql * versions do not support milliseconds. Test which test timestamp * should avoid timestamps with milliseconds. * * @return the new current time */ public static Date setClockToDateWithoutMilliseconds() { ClockUtil.setCurrentTime(new Date(1363608000000L)); return ClockUtil.getCurrentTime(); }
@Override public void execute(ProcessEngine processEngine, String s) { ClockUtil. setCurrentTime(TIMESTAMP); deployModel(processEngine, DEPLOYMENT_NAME, PROCESS_DEFINITION_KEY, DEPLOYMENT_MODEL); ClockUtil.reset(); } };
@Test public void resetClockShouldResetToCurrentTime() { long duration = TWO_DAYS; Date target = new Date(new Date().getTime() + duration); ClockUtil.offset(duration); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); assertThat(ClockUtil.resetClock()).isCloseTo(new Date(), ONE_SECOND); assertThat(ClockUtil.getCurrentTime()).isCloseTo(new Date(), ONE_SECOND); }
@Test public void resetShouldResetToCurrentTime() { long duration = TWO_DAYS; Date target = new Date(new Date().getTime() + duration); ClockUtil.offset(duration); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); ClockUtil.reset(); assertThat(ClockUtil.now()).isCloseTo(new Date(), ONE_SECOND); }
public HalResourceCacheEntry(String id, Object resource) { this.id = id; this.created = ClockUtil.getCurrentTime().getTime(); this.resource = resource; }
@Override protected void tearDown() throws Exception { TestHelper.annotationDeploymentTearDown(processEngine, deploymentId, getClass(), getName()); ClockUtil.reset(); super.tearDown(); }
protected Date oneWeekLater() { // one week from now Date startTime = new Date(); ClockUtil.setCurrentTime(startTime); long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000); return new Date(oneWeekFromStartTime); }
@Test public void setCurrentTimeShouldFreezeTime() { long duration = TWO_DAYS; Date target = new Date(new Date().getTime() + duration); ClockUtil.setCurrentTime(target); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); }
@Test public void getCurrentTimeShouldReturnSameValueAsNow() { assertThat(ClockUtil.getCurrentTime()).isCloseTo(ClockUtil.now(), ONE_SECOND); }
@Test public void timeShouldMoveOnAfterTravel() throws InterruptedException { Date now = new Date(); long duration = TWO_DAYS; Date target = new Date(now.getTime() + duration); ClockUtil.offset(duration); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); Thread.sleep(FIVE_SECONDS); assertThat(ClockUtil.now()).isCloseTo(new Date(target.getTime() + FIVE_SECONDS), ONE_SECOND); }
public static synchronized Date parseTimeConfiguration(String time) throws ParseException { String today = DATE_FORMAT_WITHOUT_TIME.format(ClockUtil.getCurrentTime()); try { return TIME_FORMAT_WITHOUT_SECONDS_WITH_TIMEZONE.parse(today+time); } catch (ParseException ex) { return TIME_FORMAT_WITHOUT_SECONDS.parse(today+time); } }
@Override protected void tearDown() throws Exception { TestHelper.annotationDeploymentTearDown(processEngine, deploymentId, getClass(), getName()); ClockUtil.reset(); super.tearDown(); }
protected void setCurrentTime(int year, int month, int dayOfMonth, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, dayOfMonth, hourOfDay, minute); ClockUtil.setCurrentTime(calendar.getTime()); }
@Test public void timeShouldFreezeWithSetCurrentTime() throws InterruptedException { Date now = new Date(); long duration = TWO_DAYS; Date target = new Date(now.getTime() + duration); ClockUtil.setCurrentTime(target); Thread.sleep(FIVE_SECONDS); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); } }
public void shiftTimeByOneMinute() { Long oneMinute = 1000L * 60L; Date shiftedTimeByOneMinute = new Date(ClockUtil.getCurrentTime().getTime() + oneMinute); ClockUtil.setCurrentTime(shiftedTimeByOneMinute); }
public void extendLock(long newLockExpirationTime) { ensureActive(); long newTime = ClockUtil.getCurrentTime().getTime() + newLockExpirationTime; this.lockExpirationTime = new Date(newTime); }
@Override public void execute(ProcessEngine processEngine, String scenarioName) { ClockUtil.setCurrentTime(TIMESTAMP); deployModel(processEngine, PROCESS_DEFINITION_KEY, PROCESS_DEFINITION_KEY, FAILING_SERVICE_TASK_MODEL); String processInstanceId = processEngine.getRuntimeService() .startProcessInstanceByKey(PROCESS_DEFINITION_KEY, scenarioName) .getId(); causeIncident(processEngine, processInstanceId); ClockUtil.reset(); } };
@Before public void setUp() throws Exception { ClockUtil.reset(); }
protected void setCurrentTime(int year, int month, int dayOfMonth, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); // Calendars month start with 0 = January calendar.set(year, month - 1, dayOfMonth, hourOfDay, minute); ClockUtil.setCurrentTime(calendar.getTime()); }