-
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.
Consolidate scheduler extension - part 1
- introduce lightweight scheduler implementation in quarkus-scheduler - introduce quarkus-quartz based on quarkus-scheduler build steps and API - remove Scheduler#startTimer() method - add proper intergration test
- Loading branch information
Showing
42 changed files
with
1,368 additions
and
405 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-quartz-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-quartz-deployment</artifactId> | ||
<name>Quarkus - Scheduler Quartz - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-scheduler-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-quartz</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
82 changes: 82 additions & 0 deletions
82
extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.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,82 @@ | ||
package io.quarkus.quartz.deployment; | ||
|
||
import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.quartz.simpl.CascadingClassLoadHelper; | ||
import org.quartz.simpl.RAMJobStore; | ||
import org.quartz.simpl.SimpleThreadPool; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.arc.deployment.BeanContainerBuildItem; | ||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.CapabilityBuildItem; | ||
import io.quarkus.deployment.builditem.ServiceStartBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.deployment.logging.LogCleanupFilterBuildItem; | ||
import io.quarkus.quartz.runtime.QuartzRecorder; | ||
import io.quarkus.quartz.runtime.QuartzRuntimeConfig; | ||
import io.quarkus.quartz.runtime.QuartzScheduler; | ||
import io.quarkus.quartz.runtime.QuartzSupport; | ||
|
||
/** | ||
* @author Martin Kouba | ||
*/ | ||
public class QuartzProcessor { | ||
|
||
@BuildStep | ||
CapabilityBuildItem capability() { | ||
return new CapabilityBuildItem(Capabilities.QUARTZ); | ||
} | ||
|
||
@BuildStep | ||
AdditionalBeanBuildItem beans() { | ||
return new AdditionalBeanBuildItem(QuartzScheduler.class, QuartzSupport.class); | ||
} | ||
|
||
@BuildStep | ||
List<ReflectiveClassBuildItem> reflectiveClasses() { | ||
List<ReflectiveClassBuildItem> reflectiveClasses = new ArrayList<>(); | ||
reflectiveClasses.add(new ReflectiveClassBuildItem(false, false, CascadingClassLoadHelper.class.getName())); | ||
reflectiveClasses.add(new ReflectiveClassBuildItem(true, false, SimpleThreadPool.class.getName())); | ||
reflectiveClasses.add(new ReflectiveClassBuildItem(true, false, RAMJobStore.class.getName())); | ||
return reflectiveClasses; | ||
} | ||
|
||
@BuildStep | ||
public void logCleanup(BuildProducer<LogCleanupFilterBuildItem> logCleanupFilter) { | ||
logCleanupFilter.produce(new LogCleanupFilterBuildItem("org.quartz.impl.StdSchedulerFactory", | ||
"Quartz scheduler version:", | ||
// no need to log if it's the default | ||
"Using default implementation for", | ||
"Quartz scheduler 'DefaultQuartzScheduler'")); | ||
|
||
logCleanupFilter.produce(new LogCleanupFilterBuildItem("org.quartz.core.QuartzScheduler", | ||
"Quartz Scheduler v", | ||
"JobFactory set to:", | ||
"Scheduler meta-data:", | ||
// no need to log if it's the default | ||
"Scheduler DefaultQuartzScheduler")); | ||
|
||
logCleanupFilter.produce(new LogCleanupFilterBuildItem("org.quartz.simpl.RAMJobStore", | ||
"RAMJobStore initialized.")); | ||
|
||
logCleanupFilter.produce(new LogCleanupFilterBuildItem("org.quartz.core.SchedulerSignalerImpl", | ||
"Initialized Scheduler Signaller of type")); | ||
} | ||
|
||
@BuildStep | ||
@Record(RUNTIME_INIT) | ||
public void build(QuartzRuntimeConfig runtimeConfig, QuartzRecorder recorder, BeanContainerBuildItem beanContainer, | ||
BuildProducer<ServiceStartBuildItem> serviceStart) { | ||
recorder.initialize(runtimeConfig, beanContainer.getValue()); | ||
// Make sure that StartupEvent is fired after the init | ||
serviceStart.produce(new ServiceStartBuildItem("quartz")); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ons/quartz/deployment/src/test/java/io/quarkus/quartz/test/InvalidCronExpressionTest.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,33 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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 InvalidCronExpressionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(DeploymentException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(InvalidBean.class)); | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
} | ||
|
||
static class InvalidBean { | ||
|
||
@Scheduled(cron = "0 0 0 ????") | ||
void wrong() { | ||
} | ||
|
||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ns/quartz/deployment/src/test/java/io/quarkus/quartz/test/InvalidEveryExpressionTest.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,33 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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 InvalidEveryExpressionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(DeploymentException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(InvalidEveryExpressionTest.InvalidBean.class)); | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
} | ||
|
||
static class InvalidBean { | ||
|
||
@Scheduled(every = "call me every other day") | ||
void wrong() { | ||
} | ||
|
||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...artz/deployment/src/test/java/io/quarkus/quartz/test/MissingConfigCronExpressionTest.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,33 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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 MissingConfigCronExpressionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(NoSuchElementException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MissingConfigCronExpressionTest.InvalidBean.class)); | ||
|
||
@Test | ||
public void test() { | ||
} | ||
|
||
static class InvalidBean { | ||
|
||
@Scheduled(cron = "{my.cron}") | ||
void wrong() { | ||
} | ||
|
||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/NoExpressionTest.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,33 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import javax.enterprise.inject.spi.DeploymentException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
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 NoExpressionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setExpectedException(DeploymentException.class) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(InvalidBean.class)); | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
} | ||
|
||
static class InvalidBean { | ||
|
||
@Scheduled | ||
void wrong() { | ||
} | ||
|
||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/RequestContextJobs.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,40 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
|
||
public class RequestContextJobs { | ||
|
||
static final CountDownLatch LATCH = new CountDownLatch(1); | ||
|
||
@Inject | ||
RequestFoo foo; | ||
|
||
@Scheduled(every = "1s") | ||
void checkEverySecond() { | ||
foo.getName(); | ||
LATCH.countDown(); | ||
} | ||
|
||
@RequestScoped | ||
static class RequestFoo { | ||
|
||
private String name; | ||
|
||
@PostConstruct | ||
void init() { | ||
name = "oof"; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.