Skip to content

Commit

Permalink
[hotfix] Make TestExecutorResource generic in the ExecutorService
Browse files Browse the repository at this point in the history
Making the TestExecutorResource generic in the ExecutorService has the advantage that the resource
can also manage and return SchedulerExecutorServices.
  • Loading branch information
tillrohrmann committed Mar 20, 2021
1 parent ce55b21 commit 848e6d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public class TaskExecutorPartitionLifecycleTest extends TestLogger {
@Rule public final TemporaryFolder tmp = new TemporaryFolder();

@ClassRule
public static final TestExecutorResource TEST_EXECUTOR_SERVICE_RESOURCE =
new TestExecutorResource(() -> java.util.concurrent.Executors.newFixedThreadPool(1));
public static final TestExecutorResource<?> TEST_EXECUTOR_SERVICE_RESOURCE =
new TestExecutorResource<>(() -> java.util.concurrent.Executors.newFixedThreadPool(1));

@Before
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@

import org.junit.rules.ExternalResource;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

/** Resource which starts/stops an {@link ExecutorService} for testing purposes. */
public class TestExecutorResource extends ExternalResource {
public class TestExecutorResource<T extends ExecutorService> extends ExternalResource {

private final Supplier<ExecutorService> serviceFactory;
private final Supplier<T> serviceFactory;

private ExecutorService executorService;
private T executorService;

public TestExecutorResource(Supplier<ExecutorService> serviceFactory) {
public TestExecutorResource(Supplier<T> serviceFactory) {
this.serviceFactory = serviceFactory;
}

Expand All @@ -39,7 +38,7 @@ protected void before() throws Throwable {
executorService = serviceFactory.get();
}

public Executor getExecutor() {
public T getExecutor() {
// only return an Executor since this resource is in charge of the life cycle
return executorService;
}
Expand Down

0 comments on commit 848e6d8

Please sign in to comment.