-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to configure Quartz misfire handling strategy
- Loading branch information
Showing
4 changed files
with
259 additions
and
3 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/MisfirePolicyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.quartz.CronTrigger; | ||
import org.quartz.SchedulerException; | ||
import org.quartz.SimpleTrigger; | ||
import org.quartz.Trigger; | ||
import org.quartz.TriggerKey; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
import io.quarkus.scheduler.Scheduler; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MisfirePolicyTest { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(MisfirePolicyTest.class.getName()); | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.quartz.\"simple_ignore_misfire_policy\".misfire-policy=IGNORE_MISFIRE_POLICY\n" + | ||
"quarkus.quartz.\"cron_ignore_misfire_policy\".misfire-policy=IGNORE_MISFIRE_POLICY\n" + | ||
"quarkus.quartz.\"simple_invalid_misfire_policy\".misfire-policy=CRON_TRIGGER_DO_NOTHING\n" | ||
+ | ||
"quarkus.quartz.\"cron_invalid_misfire_policy\".misfire-policy=SIMPLE_TRIGGER_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT\n" | ||
+ | ||
"quarkus.quartz.\"simple_reschedule_now_existing_policy\".misfire-policy=SIMPLE_TRIGGER_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT\n" | ||
+ | ||
"quarkus.quartz.\"simple_reschedule_now_remaining_policy\".misfire-policy=SIMPLE_TRIGGER_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT\n" | ||
+ | ||
"quarkus.quartz.\"simple_reschedule_next_existing_policy\".misfire-policy=SIMPLE_TRIGGER_RESCHEDULE_NEXT_WITH_EXISTING_COUNT\n" | ||
+ | ||
"quarkus.quartz.\"simple_reschedule_next_remaining_policy\".misfire-policy=SIMPLE_TRIGGER_RESCHEDULE_NEXT_WITH_REMAINING_COUNT\n" | ||
+ | ||
"quarkus.quartz.\"cron_do_nothing_policy\".misfire-policy=CRON_TRIGGER_DO_NOTHING\n" | ||
|
||
), "application.properties")); | ||
|
||
@Inject | ||
org.quartz.Scheduler quartz; | ||
|
||
@Test | ||
public void testDefaultMisfirePolicy() throws SchedulerException { | ||
Trigger defaultMisfirePolicy = quartz | ||
.getTrigger(new TriggerKey("default_misfire_policy", Scheduler.class.getName())); | ||
assertNotNull(defaultMisfirePolicy); | ||
assertEquals(Trigger.MISFIRE_INSTRUCTION_SMART_POLICY, defaultMisfirePolicy.getMisfireInstruction()); | ||
|
||
} | ||
|
||
@Test | ||
public void testIgnoreMisfirePolicy() throws SchedulerException { | ||
Trigger simpleIgnoreMisfirePolicyTrigger = quartz | ||
.getTrigger(new TriggerKey("simple_ignore_misfire_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleIgnoreMisfirePolicyTrigger); | ||
assertEquals(Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY, | ||
simpleIgnoreMisfirePolicyTrigger.getMisfireInstruction()); | ||
|
||
Trigger cronIgnoreMisfirePolicyTrigger = quartz | ||
.getTrigger(new TriggerKey("cron_ignore_misfire_policy", Scheduler.class.getName())); | ||
assertNotNull(cronIgnoreMisfirePolicyTrigger); | ||
assertEquals(Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY, cronIgnoreMisfirePolicyTrigger.getMisfireInstruction()); | ||
} | ||
|
||
@Test | ||
public void testInvalidMisfirePolicy() throws SchedulerException { | ||
Trigger simpleInvalidMisfirePolicyTrigger = quartz | ||
.getTrigger(new TriggerKey("simple_invalid_misfire_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleInvalidMisfirePolicyTrigger); | ||
assertEquals(Trigger.MISFIRE_INSTRUCTION_SMART_POLICY, simpleInvalidMisfirePolicyTrigger.getMisfireInstruction()); | ||
|
||
Trigger cronInvalidMisfirePolicyTrigger = quartz | ||
.getTrigger(new TriggerKey("cron_invalid_misfire_policy", Scheduler.class.getName())); | ||
assertNotNull(cronInvalidMisfirePolicyTrigger); | ||
assertEquals(Trigger.MISFIRE_INSTRUCTION_SMART_POLICY, cronInvalidMisfirePolicyTrigger.getMisfireInstruction()); | ||
} | ||
|
||
@Test | ||
public void testSimpleTriggerMisfirePolicy() throws SchedulerException { | ||
Trigger simpleRescheduleNowExistingPolicy = quartz | ||
.getTrigger(new TriggerKey("simple_reschedule_now_existing_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleRescheduleNowExistingPolicy); | ||
assertEquals(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT, | ||
simpleRescheduleNowExistingPolicy.getMisfireInstruction()); | ||
|
||
Trigger simpleRescheduleNowRemainingPolicy = quartz | ||
.getTrigger(new TriggerKey("simple_reschedule_now_remaining_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleRescheduleNowRemainingPolicy); | ||
assertEquals(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT, | ||
simpleRescheduleNowRemainingPolicy.getMisfireInstruction()); | ||
|
||
Trigger simpleRescheduleNextExistingPolicy = quartz | ||
.getTrigger(new TriggerKey("simple_reschedule_next_existing_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleRescheduleNextExistingPolicy); | ||
assertEquals(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT, | ||
simpleRescheduleNextExistingPolicy.getMisfireInstruction()); | ||
|
||
Trigger simpleRescheduleNextRemainingPolicy = quartz | ||
.getTrigger(new TriggerKey("simple_reschedule_next_remaining_policy", Scheduler.class.getName())); | ||
assertNotNull(simpleRescheduleNextRemainingPolicy); | ||
assertEquals(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT, | ||
simpleRescheduleNextRemainingPolicy.getMisfireInstruction()); | ||
} | ||
|
||
@Test | ||
public void testCronTriggerMisfirePolicy() throws SchedulerException { | ||
Trigger cronDoNothingPolicy = quartz.getTrigger(new TriggerKey("cron_do_nothing_policy", Scheduler.class.getName())); | ||
assertNotNull(cronDoNothingPolicy); | ||
assertEquals(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING, cronDoNothingPolicy.getMisfireInstruction()); | ||
} | ||
|
||
static class Jobs { | ||
|
||
@Scheduled(identity = "default_misfire_policy", every = "1s") | ||
void defaultMisfirePolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_ignore_misfire_policy", every = "1s") | ||
void simpleIgnoreMisfirePolicy() { | ||
} | ||
|
||
@Scheduled(identity = "cron_ignore_misfire_policy", cron = "0/1 * * * * ?") | ||
void cronIgnoreMisfirePolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_invalid_misfire_policy", every = "1s") | ||
void simpleInvalidMisfirePolicy() { | ||
} | ||
|
||
@Scheduled(identity = "cron_invalid_misfire_policy", cron = "0/1 * * * * ?") | ||
void cronInvalidMisfirePolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_reschedule_now_existing_policy", every = "1s") | ||
void simpleRescheduleNowExistingPolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_reschedule_now_remaining_policy", every = "1s") | ||
void simpleRescheduleNowRemainingPolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_reschedule_next_existing_policy", every = "1s") | ||
void simpleRescheduleNextExistingPolicy() { | ||
} | ||
|
||
@Scheduled(identity = "simple_reschedule_next_remaining_policy", every = "1s") | ||
void simpleRescheduleNextRemainingPolicy() { | ||
} | ||
|
||
@Scheduled(identity = "cron_do_nothing_policy", cron = "0/1 * * * * ?") | ||
void cronDoNothingPolicy() { | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzMisfirePolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkus.quartz.runtime; | ||
|
||
public enum QuartzMisfirePolicy { | ||
SMART_POLICY, | ||
IGNORE_MISFIRE_POLICY, | ||
FIRE_NOW, | ||
SIMPLE_TRIGGER_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT, | ||
SIMPLE_TRIGGER_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT, | ||
SIMPLE_TRIGGER_RESCHEDULE_NEXT_WITH_REMAINING_COUNT, | ||
SIMPLE_TRIGGER_RESCHEDULE_NEXT_WITH_EXISTING_COUNT, | ||
CRON_TRIGGER_DO_NOTHING | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters