Attempt to make AbstractSchedulingTaskExecutorTests more robust
This commit is contained in:
parent
4b9f5a35a6
commit
32277b74db
|
|
@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 5.0.5
|
* @since 5.0.5
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSchedulingTaskExecutorTests {
|
public abstract class AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
@ -99,14 +100,12 @@ public abstract class AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submitRunnableWithGetAfterShutdown() throws Exception {
|
public void submitRunnableWithGetAfterShutdown() throws Exception {
|
||||||
TestTask task1 = new TestTask(-1);
|
Future<?> future1 = executor.submit(new TestTask(-1));
|
||||||
Future<?> future1 = executor.submit(task1);
|
Future<?> future2 = executor.submit(new TestTask(-1));
|
||||||
TestTask task2 = new TestTask(-1);
|
|
||||||
Future<?> future2 = executor.submit(task2);
|
|
||||||
shutdownExecutor();
|
shutdownExecutor();
|
||||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
||||||
future1.get();
|
future1.get(1000, TimeUnit.MILLISECONDS);
|
||||||
future2.get();
|
future2.get(1000, TimeUnit.MILLISECONDS);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,15 +140,23 @@ public abstract class AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submitListenableRunnableWithGetAfterShutdown() throws Exception {
|
public void submitListenableRunnableWithGetAfterShutdown() throws Exception {
|
||||||
TestTask task1 = new TestTask(-1);
|
ListenableFuture<?> future1 = executor.submitListenable(new TestTask(-1));
|
||||||
ListenableFuture<?> future1 = executor.submitListenable(task1);
|
ListenableFuture<?> future2 = executor.submitListenable(new TestTask(-1));
|
||||||
TestTask task2 = new TestTask(-1);
|
|
||||||
ListenableFuture<?> future2 = executor.submitListenable(task2);
|
|
||||||
shutdownExecutor();
|
shutdownExecutor();
|
||||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
|
||||||
future1.get();
|
try {
|
||||||
future2.get();
|
future1.get(1000, TimeUnit.MILLISECONDS);
|
||||||
});
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
Awaitility.await()
|
||||||
|
.atMost(4, TimeUnit.SECONDS)
|
||||||
|
.pollInterval(10, TimeUnit.MILLISECONDS)
|
||||||
|
.untilAsserted(() ->
|
||||||
|
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
|
||||||
|
future2.get(1000, TimeUnit.MILLISECONDS)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -171,10 +178,8 @@ public abstract class AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submitCallableWithGetAfterShutdown() throws Exception {
|
public void submitCallableWithGetAfterShutdown() throws Exception {
|
||||||
TestCallable task1 = new TestCallable(-1);
|
Future<?> future1 = executor.submit(new TestCallable(-1));
|
||||||
Future<?> future1 = executor.submit(task1);
|
Future<?> future2 = executor.submit(new TestCallable(-1));
|
||||||
TestCallable task2 = new TestCallable(-1);
|
|
||||||
Future<?> future2 = executor.submit(task2);
|
|
||||||
shutdownExecutor();
|
shutdownExecutor();
|
||||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
||||||
future1.get(1000, TimeUnit.MILLISECONDS);
|
future1.get(1000, TimeUnit.MILLISECONDS);
|
||||||
|
|
@ -213,14 +218,13 @@ public abstract class AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submitListenableCallableWithGetAfterShutdown() throws Exception {
|
public void submitListenableCallableWithGetAfterShutdown() throws Exception {
|
||||||
TestCallable task1 = new TestCallable(-1);
|
ListenableFuture<?> future1 = executor.submitListenable(new TestCallable(-1));
|
||||||
ListenableFuture<?> future1 = executor.submitListenable(task1);
|
ListenableFuture<?> future2 = executor.submitListenable(new TestCallable(-1));
|
||||||
TestCallable task2 = new TestCallable(-1);
|
|
||||||
ListenableFuture<?> future2 = executor.submitListenable(task2);
|
|
||||||
shutdownExecutor();
|
shutdownExecutor();
|
||||||
future1.get(1000, TimeUnit.MILLISECONDS);
|
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
||||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
|
future1.get(1000, TimeUnit.MILLISECONDS);
|
||||||
future2.get(1000, TimeUnit.MILLISECONDS));
|
future2.get(1000, TimeUnit.MILLISECONDS);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue