forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scheduler: run multiple scheduler implementations
- related to quarkusio#41954
- Loading branch information
Showing
20 changed files
with
722 additions
and
21 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
...loyment/src/test/java/io/quarkus/quartz/test/composite/CompositeSchedulerNotUsedTest.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,36 @@ | ||
package io.quarkus.quartz.test.composite; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class CompositeSchedulerNotUsedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Jobs.class)) | ||
.assertException(t -> { | ||
assertThat(t).cause().isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining( | ||
"The required scheduler implementation is not available because the composite scheduler is not used: SIMPLE"); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
fail(); | ||
} | ||
|
||
static class Jobs { | ||
|
||
@Scheduled(every = "1s", executeWith = Scheduled.SIMPLE) | ||
void quartz() { | ||
} | ||
|
||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...rtz/deployment/src/test/java/io/quarkus/quartz/test/composite/CompositeSchedulerTest.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,99 @@ | ||
package io.quarkus.quartz.test.composite; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.quartz.QuartzScheduler; | ||
import io.quarkus.scheduler.Scheduled; | ||
import io.quarkus.scheduler.Scheduler; | ||
import io.quarkus.scheduler.runtime.Constituent; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.common.annotation.Identifier; | ||
|
||
public class CompositeSchedulerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Jobs.class)) | ||
.overrideConfigKey("quarkus.scheduler.use-composite-scheduler", "true"); | ||
|
||
@Constituent | ||
QuartzScheduler quartz; | ||
|
||
@Constituent | ||
@Identifier("SIMPLE") | ||
Scheduler simple; | ||
|
||
@Inject | ||
Scheduler composite; | ||
|
||
@Test | ||
public void testExecution() throws InterruptedException { | ||
assertTrue(Jobs.simpleLatch.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.quartzLatch.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.autoLatch.await(5, TimeUnit.SECONDS)); | ||
|
||
assertNull(quartz.getScheduledJob("simple")); | ||
assertNotNull(quartz.getScheduledJob("quartz")); | ||
assertNotNull(quartz.getScheduledJob("auto")); | ||
|
||
assertNotNull(simple.getScheduledJob("simple")); | ||
assertNull(simple.getScheduledJob("quartz")); | ||
assertNull(simple.getScheduledJob("auto")); | ||
|
||
assertNotNull(composite.getScheduledJob("quartz")); | ||
assertNotNull(composite.getScheduledJob("auto")); | ||
assertNotNull(composite.getScheduledJob("simple")); | ||
|
||
composite.pause(); | ||
Jobs.reset(); | ||
assertFalse(composite.isRunning()); | ||
assertFalse(Jobs.simpleLatch.await(2, TimeUnit.SECONDS)); | ||
|
||
composite.resume(); | ||
assertTrue(composite.isRunning()); | ||
assertTrue(Jobs.simpleLatch.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.quartzLatch.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.autoLatch.await(5, TimeUnit.SECONDS)); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static CountDownLatch simpleLatch = new CountDownLatch(1); | ||
static CountDownLatch quartzLatch = new CountDownLatch(1); | ||
static CountDownLatch autoLatch = new CountDownLatch(1); | ||
|
||
static void reset() { | ||
simpleLatch = new CountDownLatch(1); | ||
quartzLatch = new CountDownLatch(1); | ||
autoLatch = new CountDownLatch(1); | ||
} | ||
|
||
@Scheduled(identity = "simple", every = "1s", executeWith = Scheduled.SIMPLE) | ||
void simple() { | ||
simpleLatch.countDown(); | ||
} | ||
|
||
@Scheduled(identity = "quartz", every = "1s", executeWith = Scheduled.QUARTZ) | ||
void quartz() { | ||
quartzLatch.countDown(); | ||
} | ||
|
||
@Scheduled(identity = "auto", every = "1s") | ||
void auto() { | ||
autoLatch.countDown(); | ||
} | ||
|
||
} | ||
} |
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
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
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
Oops, something went wrong.