Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SimpleScheduler pause functionality #13532

Merged
merged 1 commit into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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