org.quartz.impl.calendar.WeeklyCalendar Java Examples
The following examples show how to use
org.quartz.impl.calendar.WeeklyCalendar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StoreTriggerTest.java From quartz-redis-jobstore with Apache License 2.0 | 6 votes |
@Test
public void resumeTrigger() throws Exception {
// create and store a job and trigger
JobDetail job = getJobDetail();
jobStore.storeJob(job, false);
CronTriggerImpl trigger = getCronTrigger("trigger1", "group1", job.getKey());
trigger.computeFirstFireTime(new WeeklyCalendar());
jobStore.storeTrigger(trigger, false);
// pause the trigger
jobStore.pauseTrigger(trigger.getKey());
assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger.getKey()));
// resume the trigger
jobStore.resumeTrigger(trigger.getKey());
// the trigger state should now be NORMAL
assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));
// attempt to resume the trigger, again
jobStore.resumeTrigger(trigger.getKey());
// the trigger state should not have changed
assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));
}
Example #2
Source File: BaseTest.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
protected CronTriggerImpl getCronTrigger(final String name, final String group, final JobKey jobKey, String cron){ CronTriggerImpl trigger = (CronTriggerImpl) TriggerBuilder.newTrigger() .forJob(jobKey) .withIdentity(name, group) .withSchedule(CronScheduleBuilder.cronSchedule(cron)) .usingJobData("timeout", 5) .withDescription("A description!") .build(); WeeklyCalendar calendar = new WeeklyCalendar(); calendar.setDaysExcluded(new boolean[]{false, false, false, false, false, false, false, false, false}); trigger.computeFirstFireTime(calendar); trigger.setCalendarName("testCalendar"); return trigger; }
Example #3
Source File: BaseTest.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
protected Calendar getCalendar(){ WeeklyCalendar calendar = new WeeklyCalendar(); // exclude weekends calendar.setDayExcluded(1, true); calendar.setDayExcluded(7, true); calendar.setDescription("Only run on weekdays."); return calendar; }
Example #4
Source File: StoreTriggerTest.java From quartz-redis-jobstore with Apache License 2.0 | 4 votes |
@Test
@SuppressWarnings("unchecked")
public void triggersFired() throws Exception {
// store some jobs with triggers
Map<JobDetail, Set<? extends Trigger>> jobsAndTriggers = getJobsAndTriggers(2, 2, 2, 2, "* * * * * ?");
// disallow concurrent execution for one of the jobs
Map.Entry<JobDetail, Set<? extends Trigger>> firstEntry = jobsAndTriggers.entrySet().iterator().next();
JobDetail nonConcurrentKey = firstEntry.getKey().getJobBuilder().ofType(TestJobNonConcurrent.class).build();
Set<? extends Trigger> nonConcurrentTriggers = firstEntry.getValue();
jobsAndTriggers.remove(firstEntry.getKey());
jobsAndTriggers.put(nonConcurrentKey, nonConcurrentTriggers);
jobStore.storeCalendar("testCalendar", new WeeklyCalendar(), false, true);
jobStore.storeJobsAndTriggers(jobsAndTriggers, false);
List<OperableTrigger> acquiredTriggers = jobStore.acquireNextTriggers(System.currentTimeMillis() - 1000, 500, 4000);
assertThat(acquiredTriggers, hasSize(13));
int lockedTriggers = 0;
// ensure that all triggers are in the NORMAL state and have been ACQUIRED
for (Map.Entry<JobDetail, Set<? extends Trigger>> jobDetailSetEntry : jobsAndTriggers.entrySet()) {
for (Trigger trigger : jobDetailSetEntry.getValue()) {
assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));
String triggerHashKey = schema.triggerHashKey(trigger.getKey());
if (jobDetailSetEntry.getKey().isConcurrentExectionDisallowed()) {
if (jedis.zscore(schema.triggerStateKey(RedisTriggerState.ACQUIRED), triggerHashKey) != null) {
assertThat("acquired trigger should be locked", jedis.get(schema.triggerLockKey(schema.triggerKey(triggerHashKey))), notNullValue());
lockedTriggers++;
} else {
assertThat("non-acquired trigger should not be locked", jedis.get(schema.triggerLockKey(schema.triggerKey(triggerHashKey))), nullValue());
}
} else {
assertThat(jedis.zscore(schema.triggerStateKey(RedisTriggerState.ACQUIRED), triggerHashKey), not(nullValue()));
}
}
}
assertThat(lockedTriggers, equalTo(1));
Set<? extends OperableTrigger> triggers = (Set<? extends OperableTrigger>) new ArrayList<>(jobsAndTriggers.entrySet()).get(0).getValue();
List<TriggerFiredResult> triggerFiredResults = jobStore.triggersFired(new ArrayList<>(triggers));
assertThat("exactly one trigger fired for job with concurrent execution disallowed", triggerFiredResults, hasSize(1));
triggers = (Set<? extends OperableTrigger>) new ArrayList<>(jobsAndTriggers.entrySet()).get(1).getValue();
triggerFiredResults = jobStore.triggersFired(new ArrayList<>(triggers));
assertThat("all triggers fired for job with concurrent execution allowed", triggerFiredResults, hasSize(4));
}