1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
58
58
59
59
60
60
@ BeforeEach
61
- void setUp (TestInfo testInfo ) {
61
+ void setup (TestInfo testInfo ) {
62
62
this .testName = testInfo .getTestMethod ().get ().getName ();
63
63
this .threadNamePrefix = this .testName + "-" ;
64
64
this .executor = buildExecutor ();
@@ -88,11 +88,11 @@ void executeFailingRunnable() {
88
88
TestTask task = new TestTask (this .testName , 0 );
89
89
executor .execute (task );
90
90
Awaitility .await ()
91
- .dontCatchUncaughtExceptions ()
92
- .atMost (1 , TimeUnit .SECONDS )
93
- .pollInterval (10 , TimeUnit .MILLISECONDS )
94
- .until (() -> task .exception .get () != null && task .exception .get ().getMessage ().equals (
95
- "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>" ));
91
+ .dontCatchUncaughtExceptions ()
92
+ .atMost (1 , TimeUnit .SECONDS )
93
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
94
+ .until (() -> task .exception .get () != null && task .exception .get ().getMessage ().equals (
95
+ "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>" ));
96
96
}
97
97
98
98
@ Test
@@ -105,7 +105,7 @@ void submitRunnable() throws Exception {
105
105
}
106
106
107
107
@ Test
108
- void submitFailingRunnable () throws Exception {
108
+ void submitFailingRunnable () {
109
109
TestTask task = new TestTask (this .testName , 0 );
110
110
Future <?> future = executor .submit (task );
111
111
assertThatExceptionOfType (ExecutionException .class ).isThrownBy (() ->
@@ -126,61 +126,61 @@ void submitRunnableWithGetAfterShutdown() throws Exception {
126
126
127
127
@ Test
128
128
@ SuppressWarnings ("deprecation" )
129
- void submitListenableRunnable () throws Exception {
129
+ void submitListenableRunnable () {
130
130
TestTask task = new TestTask (this .testName , 1 );
131
131
// Act
132
132
org .springframework .util .concurrent .ListenableFuture <?> future = executor .submitListenable (task );
133
133
future .addCallback (result -> outcome = result , ex -> outcome = ex );
134
134
// Assert
135
135
Awaitility .await ()
136
- .atMost (1 , TimeUnit .SECONDS )
137
- .pollInterval (10 , TimeUnit .MILLISECONDS )
138
- .until (future ::isDone );
136
+ .atMost (1 , TimeUnit .SECONDS )
137
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
138
+ .until (future ::isDone );
139
139
assertThat (outcome ).isNull ();
140
140
assertThreadNamePrefix (task );
141
141
}
142
142
143
143
@ Test
144
- void submitCompletableRunnable () throws Exception {
144
+ void submitCompletableRunnable () {
145
145
TestTask task = new TestTask (this .testName , 1 );
146
146
// Act
147
147
CompletableFuture <Void > future = executor .submitCompletable (task );
148
148
future .whenComplete (this ::storeOutcome );
149
149
// Assert
150
150
Awaitility .await ()
151
- .atMost (1 , TimeUnit .SECONDS )
152
- .pollInterval (10 , TimeUnit .MILLISECONDS )
153
- .until (future ::isDone );
151
+ .atMost (1 , TimeUnit .SECONDS )
152
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
153
+ .until (future ::isDone );
154
154
assertThat (outcome ).isNull ();
155
155
assertThreadNamePrefix (task );
156
156
}
157
157
158
158
@ Test
159
159
@ SuppressWarnings ("deprecation" )
160
- void submitFailingListenableRunnable () throws Exception {
160
+ void submitFailingListenableRunnable () {
161
161
TestTask task = new TestTask (this .testName , 0 );
162
162
org .springframework .util .concurrent .ListenableFuture <?> future = executor .submitListenable (task );
163
163
future .addCallback (result -> outcome = result , ex -> outcome = ex );
164
164
165
165
Awaitility .await ()
166
- .dontCatchUncaughtExceptions ()
167
- .atMost (1 , TimeUnit .SECONDS )
168
- .pollInterval (10 , TimeUnit .MILLISECONDS )
169
- .until (() -> future .isDone () && outcome != null );
166
+ .dontCatchUncaughtExceptions ()
167
+ .atMost (1 , TimeUnit .SECONDS )
168
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
169
+ .until (() -> future .isDone () && outcome != null );
170
170
assertThat (outcome .getClass ()).isSameAs (RuntimeException .class );
171
171
}
172
172
173
173
@ Test
174
- void submitFailingCompletableRunnable () throws Exception {
174
+ void submitFailingCompletableRunnable () {
175
175
TestTask task = new TestTask (this .testName , 0 );
176
176
CompletableFuture <?> future = executor .submitCompletable (task );
177
177
future .whenComplete (this ::storeOutcome );
178
178
179
179
Awaitility .await ()
180
- .dontCatchUncaughtExceptions ()
181
- .atMost (1 , TimeUnit .SECONDS )
182
- .pollInterval (10 , TimeUnit .MILLISECONDS )
183
- .until (() -> future .isDone () && outcome != null );
180
+ .dontCatchUncaughtExceptions ()
181
+ .atMost (1 , TimeUnit .SECONDS )
182
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
183
+ .until (() -> future .isDone () && outcome != null );
184
184
assertThat (outcome .getClass ()).isSameAs (CompletionException .class );
185
185
}
186
186
@@ -195,14 +195,13 @@ void submitListenableRunnableWithGetAfterShutdown() throws Exception {
195
195
future1 .get (1000 , TimeUnit .MILLISECONDS );
196
196
}
197
197
catch (Exception ex ) {
198
- /* ignore */
198
+ // ignore
199
199
}
200
200
Awaitility .await ()
201
- .atMost (4 , TimeUnit .SECONDS )
202
- .pollInterval (10 , TimeUnit .MILLISECONDS )
203
- .untilAsserted (() ->
204
- assertThatExceptionOfType (CancellationException .class ).isThrownBy (() ->
205
- future2 .get (1000 , TimeUnit .MILLISECONDS )));
201
+ .atMost (4 , TimeUnit .SECONDS )
202
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
203
+ .untilAsserted (() -> assertThatExceptionOfType (CancellationException .class )
204
+ .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
206
205
}
207
206
208
207
@ Test
@@ -215,14 +214,13 @@ void submitCompletableRunnableWithGetAfterShutdown() throws Exception {
215
214
future1 .get (1000 , TimeUnit .MILLISECONDS );
216
215
}
217
216
catch (Exception ex ) {
218
- /* ignore */
217
+ // ignore
219
218
}
220
219
Awaitility .await ()
221
- .atMost (4 , TimeUnit .SECONDS )
222
- .pollInterval (10 , TimeUnit .MILLISECONDS )
223
- .untilAsserted (() ->
224
- assertThatExceptionOfType (TimeoutException .class )
225
- .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
220
+ .atMost (4 , TimeUnit .SECONDS )
221
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
222
+ .untilAsserted (() -> assertThatExceptionOfType (TimeoutException .class )
223
+ .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
226
224
}
227
225
228
226
@ Test
@@ -234,11 +232,11 @@ void submitCallable() throws Exception {
234
232
}
235
233
236
234
@ Test
237
- void submitFailingCallable () throws Exception {
235
+ void submitFailingCallable () {
238
236
TestCallable task = new TestCallable (this .testName , 0 );
239
237
Future <String > future = executor .submit (task );
240
238
assertThatExceptionOfType (ExecutionException .class )
241
- .isThrownBy (() -> future .get (1000 , TimeUnit .MILLISECONDS ));
239
+ .isThrownBy (() -> future .get (1000 , TimeUnit .MILLISECONDS ));
242
240
assertThat (future .isDone ()).isTrue ();
243
241
}
244
242
@@ -252,44 +250,43 @@ void submitCallableWithGetAfterShutdown() throws Exception {
252
250
future1 .get (1000 , TimeUnit .MILLISECONDS );
253
251
}
254
252
catch (Exception ex ) {
255
- /* ignore */
253
+ // ignore
256
254
}
257
255
Awaitility .await ()
258
- .atMost (4 , TimeUnit .SECONDS )
259
- .pollInterval (10 , TimeUnit .MILLISECONDS )
260
- .untilAsserted (() ->
261
- assertThatExceptionOfType (CancellationException .class )
262
- .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
256
+ .atMost (4 , TimeUnit .SECONDS )
257
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
258
+ .untilAsserted (() -> assertThatExceptionOfType (CancellationException .class )
259
+ .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
263
260
}
264
261
265
262
@ Test
266
263
@ SuppressWarnings ("deprecation" )
267
- void submitListenableCallable () throws Exception {
264
+ void submitListenableCallable () {
268
265
TestCallable task = new TestCallable (this .testName , 1 );
269
266
// Act
270
267
org .springframework .util .concurrent .ListenableFuture <String > future = executor .submitListenable (task );
271
268
future .addCallback (result -> outcome = result , ex -> outcome = ex );
272
269
// Assert
273
270
Awaitility .await ()
274
- .atMost (1 , TimeUnit .SECONDS )
275
- .pollInterval (10 , TimeUnit .MILLISECONDS )
276
- .until (() -> future .isDone () && outcome != null );
271
+ .atMost (1 , TimeUnit .SECONDS )
272
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
273
+ .until (() -> future .isDone () && outcome != null );
277
274
assertThat (outcome .toString ().substring (0 , this .threadNamePrefix .length ())).isEqualTo (this .threadNamePrefix );
278
275
}
279
276
280
277
@ Test
281
278
@ SuppressWarnings ("deprecation" )
282
- void submitFailingListenableCallable () throws Exception {
279
+ void submitFailingListenableCallable () {
283
280
TestCallable task = new TestCallable (this .testName , 0 );
284
281
// Act
285
282
org .springframework .util .concurrent .ListenableFuture <String > future = executor .submitListenable (task );
286
283
future .addCallback (result -> outcome = result , ex -> outcome = ex );
287
284
// Assert
288
285
Awaitility .await ()
289
- .dontCatchUncaughtExceptions ()
290
- .atMost (1 , TimeUnit .SECONDS )
291
- .pollInterval (10 , TimeUnit .MILLISECONDS )
292
- .until (() -> future .isDone () && outcome != null );
286
+ .dontCatchUncaughtExceptions ()
287
+ .atMost (1 , TimeUnit .SECONDS )
288
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
289
+ .until (() -> future .isDone () && outcome != null );
293
290
assertThat (outcome .getClass ()).isSameAs (RuntimeException .class );
294
291
}
295
292
@@ -306,31 +303,31 @@ void submitListenableCallableWithGetAfterShutdown() throws Exception {
306
303
}
307
304
308
305
@ Test
309
- void submitCompletableCallable () throws Exception {
306
+ void submitCompletableCallable () {
310
307
TestCallable task = new TestCallable (this .testName , 1 );
311
308
// Act
312
309
CompletableFuture <String > future = this .executor .submitCompletable (task );
313
310
future .whenComplete (this ::storeOutcome );
314
311
// Assert
315
312
Awaitility .await ()
316
- .atMost (1 , TimeUnit .SECONDS )
317
- .pollInterval (10 , TimeUnit .MILLISECONDS )
318
- .until (() -> future .isDone () && outcome != null );
313
+ .atMost (1 , TimeUnit .SECONDS )
314
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
315
+ .until (() -> future .isDone () && outcome != null );
319
316
assertThat (outcome .toString ().substring (0 , this .threadNamePrefix .length ())).isEqualTo (this .threadNamePrefix );
320
317
}
321
318
322
319
@ Test
323
- void submitFailingCompletableCallable () throws Exception {
320
+ void submitFailingCompletableCallable () {
324
321
TestCallable task = new TestCallable (this .testName , 0 );
325
322
// Act
326
323
CompletableFuture <String > future = this .executor .submitCompletable (task );
327
324
future .whenComplete (this ::storeOutcome );
328
325
// Assert
329
326
Awaitility .await ()
330
- .dontCatchUncaughtExceptions ()
331
- .atMost (1 , TimeUnit .SECONDS )
332
- .pollInterval (10 , TimeUnit .MILLISECONDS )
333
- .until (() -> future .isDone () && outcome != null );
327
+ .dontCatchUncaughtExceptions ()
328
+ .atMost (1 , TimeUnit .SECONDS )
329
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
330
+ .until (() -> future .isDone () && outcome != null );
334
331
assertThat (outcome .getClass ()).isSameAs (CompletionException .class );
335
332
}
336
333
@@ -355,8 +352,6 @@ else if (t != null) {
355
352
}
356
353
}
357
354
358
-
359
-
360
355
protected void assertThreadNamePrefix (TestTask task ) {
361
356
assertThat (task .lastThread .getName ().substring (0 , this .threadNamePrefix .length ())).isEqualTo (this .threadNamePrefix );
362
357
}
@@ -406,8 +401,9 @@ public void run() {
406
401
}
407
402
if (expectedRunCount >= 0 ) {
408
403
if (actualRunCount .incrementAndGet () > expectedRunCount ) {
409
- RuntimeException exception = new RuntimeException (String .format ("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
410
- getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
404
+ RuntimeException exception = new RuntimeException (String .format (
405
+ "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
406
+ getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
411
407
this .exception .set (exception );
412
408
throw exception ;
413
409
}
@@ -439,8 +435,9 @@ public String call() throws Exception {
439
435
}
440
436
if (expectedRunCount >= 0 ) {
441
437
if (actualRunCount .incrementAndGet () > expectedRunCount ) {
442
- throw new RuntimeException (String .format ("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
443
- getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
438
+ throw new RuntimeException (String .format (
439
+ "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
440
+ getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
444
441
}
445
442
}
446
443
return Thread .currentThread ().getName ();
0 commit comments