mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-01 11:49:04 +00:00
Merge branch '7.0.x'
This commit is contained in:
+10
-8
@@ -21,6 +21,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -153,17 +154,18 @@ class SimpleAsyncTaskExecutorTests {
|
||||
|
||||
@Test
|
||||
void taskTerminationTimeoutWithImmediateCancel() {
|
||||
AtomicBoolean finished = new AtomicBoolean();
|
||||
AtomicReference<Runnable> captured = new AtomicReference<>();
|
||||
Future<?> future;
|
||||
try (SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor()) {
|
||||
try (SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor() {
|
||||
@Override
|
||||
protected void doExecute(Runnable task) {
|
||||
captured.set(task);
|
||||
}
|
||||
}) {
|
||||
executor.setTaskTerminationTimeout(100);
|
||||
future = executor.submit(() -> {
|
||||
if (finished.get()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
});
|
||||
future = executor.submit(() -> {});
|
||||
}
|
||||
finished.set(true);
|
||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(captured.get()::run);
|
||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(future::get);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user