diff --git a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/ApplicationNotRunningPredicateTest.java b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/ApplicationNotRunningPredicateTest.java new file mode 100644 index 0000000000000..8cb4bcda0915d --- /dev/null +++ b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/ApplicationNotRunningPredicateTest.java @@ -0,0 +1,57 @@ +package io.quarkus.quartz.test; + +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.enterprise.event.Observes; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.StartupEvent; +import io.quarkus.scheduler.FailedExecution; +import io.quarkus.scheduler.Scheduled; +import io.quarkus.scheduler.SuccessfulExecution; +import io.quarkus.test.QuarkusUnitTest; + +public class ApplicationNotRunningPredicateTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest().withApplicationRoot((jar) -> jar.addClasses(Jobs.class)); + + static final CountDownLatch SUCCESS_LATCH = new CountDownLatch(1); + static volatile FailedExecution failedExecution; + + @Test + public void testTriggerErrorStatus() throws InterruptedException { + assertTrue(SUCCESS_LATCH.await(5, TimeUnit.SECONDS)); + assertNull(failedExecution); + } + + void observeSuccessfulExecution(@Observes SuccessfulExecution successfulExecution) { + SUCCESS_LATCH.countDown(); + } + + void observeFailedExecution(@Observes FailedExecution failedExecution) { + ApplicationNotRunningPredicateTest.failedExecution = failedExecution; + } + + static class Jobs { + + volatile boolean started; + + void started(@Observes StartupEvent event) { + started = true; + } + + @Scheduled(every = "0.2s", skipExecutionIf = Scheduled.ApplicationNotRunning.class) + void scheduleAfterStarted() { + if (!started) { + throw new IllegalStateException(); + } + } + } +} diff --git a/extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/SchedulerProcessor.java b/extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/SchedulerProcessor.java index 82c9a9ba89d69..761598d93a6bc 100644 --- a/extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/SchedulerProcessor.java +++ b/extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/SchedulerProcessor.java @@ -98,8 +98,9 @@ public class SchedulerProcessor { @BuildStep void beans(Capabilities capabilities, BuildProducer additionalBeans) { + additionalBeans.produce(new AdditionalBeanBuildItem(Scheduled.ApplicationNotRunning.class)); if (capabilities.isMissing(Capability.QUARTZ)) { - additionalBeans.produce(new AdditionalBeanBuildItem(SimpleScheduler.class, Scheduled.ApplicationNotRunning.class)); + additionalBeans.produce(new AdditionalBeanBuildItem(SimpleScheduler.class)); } } diff --git a/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/ApplicationNotRunningPredicateTest.java b/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/ApplicationNotRunningPredicateTest.java index 6318d8ecb0d31..c7b246ebe2b0b 100644 --- a/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/ApplicationNotRunningPredicateTest.java +++ b/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/ApplicationNotRunningPredicateTest.java @@ -6,9 +6,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import jakarta.annotation.Priority; import jakarta.enterprise.event.Observes; -import jakarta.interceptor.Interceptor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -43,15 +41,15 @@ void observeFailedExecution(@Observes FailedExecution failedExecution) { static class Jobs { - volatile boolean preStart; + volatile boolean started; - void started(@Observes @Priority(Interceptor.Priority.PLATFORM_BEFORE) StartupEvent event) { - preStart = true; + void started(@Observes StartupEvent event) { + started = true; } @Scheduled(every = "0.2s", skipExecutionIf = Scheduled.ApplicationNotRunning.class) void scheduleAfterStarted() { - if (!preStart) { + if (!started) { throw new IllegalStateException(); } } diff --git a/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java index 7f3897f6c3671..0238f61946b2f 100644 --- a/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java +++ b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java @@ -28,9 +28,9 @@ public class OpenTelemetryQuartzTest { @Test public void quartzSpanTest() { // ensure that scheduled job is called - assertCounter("/scheduler/count", 1, Duration.ofSeconds(1)); + assertCounter("/scheduler/count", 1, Duration.ofSeconds(3)); // assert programmatically scheduled job is called - assertCounter("/scheduler/count/manual", 1, Duration.ofSeconds(1)); + assertCounter("/scheduler/count/manual", 1, Duration.ofSeconds(3)); // assert JobDefinition type scheduler assertCounter("/scheduler/count/job-definition", 1, Duration.ofSeconds(1)); @@ -53,6 +53,7 @@ public void quartzSpanTest() { private void assertCounter(String counterPath, int expectedCount, Duration timeout) { await().atMost(timeout) + .pollInterval(Duration.ofMillis(500)) .until(() -> { Response response = given().when().get(counterPath); int code = response.statusCode(); diff --git a/integration-tests/opentelemetry-scheduler/src/test/java/io/quarkus/it/opentelemetry/scheduler/OpenTelemetrySchedulerTest.java b/integration-tests/opentelemetry-scheduler/src/test/java/io/quarkus/it/opentelemetry/scheduler/OpenTelemetrySchedulerTest.java index c33b61ccff386..28652a8ddd4c5 100644 --- a/integration-tests/opentelemetry-scheduler/src/test/java/io/quarkus/it/opentelemetry/scheduler/OpenTelemetrySchedulerTest.java +++ b/integration-tests/opentelemetry-scheduler/src/test/java/io/quarkus/it/opentelemetry/scheduler/OpenTelemetrySchedulerTest.java @@ -28,9 +28,9 @@ public class OpenTelemetrySchedulerTest { @Test public void schedulerSpanTest() { // ensure that scheduled job is called - assertCounter("/scheduler/count", 1, Duration.ofSeconds(1)); + assertCounter("/scheduler/count", 1, Duration.ofSeconds(3)); // assert JobDefinition type scheduler - assertCounter("/scheduler/count/job-definition", 1, Duration.ofSeconds(1)); + assertCounter("/scheduler/count/job-definition", 1, Duration.ofSeconds(3)); // ------- SPAN ASSERTS ------- List> spans = getSpans(); @@ -48,6 +48,7 @@ public void schedulerSpanTest() { private void assertCounter(String counterPath, int expectedCount, Duration timeout) { await().atMost(timeout) + .pollInterval(Duration.ofMillis(500)) .until(() -> { Response response = given().when().get(counterPath); int code = response.statusCode();