diff --git a/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/PausedSchedulerTest.java b/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/PausedSchedulerTest.java new file mode 100644 index 00000000000000..4810c3d87c1067 --- /dev/null +++ b/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/PausedSchedulerTest.java @@ -0,0 +1,48 @@ +package io.quarkus.scheduler.test; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +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.scheduler.Scheduler; +import io.quarkus.test.QuarkusUnitTest; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class PausedSchedulerTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(DisabledSchedulerTest.Jobs.class) + .addAsResource(new StringAsset("quarkus.scheduler.enabled=true"), + "application.properties")); + + @Inject + Scheduler scheduler; + + @Test + public void testSchedulerPauseMethod() throws InterruptedException { + scheduler.pause(); + assertFalse(scheduler.isRunning()); + assertFalse(Jobs.LATCH.await(3, TimeUnit.SECONDS)); + } + + static class Jobs { + static final CountDownLatch LATCH = new CountDownLatch(2); + + @Scheduled(every = "1s") + void countDownSecond() { + LATCH.countDown(); + } + } + +}