Skip to content

Commit

Permalink
Fix SimpleScheduler pause functionality.
Browse files Browse the repository at this point in the history
Add return in SimpleScheduler::checkTriggers method if !running.

Unit test for SimpleScheduler::pause functionality
Pause and check isRunning returns false and scheduler doesn't trigger CountDownLatch::countDown
  • Loading branch information
sultansoy authored and RustamSultansoy committed Nov 28, 2020
1 parent dff9345 commit 5bbc400
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.scheduler.test;

import static org.junit.jupiter.api.Assertions.assertFalse;

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;

public class PausedSchedulerTest {

@RegisterExtension
static final QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(PausedSchedulerTest.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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void stop() {
void checkTriggers() {
if (!running) {
LOGGER.trace("Skip all triggers - scheduler paused");
return;
}
ZonedDateTime now = ZonedDateTime.now();
for (ScheduledTask task : scheduledTasks) {
Expand Down

0 comments on commit 5bbc400

Please sign in to comment.