-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Support for Default Value and for Switching Timer Off
- Loading branch information
Showing
10 changed files
with
430 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...s/quartz/deployment/src/test/java/io/quarkus/quartz/test/DisabledScheduledMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.test.QuarkusUnitTest; | ||
|
||
public class DisabledScheduledMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("DisabledScheduledMethodTest.interval=disabled"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testNoSchedulerInvocations() throws InterruptedException { | ||
Thread.sleep(100); | ||
Jobs.LATCH.await(500, TimeUnit.MILLISECONDS); | ||
assertEquals(0, Jobs.executionCounter); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch LATCH = new CountDownLatch(1); | ||
|
||
static volatile int executionCounter = 0; | ||
|
||
@Scheduled(every = "{DisabledScheduledMethodTest.interval}") | ||
void disabledByConfigValue() { | ||
executionCounter++; | ||
} | ||
|
||
@Scheduled(every = "{non.existent.property:disabled}") | ||
void disabledByDefault() { | ||
executionCounter++; | ||
} | ||
|
||
@Scheduled(every = "0.001s") | ||
void enabled() { | ||
LATCH.countDown(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...tz/deployment/src/test/java/io/quarkus/quartz/test/PropertyDefaultValueSchedulerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.ScheduledExecution; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class PropertyDefaultValueSchedulerTest { | ||
|
||
private static final String EXPECTED_IDENTITY = "TestIdentity"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("PropertyDefaultValueSchedulerTest.default=" + EXPECTED_IDENTITY), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testDefaultIdentity() throws InterruptedException { | ||
assertTrue(Jobs.LATCH.await(500, TimeUnit.MILLISECONDS), "Scheduler was not triggered"); | ||
assertNotNull(Jobs.execution); | ||
final String actualIdentity = Jobs.execution.getTrigger().getId(); | ||
assertTrue(actualIdentity.contains(EXPECTED_IDENTITY), | ||
"<" + actualIdentity + "> did not contain: " + EXPECTED_IDENTITY); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch LATCH = new CountDownLatch(1); | ||
|
||
static ScheduledExecution execution; | ||
|
||
@Scheduled(every = "0.001s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}") | ||
void trigger(ScheduledExecution execution) { | ||
if (this.execution == null) { | ||
this.execution = execution; | ||
} | ||
LATCH.countDown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...duler/deployment/src/test/java/io/quarkus/scheduler/test/DisabledScheduledMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.scheduler.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.test.QuarkusUnitTest; | ||
|
||
public class DisabledScheduledMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("DisabledScheduledMethodTest.interval=off"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testNoSchedulerInvocations() throws InterruptedException { | ||
Thread.sleep(100); | ||
Jobs.LATCH.await(500, TimeUnit.MILLISECONDS); | ||
assertEquals(0, Jobs.executionCounter); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch LATCH = new CountDownLatch(1); | ||
|
||
static volatile int executionCounter = 0; | ||
|
||
@Scheduled(every = "{DisabledScheduledMethodTest.interval}") | ||
void disabledByConfigValue() { | ||
executionCounter++; | ||
} | ||
|
||
@Scheduled(every = "{non.existent.property:disabled}") | ||
void disabledByDefault() { | ||
executionCounter++; | ||
} | ||
|
||
@Scheduled(every = "0.001s") | ||
void enabled() { | ||
LATCH.countDown(); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...deployment/src/test/java/io/quarkus/scheduler/test/PropertyDefaultValueSchedulerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.scheduler.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
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.ScheduledExecution; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class PropertyDefaultValueSchedulerTest { | ||
|
||
private static final String EXPECTED_IDENTITY = "TestIdentity"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("PropertyDefaultValueSchedulerTest.default=" + EXPECTED_IDENTITY), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testDefaultIdentity() throws InterruptedException { | ||
assertTrue(Jobs.LATCH.await(500, TimeUnit.MILLISECONDS), "Scheduler was not triggered"); | ||
assertNotNull(Jobs.execution); | ||
assertEquals(EXPECTED_IDENTITY, Jobs.execution.getTrigger().getId()); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch LATCH = new CountDownLatch(1); | ||
|
||
static ScheduledExecution execution; | ||
|
||
@Scheduled(every = "0.001s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}") | ||
void trigger(ScheduledExecution execution) { | ||
if (this.execution == null) { | ||
this.execution = execution; | ||
} | ||
LATCH.countDown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.