use of io.cdap.cdap.internal.app.runtime.schedule.constraint.DelayConstraint in project cdap by caskdata.
the class ScheduledRunTimeTest method testGetNextRun.
@Test
public void testGetNextRun() throws Exception {
ApplicationId appId = NamespaceId.DEFAULT.app("test");
deploy(appId, new AppRequest<>(new ArtifactSummary(ARTIFACT_ID.getName(), ARTIFACT_ID.getVersion().getVersion())));
String scheduleName = "schedule1";
// Add a schedule. Use a constraint to make it not going to be executed
ProgramId programId = appId.workflow(WorkflowApp.FunWorkflow.NAME);
Constraint constraint = new DelayConstraint(1, TimeUnit.HOURS);
ScheduleProgramInfo scheduleProgramInfo = new ScheduleProgramInfo(programId.getType().getSchedulableType(), programId.getProgram());
addSchedule(appId.getNamespace(), appId.getApplication(), appId.getVersion(), scheduleName, new ScheduleDetail(scheduleName, null, scheduleProgramInfo, null, new TimeTrigger("0 0 * * * "), Collections.singletonList(constraint), null));
long now = System.currentTimeMillis();
HttpResponse response = enableSchedule(programId.getNamespace(), programId.getApplication(), programId.getVersion(), scheduleName);
Assert.assertEquals(200, response.getResponseCode());
// Get the next run time
List<ScheduledRuntime> scheduledRunTimes = getScheduledRunTimes(programId, true);
Assert.assertEquals(1, scheduledRunTimes.size());
long nextTime = scheduledRunTimes.get(0).getTime();
Assert.assertTrue(nextTime >= now);
}
use of io.cdap.cdap.internal.app.runtime.schedule.constraint.DelayConstraint in project cdap by caskdata.
the class ScheduledRunTimeTest method testBatchGetNextRun.
@Test
public void testBatchGetNextRun() throws Exception {
// deploys 5 apps and create schedules for each of them
long now = System.currentTimeMillis();
List<ProgramId> programIds = new ArrayList<>();
// Use a constraint to make it not going to be executed
Constraint constraint = new DelayConstraint(1, TimeUnit.HOURS);
for (int i = 0; i < 5; i++) {
ApplicationId appId = NamespaceId.DEFAULT.app("test" + i);
deploy(appId, new AppRequest<>(new ArtifactSummary(ARTIFACT_ID.getName(), ARTIFACT_ID.getVersion().getVersion())));
String scheduleName = "schedule" + i;
// Add a schedule
ProgramId programId = appId.workflow(WorkflowApp.FunWorkflow.NAME);
programIds.add(programId);
ScheduleProgramInfo scheduleProgramInfo = new ScheduleProgramInfo(programId.getType().getSchedulableType(), programId.getProgram());
addSchedule(appId.getNamespace(), appId.getApplication(), appId.getVersion(), scheduleName, new ScheduleDetail(scheduleName, null, scheduleProgramInfo, null, new TimeTrigger("0 0 * * * "), Collections.singletonList(constraint), null));
HttpResponse response = enableSchedule(programId.getNamespace(), programId.getApplication(), programId.getVersion(), scheduleName);
Assert.assertEquals(200, response.getResponseCode());
}
// Add programs that the app or the program doesn't exist
programIds.add(NamespaceId.DEFAULT.app("not-exist").workflow("not-exist"));
programIds.add(NamespaceId.DEFAULT.app("test1").workflow("not-exist"));
List<BatchProgramSchedule> schedules = getScheduledRunTimes(NamespaceId.DEFAULT.getNamespace(), programIds, true);
Assert.assertEquals(programIds.size(), schedules.size());
// For the first 5 programs, they should have a next run
for (int i = 0; i < 5; i++) {
BatchProgramSchedule schedule = schedules.get(i);
Assert.assertEquals(200, schedule.getStatusCode());
List<ScheduledRuntime> nextRuns = schedule.getSchedules();
Assert.assertNotNull(nextRuns);
Assert.assertEquals(1, nextRuns.size());
long nextTime = nextRuns.get(0).getTime();
Assert.assertTrue(nextTime >= now);
}
// The last two should be a not found
Assert.assertEquals(404, schedules.get(5).getStatusCode());
Assert.assertEquals(404, schedules.get(6).getStatusCode());
}
Aggregations