From 45c8c1e5602ac068f50976ef63d092921daaf2fc Mon Sep 17 00:00:00 2001 From: Rustam Sultansoy Date: Sat, 28 Nov 2020 12:04:11 +0200 Subject: [PATCH] Unit test for SimpleScheduler::pause functionality Pause and check isRunning returns false and scheduler doesn't trigger CountDownLatch::countDown --- .../scheduler/test/PausedSchedulerTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/PausedSchedulerTest.java 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 0000000000000..b6038ba7d3d29 --- /dev/null +++ b/extensions/scheduler/deployment/src/test/java/io/quarkus/scheduler/test/PausedSchedulerTest.java @@ -0,0 +1,49 @@ +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(); + } + } + +}