-
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.
Merge pull request #10451 from mkouba/scheduler-fix-concurrent-exec-t…
…ests Scheduler - make tests for concurrent execution more robust
- Loading branch information
Showing
10 changed files
with
277 additions
and
119 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...uartz/deployment/src/test/java/io/quarkus/quartz/test/ConcurrentExecutionProceedTest.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.fail; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 ConcurrentExecutionProceedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class)); | ||
|
||
@Test | ||
public void testExecution() { | ||
try { | ||
// Wait until Jobs#concurrent() is executed 3x and skipped 0x | ||
if (Jobs.START_LATCH.await(10, TimeUnit.SECONDS)) { | ||
// Unblock all executions | ||
Jobs.BLOCKING_LATCH.countDown(); | ||
} else { | ||
fail("Jobs were not executed in 10 seconds!"); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch BLOCKING_LATCH = new CountDownLatch(1); | ||
|
||
static final CountDownLatch START_LATCH = new CountDownLatch(3); | ||
|
||
@Scheduled(every = "1s") | ||
void concurrent() throws InterruptedException { | ||
START_LATCH.countDown(); | ||
if (!BLOCKING_LATCH.await(10, TimeUnit.SECONDS)) { | ||
throw new IllegalStateException("concurrent() execution blocked too long..."); | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...s/quartz/deployment/src/test/java/io/quarkus/quartz/test/ConcurrentExecutionSkipTest.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,66 @@ | ||
package io.quarkus.quartz.test; | ||
|
||
import static io.quarkus.scheduler.Scheduled.ConcurrentExecution.SKIP; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.event.Observes; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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.SkippedExecution; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConcurrentExecutionSkipTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class)); | ||
|
||
@Test | ||
public void testExecution() { | ||
try { | ||
// Wait until Jobs#nonconcurrent() is executed 1x and skipped 1x | ||
if (Jobs.SKIPPED_LATCH.await(10, TimeUnit.SECONDS)) { | ||
// Exactly one job is blocked | ||
assertEquals(1, Jobs.COUNTER.get()); | ||
// Unblock all executions | ||
Jobs.BLOCKING_LATCH.countDown(); | ||
} else { | ||
fail("Jobs were not executed in 10 seconds!"); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch BLOCKING_LATCH = new CountDownLatch(1); | ||
|
||
static final AtomicInteger COUNTER = new AtomicInteger(0); | ||
static final CountDownLatch SKIPPED_LATCH = new CountDownLatch(1); | ||
|
||
@Scheduled(every = "1s", concurrentExecution = SKIP) | ||
void nonconcurrent() throws InterruptedException { | ||
COUNTER.incrementAndGet(); | ||
if (!BLOCKING_LATCH.await(10, TimeUnit.SECONDS)) { | ||
throw new IllegalStateException("nonconcurrent() execution blocked too long..."); | ||
} | ||
} | ||
|
||
void onSkip(@Observes SkippedExecution event) { | ||
SKIPPED_LATCH.countDown(); | ||
} | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
...sions/quartz/deployment/src/test/java/io/quarkus/quartz/test/ConcurrentExecutionTest.java
This file was deleted.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
...er/deployment/src/test/java/io/quarkus/scheduler/test/ConcurrentExecutionProceedTest.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.scheduler.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 ConcurrentExecutionProceedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class)); | ||
|
||
@Test | ||
public void testExecution() { | ||
try { | ||
// Wait until Jobs#concurrent() is executed 3x and skipped 0x | ||
if (Jobs.START_LATCH.await(10, TimeUnit.SECONDS)) { | ||
// Unblock all executions | ||
Jobs.BLOCKING_LATCH.countDown(); | ||
} else { | ||
fail("Jobs were not executed in 10 seconds!"); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch BLOCKING_LATCH = new CountDownLatch(1); | ||
|
||
static final CountDownLatch START_LATCH = new CountDownLatch(3); | ||
|
||
@Scheduled(every = "1s") | ||
void concurrent() throws InterruptedException { | ||
START_LATCH.countDown(); | ||
if (!BLOCKING_LATCH.await(10, TimeUnit.SECONDS)) { | ||
throw new IllegalStateException("concurrent() execution blocked too long..."); | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...duler/deployment/src/test/java/io/quarkus/scheduler/test/ConcurrentExecutionSkipTest.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,66 @@ | ||
package io.quarkus.scheduler.test; | ||
|
||
import static io.quarkus.scheduler.Scheduled.ConcurrentExecution.SKIP; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.enterprise.event.Observes; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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.SkippedExecution; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConcurrentExecutionSkipTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class)); | ||
|
||
@Test | ||
public void testExecution() { | ||
try { | ||
// Wait until Jobs#nonconcurrent() is executed 1x and skipped 1x | ||
if (Jobs.SKIPPED_LATCH.await(10, TimeUnit.SECONDS)) { | ||
// Exactly one job is blocked | ||
assertEquals(1, Jobs.COUNTER.get()); | ||
// Unblock all executions | ||
Jobs.BLOCKING_LATCH.countDown(); | ||
} else { | ||
fail("Jobs were not executed in 10 seconds!"); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch BLOCKING_LATCH = new CountDownLatch(1); | ||
|
||
static final AtomicInteger COUNTER = new AtomicInteger(0); | ||
static final CountDownLatch SKIPPED_LATCH = new CountDownLatch(1); | ||
|
||
@Scheduled(every = "1s", concurrentExecution = SKIP) | ||
void nonconcurrent() throws InterruptedException { | ||
COUNTER.incrementAndGet(); | ||
if (!BLOCKING_LATCH.await(10, TimeUnit.SECONDS)) { | ||
throw new IllegalStateException("nonconcurrent() execution blocked too long..."); | ||
} | ||
} | ||
|
||
void onSkip(@Observes SkippedExecution event) { | ||
SKIPPED_LATCH.countDown(); | ||
} | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
...scheduler/deployment/src/test/java/io/quarkus/scheduler/test/ConcurrentExecutionTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.