-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make newScheduledExecutor public and move to StandardLifecycles
* Move newScheduledExecutor from MonitoredJobs to StandardLifecycles * Update the javadocs in StandardLifecycles since it is no longer just about setting up lifecycle listeners * Since MonitoredJobsTest and StandardLifecyclesTest had the same code to shut down the ScheduledExecutorService, moved that code into a new shared test utility, TestExecutors, which ensures the executor is gracefully shut down once the test is finished with it Closes #109
- Loading branch information
1 parent
2c7cd4e
commit af4176c
Showing
5 changed files
with
118 additions
and
45 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
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
27 changes: 27 additions & 0 deletions
27
src/test/java/org/kiwiproject/dropwizard/util/concurrent/TestExecutors.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,27 @@ | ||
package org.kiwiproject.dropwizard.util.concurrent; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
|
||
@Slf4j | ||
public class TestExecutors { | ||
|
||
/** | ||
* Perform actions using the given executor inside the Consumer, then shut the executor service down and | ||
* await termination (with timeout). | ||
*/ | ||
public static void use(ScheduledExecutorService executor, Consumer<ScheduledExecutorService> consumer) | ||
throws InterruptedException { | ||
|
||
try { | ||
consumer.accept(executor); | ||
} finally { | ||
executor.shutdown(); | ||
var terminatedOk = executor.awaitTermination(500, TimeUnit.MILLISECONDS); | ||
LOG.info("terminated OK within timeout period? {}", terminatedOk); | ||
} | ||
} | ||
} |
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
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