@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);
DelayConstraint tenMinuteDelayConstraint = new DelayConstraint(10, TimeUnit.MINUTES);
ConstraintContext constraintContext = new ConstraintContext(job, now + TimeUnit.MINUTES.toMillis(12), null);
ConstraintResult result = tenMinuteDelayConstraint.check(schedule, constraintContext);
Assert.assertEquals(ConstraintResult.SATISFIED, result);
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());
}