@Test public void testDelayConstraint() { long now = System.currentTimeMillis(); ProgramSchedule schedule = new ProgramSchedule("SCHED1", "one partition schedule", WORKFLOW_ID, ImmutableMap.of("prop3", "abc"), new PartitionTrigger(DATASET_ID, 1), ImmutableList.<Constraint>of()); SimpleJob job = new SimpleJob(schedule, now, Collections.<Notification>emptyList(), Job.State.PENDING_TRIGGER, 0L); // test with 10 minute delay DelayConstraint tenMinuteDelayConstraint = new DelayConstraint(10, TimeUnit.MINUTES); // a check against 12 minutes after 'now' will return SATISFIED ConstraintContext constraintContext = new ConstraintContext(job, now + TimeUnit.MINUTES.toMillis(12), null); ConstraintResult result = tenMinuteDelayConstraint.check(schedule, constraintContext); Assert.assertEquals(ConstraintResult.SATISFIED, result); // a check against 9 minutes after 'now' will return NOT_SATISFIED, with 1 minute to wait until next retry constraintContext = new ConstraintContext(job, now + TimeUnit.MINUTES.toMillis(9), null); result = tenMinuteDelayConstraint.check(schedule, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); Assert.assertEquals(constraintContext.getCheckTimeMillis() + TimeUnit.MINUTES.toMillis(1), (long) result.getNextCheckTime()); }
@Test public void testForwardRange() { // 3:24PM PST long now = 1494368640000L; SimpleJob job = new SimpleJob(SCHEDULE, now, Collections.<Notification>emptyList(), Job.State.PENDING_TRIGGER, 0L); // use a TimeRangeConstraint [4:00PM, 5:00PM) TimeRangeConstraint timeRangeConstraint = new TimeRangeConstraint("16:00", "17:00", TimeZone.getTimeZone("PST")); ConstraintContext constraintContext = createConstraintContext(job, now); ConstraintResult result = timeRangeConstraint.check(SCHEDULE, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); // 36 minutes till 4PM Assert.assertEquals(constraintContext.getCheckTimeMillis() + TimeUnit.MINUTES.toMillis(36), (long) result.getNextCheckTime()); constraintContext = createConstraintContext(job, result.getNextCheckTime() - 1); result = timeRangeConstraint.check(SCHEDULE, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); Assert.assertEquals(constraintContext.getCheckTimeMillis() + 1L, (long) result.getNextCheckTime()); result = timeRangeConstraint.check(SCHEDULE, createConstraintContext(job, now + TimeUnit.MINUTES.toMillis(36))); Assert.assertEquals(ConstraintResult.SATISFIED, result); // 5:00PM PST long fivePM = 1494374400000L; constraintContext = createConstraintContext(job, fivePM); result = timeRangeConstraint.check(SCHEDULE, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); // 23 hours until the next time its 4PM again Assert.assertEquals(constraintContext.getCheckTimeMillis() + TimeUnit.HOURS.toMillis(23), (long) result.getNextCheckTime()); }
(long) result.getNextCheckTime()); constraintContext = createConstraintContext(job, result.getNextCheckTime() - 1); result = timeRangeConstraint.check(SCHEDULE, constraintContext); Assert.assertEquals(ConstraintResult.SatisfiedState.NOT_SATISFIED, result.getSatisfiedState()); Assert.assertEquals(constraintContext.getCheckTimeMillis() + 1L, (long) result.getNextCheckTime()); (long) result.getNextCheckTime()); (long) result.getNextCheckTime()); (long) result.getNextCheckTime());