38
38
39
39
/**
40
40
* @author Juergen Hoeller
41
+ * @author Sam Brannen
41
42
* @since 5.0.5
42
43
*/
43
44
public abstract class AbstractSchedulingTaskExecutorTests {
@@ -99,14 +100,12 @@ public void submitFailingRunnable() throws Exception {
99
100
100
101
@ Test
101
102
public void submitRunnableWithGetAfterShutdown () throws Exception {
102
- TestTask task1 = new TestTask (-1 );
103
- Future <?> future1 = executor .submit (task1 );
104
- TestTask task2 = new TestTask (-1 );
105
- Future <?> future2 = executor .submit (task2 );
103
+ Future <?> future1 = executor .submit (new TestTask (-1 ));
104
+ Future <?> future2 = executor .submit (new TestTask (-1 ));
106
105
shutdownExecutor ();
107
106
assertThatExceptionOfType (CancellationException .class ).isThrownBy (() -> {
108
- future1 .get ();
109
- future2 .get ();
107
+ future1 .get (1000 , TimeUnit . MILLISECONDS );
108
+ future2 .get (1000 , TimeUnit . MILLISECONDS );
110
109
});
111
110
}
112
111
@@ -141,15 +140,23 @@ public void submitFailingListenableRunnable() throws Exception {
141
140
142
141
@ Test
143
142
public void submitListenableRunnableWithGetAfterShutdown () throws Exception {
144
- TestTask task1 = new TestTask (-1 );
145
- ListenableFuture <?> future1 = executor .submitListenable (task1 );
146
- TestTask task2 = new TestTask (-1 );
147
- ListenableFuture <?> future2 = executor .submitListenable (task2 );
143
+ ListenableFuture <?> future1 = executor .submitListenable (new TestTask (-1 ));
144
+ ListenableFuture <?> future2 = executor .submitListenable (new TestTask (-1 ));
148
145
shutdownExecutor ();
149
- assertThatExceptionOfType (CancellationException .class ).isThrownBy (() -> {
150
- future1 .get ();
151
- future2 .get ();
152
- });
146
+
147
+ try {
148
+ future1 .get (1000 , TimeUnit .MILLISECONDS );
149
+ }
150
+ catch (Exception ex ) {
151
+ /* ignore */
152
+ }
153
+ Awaitility .await ()
154
+ .atMost (4 , TimeUnit .SECONDS )
155
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
156
+ .untilAsserted (() ->
157
+ assertThatExceptionOfType (CancellationException .class ).isThrownBy (() ->
158
+ future2 .get (1000 , TimeUnit .MILLISECONDS )
159
+ ));
153
160
}
154
161
155
162
@ Test
@@ -171,10 +178,8 @@ public void submitFailingCallable() throws Exception {
171
178
172
179
@ Test
173
180
public void submitCallableWithGetAfterShutdown () throws Exception {
174
- TestCallable task1 = new TestCallable (-1 );
175
- Future <?> future1 = executor .submit (task1 );
176
- TestCallable task2 = new TestCallable (-1 );
177
- Future <?> future2 = executor .submit (task2 );
181
+ Future <?> future1 = executor .submit (new TestCallable (-1 ));
182
+ Future <?> future2 = executor .submit (new TestCallable (-1 ));
178
183
shutdownExecutor ();
179
184
assertThatExceptionOfType (CancellationException .class ).isThrownBy (() -> {
180
185
future1 .get (1000 , TimeUnit .MILLISECONDS );
@@ -213,14 +218,13 @@ public void submitFailingListenableCallable() throws Exception {
213
218
214
219
@ Test
215
220
public void submitListenableCallableWithGetAfterShutdown () throws Exception {
216
- TestCallable task1 = new TestCallable (-1 );
217
- ListenableFuture <?> future1 = executor .submitListenable (task1 );
218
- TestCallable task2 = new TestCallable (-1 );
219
- ListenableFuture <?> future2 = executor .submitListenable (task2 );
221
+ ListenableFuture <?> future1 = executor .submitListenable (new TestCallable (-1 ));
222
+ ListenableFuture <?> future2 = executor .submitListenable (new TestCallable (-1 ));
220
223
shutdownExecutor ();
221
- future1 .get (1000 , TimeUnit .MILLISECONDS );
222
- assertThatExceptionOfType (CancellationException .class ).isThrownBy (() ->
223
- future2 .get (1000 , TimeUnit .MILLISECONDS ));
224
+ assertThatExceptionOfType (CancellationException .class ).isThrownBy (() -> {
225
+ future1 .get (1000 , TimeUnit .MILLISECONDS );
226
+ future2 .get (1000 , TimeUnit .MILLISECONDS );
227
+ });
224
228
}
225
229
226
230
0 commit comments