use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.
the class RepositoryCleanerSystemListenerTest method doesNotRescheduleJob_IfFoundSame.
@Test
public void doesNotRescheduleJob_IfFoundSame() throws Exception {
final String oldJobId = "oldJobId";
Job oldJob = new Job();
oldJob.setJobTrigger(Frequency.WEEKLY.createTrigger());
oldJob.setJobId(oldJobId);
when(scheduler.getJobs(any(IJobFilter.class))).thenReturn(Collections.singletonList(oldJob));
prepareMp();
listener.setExecute(Frequency.WEEKLY.getValue());
assertTrue(listener.startup(null));
verify(scheduler, never()).removeJob(oldJobId);
verifyJobHaveNotCreated();
}
use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.
the class QuartzScheduler method getJobs.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List<Job> getJobs(IJobFilter filter) throws SchedulerException {
ArrayList<Job> jobs = new ArrayList<Job>();
try {
Scheduler scheduler = getQuartzScheduler();
for (String groupName : scheduler.getJobGroupNames()) {
for (String jobId : scheduler.getJobNames(groupName)) {
for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
if ("MANUAL_TRIGGER".equals(trigger.getGroup())) {
continue;
}
Job job = new Job();
job.setGroupName(groupName);
JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
if (jobDetail != null) {
job.setUserName(jobDetail.getGroup());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
if (jobDataMap != null) {
Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
job.setJobParams(wrappedMap);
}
}
job.setJobId(jobId);
setJobTrigger(scheduler, job, trigger);
job.setJobName(QuartzJobKey.parse(jobId).getJobName());
setJobNextRun(job, trigger);
job.setLastRun(trigger.getPreviousFireTime());
if ((filter == null) || filter.accept(job)) {
jobs.add(job);
}
}
}
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0004_FAILED_TO_LIST_JOBS"), // $NON-NLS-1$
e);
}
return jobs;
}
use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.
the class QuartzScheduler method getJob.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public Job getJob(String jobId) throws SchedulerException {
try {
Scheduler scheduler = getQuartzScheduler();
QuartzJobKey jobKey = QuartzJobKey.parse(jobId);
String groupName = jobKey.getUserName();
for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
Job job = new Job();
JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
if (jobDetail != null) {
JobDataMap jobDataMap = jobDetail.getJobDataMap();
if (jobDataMap != null) {
Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
job.setJobParams(wrappedMap);
}
}
job.setJobId(jobId);
setJobTrigger(scheduler, job, trigger);
job.setUserName(jobDetail.getGroup());
return job;
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0007_FAILED_TO_GET_JOB", jobId), // $NON-NLS-1$
e);
}
return null;
}
use of com.google.cloud.video.transcoder.v1.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"));
}
use of com.google.cloud.video.transcoder.v1.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);
}
Aggregations