use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method createJobTest.
@Test
public void createJobTest() throws Exception {
String actionId = "actionId";
ComplexJobTrigger trigger = getComplexJobTrigger();
IBackgroundExecutionStreamProvider outputStreamProvider = mock(IBackgroundExecutionStreamProvider.class);
final Job job = scheduler.createJob(JOB_NAME, actionId, null, trigger, outputStreamProvider);
assertNotNull(job);
assertEquals(Job.JobState.NORMAL, job.getState());
assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
assertEquals(actionId, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONID));
assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
assertEquals(outputStreamProvider, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_STREAMPROVIDER));
assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
assertNotNull(job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID));
assertTrue(job.getJobParams().containsKey(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
assertEquals(USER_NAME, job.getJobParams().get(QuartzScheduler.RESERVEDMAPKEY_ACTIONUSER));
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method testPauseAndResumeJob.
@Test
public void testPauseAndResumeJob() throws SchedulerException {
String jobName = "complexJob1";
int counter = TestAction.counter;
Calendar calendar = Calendar.getInstance();
int startingMin = calendar.get(Calendar.MINUTE);
int startingSec = calendar.get(Calendar.SECOND) + 1;
if (startingSec > 59) {
startingSec = startingSec % 60;
startingMin++;
if (startingMin > 59) {
startingMin = startingMin % 60;
}
}
ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
complexJobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
complexJobTrigger.setMinuteRecurrence(startingMin);
complexJobTrigger.setSecondRecurrence(startingSec);
Job job = scheduler.createJob(jobName, TestAction.class, jobParams, complexJobTrigger);
scheduler.pauseJob(job.getJobId());
sleep(2);
Assert.assertEquals(counter, TestAction.counter);
Assert.assertEquals(1, scheduler.getJobs(null).size());
scheduler.resumeJob(job.getJobId());
sleep(2);
Assert.assertTrue(counter != TestAction.counter);
scheduler.removeJob(job.getJobId());
Assert.assertEquals(0, scheduler.getJobs(null).size());
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method editJobTest.
@Test
public void editJobTest() throws SchedulerException {
SimpleJobTrigger repeater = new SimpleJobTrigger();
repeater.setStartTime(new Date());
repeater.setRepeatInterval(2);
repeater.setRepeatCount(20);
Job job = scheduler.createJob("testName", TestAction.class, new HashMap<String, Serializable>(), repeater);
sleep(3);
Assert.assertTrue("Job did not run the correct number of times", TestAction.counter >= 2);
repeater = new SimpleJobTrigger();
repeater.setStartTime(new Date());
repeater.setRepeatInterval(5);
repeater.setRepeatCount(3);
int count = TestAction.counter;
System.out.println("updating job! " + new Date());
scheduler.updateJob(job.getJobId(), new HashMap<String, Serializable>(), repeater);
List<Job> jobs = scheduler.getJobs(null);
Assert.assertEquals("Unexpected number of scheduled jobs", 1, jobs.size());
SimpleJobTrigger simpleJobTrigger = (SimpleJobTrigger) jobs.get(0).getJobTrigger();
Assert.assertEquals(5, simpleJobTrigger.getRepeatInterval());
Assert.assertEquals(3, simpleJobTrigger.getRepeatCount());
sleep(1);
Assert.assertEquals("Job did not run the correct number of times", count + 1, TestAction.counter);
count = TestAction.counter;
sleep(3);
Assert.assertEquals("Job ran unexpectedly", count, TestAction.counter);
sleep(3);
Assert.assertTrue("Job did not run the correct number of times", count < TestAction.counter);
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method runComplexTriggerTest.
@Test
public void runComplexTriggerTest() throws SchedulerException {
Calendar calendar = Calendar.getInstance();
// seconds
final int testTime = 7;
int startingMinute = calendar.get(Calendar.MINUTE);
int startingSec = calendar.get(Calendar.SECOND) + 1;
// we can't finish until end of the minute - sleep for this time
if (startingSec > 59 - testTime) {
sleep(59 - startingSec);
startingSec = 0;
startingMinute++;
if (startingMinute > 59) {
startingMinute = startingMinute % 60;
}
}
int endingSecond = startingSec + 5;
RecurrenceList recurrenceList = new RecurrenceList(startingSec, endingSecond);
SequentialRecurrence sequentialRecurrence = new SequentialRecurrence(startingSec, endingSecond);
IncrementalRecurrence incrementalRecurrence = new IncrementalRecurrence(startingSec, 1);
ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
jobTrigger.setMinuteRecurrence(startingMinute);
jobTrigger.setSecondRecurrence(recurrenceList);
System.out.println(jobTrigger.toString());
String jobName = "complexJob1";
Job job = scheduler.createJob(jobName, TestAction.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
jobTrigger.setSecondRecurrence(sequentialRecurrence);
jobName = "complexJob2";
job = scheduler.createJob(jobName, TestAction2.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction2.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
jobTrigger.setSecondRecurrence(incrementalRecurrence);
jobName = "complexJob3";
job = scheduler.createJob(jobName, TestAction3.class, new HashMap<String, Serializable>(), jobTrigger);
Assert.assertTrue(job.getJobName().contains(jobName));
Assert.assertEquals(job.getSchedulableClass(), TestAction3.class.getName());
Assert.assertEquals(job.getJobTrigger().toString(), jobTrigger.toString());
//
// Wait for the jobs to complete, then check that each action executed the correct number of times
//
sleep(testTime);
Assert.assertEquals("Job did not run the correct number of times", 2, TestAction.counter);
Assert.assertEquals("Job did not run the correct number of times", 6, TestAction2.counter);
System.out.println("Counter = " + TestAction3.counter);
Assert.assertTrue("Job did not run.", TestAction3.counter > 3);
}
use of com.google.cloud.talent.v4.Job in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method testGetJobs.
@Test
public void testGetJobs() throws SchedulerException {
QuartzScheduler testGetJobsSchduler = new QuartzScheduler();
Assert.assertEquals(0, testGetJobsSchduler.getJobs(null).size());
String PARAM_KEY = "testGetJobsKey";
jobParams.put(PARAM_KEY, "testParam1-value");
Calendar calendar = Calendar.getInstance();
int startingMin = calendar.get(Calendar.MINUTE);
int startingSec = calendar.get(Calendar.SECOND) + 10;
if (startingSec > 59) {
startingSec = startingSec % 60;
startingMin++;
if (startingMin > 59) {
startingMin = startingMin % 60;
}
}
calendar.set(Calendar.MINUTE, startingMin);
calendar.set(Calendar.SECOND, startingSec);
SimpleJobTrigger jobTrigger = new SimpleJobTrigger(calendar.getTime(), null, 0, 0);
testGetJobsSchduler.createJob("getJobsTestJob", TestAction.class, jobParams, jobTrigger);
List<Job> jobs = testGetJobsSchduler.getJobs(null);
Assert.assertEquals(1, jobs.size());
Job theJob = jobs.get(0);
Assert.assertTrue(theJob.getJobParams().containsKey(PARAM_KEY));
Assert.assertTrue(theJob.getJobName().contains("getJobsTestJob"));
}
Aggregations