1
1
/*
2
- * Copyright 2002-2020 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.
@@ -55,7 +55,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
55
55
56
56
57
57
@ BeforeEach
58
- void setUp (TestInfo testInfo ) {
58
+ void setup (TestInfo testInfo ) {
59
59
this .testName = testInfo .getTestMethod ().get ().getName ();
60
60
this .threadNamePrefix = this .testName + "-" ;
61
61
this .executor = buildExecutor ();
@@ -84,11 +84,11 @@ void executeFailingRunnable() {
84
84
TestTask task = new TestTask (this .testName , 0 );
85
85
executor .execute (task );
86
86
Awaitility .await ()
87
- .dontCatchUncaughtExceptions ()
88
- .atMost (1 , TimeUnit .SECONDS )
89
- .pollInterval (10 , TimeUnit .MILLISECONDS )
90
- .until (() -> task .exception .get () != null && task .exception .get ().getMessage ().equals (
91
- "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>" ));
87
+ .dontCatchUncaughtExceptions ()
88
+ .atMost (1 , TimeUnit .SECONDS )
89
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
90
+ .until (() -> task .exception .get () != null && task .exception .get ().getMessage ().equals (
91
+ "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>" ));
92
92
}
93
93
94
94
@ Test
@@ -101,7 +101,7 @@ void submitRunnable() throws Exception {
101
101
}
102
102
103
103
@ Test
104
- void submitFailingRunnable () throws Exception {
104
+ void submitFailingRunnable () {
105
105
TestTask task = new TestTask (this .testName , 0 );
106
106
Future <?> future = executor .submit (task );
107
107
assertThatExceptionOfType (ExecutionException .class ).isThrownBy (() ->
@@ -121,31 +121,31 @@ void submitRunnableWithGetAfterShutdown() throws Exception {
121
121
}
122
122
123
123
@ Test
124
- void submitListenableRunnable () throws Exception {
124
+ void submitListenableRunnable () {
125
125
TestTask task = new TestTask (this .testName , 1 );
126
126
// Act
127
127
ListenableFuture <?> future = executor .submitListenable (task );
128
128
future .addCallback (result -> outcome = result , ex -> outcome = ex );
129
129
// Assert
130
130
Awaitility .await ()
131
- .atMost (1 , TimeUnit .SECONDS )
132
- .pollInterval (10 , TimeUnit .MILLISECONDS )
133
- .until (future ::isDone );
131
+ .atMost (1 , TimeUnit .SECONDS )
132
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
133
+ .until (future ::isDone );
134
134
assertThat (outcome ).isNull ();
135
135
assertThreadNamePrefix (task );
136
136
}
137
137
138
138
@ Test
139
- void submitFailingListenableRunnable () throws Exception {
139
+ void submitFailingListenableRunnable () {
140
140
TestTask task = new TestTask (this .testName , 0 );
141
141
ListenableFuture <?> future = executor .submitListenable (task );
142
142
future .addCallback (result -> outcome = result , ex -> outcome = ex );
143
143
144
144
Awaitility .await ()
145
- .dontCatchUncaughtExceptions ()
146
- .atMost (1 , TimeUnit .SECONDS )
147
- .pollInterval (10 , TimeUnit .MILLISECONDS )
148
- .until (() -> future .isDone () && outcome != null );
145
+ .dontCatchUncaughtExceptions ()
146
+ .atMost (1 , TimeUnit .SECONDS )
147
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
148
+ .until (() -> future .isDone () && outcome != null );
149
149
assertThat (outcome .getClass ()).isSameAs (RuntimeException .class );
150
150
}
151
151
@@ -159,14 +159,13 @@ void submitListenableRunnableWithGetAfterShutdown() throws Exception {
159
159
future1 .get (1000 , TimeUnit .MILLISECONDS );
160
160
}
161
161
catch (Exception ex ) {
162
- /* ignore */
162
+ // ignore
163
163
}
164
164
Awaitility .await ()
165
- .atMost (4 , TimeUnit .SECONDS )
166
- .pollInterval (10 , TimeUnit .MILLISECONDS )
167
- .untilAsserted (() ->
168
- assertThatExceptionOfType (CancellationException .class ).isThrownBy (() ->
169
- future2 .get (1000 , TimeUnit .MILLISECONDS )));
165
+ .atMost (4 , TimeUnit .SECONDS )
166
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
167
+ .untilAsserted (() -> assertThatExceptionOfType (CancellationException .class )
168
+ .isThrownBy (() -> future2 .get (1000 , TimeUnit .MILLISECONDS )));
170
169
}
171
170
172
171
@ Test
@@ -178,11 +177,11 @@ void submitCallable() throws Exception {
178
177
}
179
178
180
179
@ Test
181
- void submitFailingCallable () throws Exception {
180
+ void submitFailingCallable () {
182
181
TestCallable task = new TestCallable (this .testName , 0 );
183
182
Future <String > future = executor .submit (task );
184
- assertThatExceptionOfType (ExecutionException .class ). isThrownBy (() ->
185
- future .get (1000 , TimeUnit .MILLISECONDS ));
183
+ assertThatExceptionOfType (ExecutionException .class )
184
+ . isThrownBy (() -> future .get (1000 , TimeUnit .MILLISECONDS ));
186
185
assertThat (future .isDone ()).isTrue ();
187
186
}
188
187
@@ -196,42 +195,41 @@ void submitCallableWithGetAfterShutdown() throws Exception {
196
195
future1 .get (1000 , TimeUnit .MILLISECONDS );
197
196
}
198
197
catch (Exception ex ) {
199
- /* ignore */
198
+ // ignore
200
199
}
201
200
Awaitility .await ()
202
- .atMost (4 , TimeUnit .SECONDS )
203
- .pollInterval (10 , TimeUnit .MILLISECONDS )
204
- .untilAsserted (() ->
205
- assertThatExceptionOfType (CancellationException .class ).isThrownBy (() ->
206
- 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 )));
207
205
}
208
206
209
207
@ Test
210
- void submitListenableCallable () throws Exception {
208
+ void submitListenableCallable () {
211
209
TestCallable task = new TestCallable (this .testName , 1 );
212
210
// Act
213
211
ListenableFuture <String > future = executor .submitListenable (task );
214
212
future .addCallback (result -> outcome = result , ex -> outcome = ex );
215
213
// Assert
216
214
Awaitility .await ()
217
- .atMost (1 , TimeUnit .SECONDS )
218
- .pollInterval (10 , TimeUnit .MILLISECONDS )
219
- .until (() -> future .isDone () && outcome != null );
215
+ .atMost (1 , TimeUnit .SECONDS )
216
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
217
+ .until (() -> future .isDone () && outcome != null );
220
218
assertThat (outcome .toString ().substring (0 , this .threadNamePrefix .length ())).isEqualTo (this .threadNamePrefix );
221
219
}
222
220
223
221
@ Test
224
- void submitFailingListenableCallable () throws Exception {
222
+ void submitFailingListenableCallable () {
225
223
TestCallable task = new TestCallable (this .testName , 0 );
226
224
// Act
227
225
ListenableFuture <String > future = executor .submitListenable (task );
228
226
future .addCallback (result -> outcome = result , ex -> outcome = ex );
229
227
// Assert
230
228
Awaitility .await ()
231
- .dontCatchUncaughtExceptions ()
232
- .atMost (1 , TimeUnit .SECONDS )
233
- .pollInterval (10 , TimeUnit .MILLISECONDS )
234
- .until (() -> future .isDone () && outcome != null );
229
+ .dontCatchUncaughtExceptions ()
230
+ .atMost (1 , TimeUnit .SECONDS )
231
+ .pollInterval (10 , TimeUnit .MILLISECONDS )
232
+ .until (() -> future .isDone () && outcome != null );
235
233
assertThat (outcome .getClass ()).isSameAs (RuntimeException .class );
236
234
}
237
235
@@ -296,8 +294,9 @@ public void run() {
296
294
}
297
295
if (expectedRunCount >= 0 ) {
298
296
if (actualRunCount .incrementAndGet () > expectedRunCount ) {
299
- RuntimeException exception = new RuntimeException (String .format ("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
300
- getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
297
+ RuntimeException exception = new RuntimeException (String .format (
298
+ "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
299
+ getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
301
300
this .exception .set (exception );
302
301
throw exception ;
303
302
}
@@ -329,8 +328,9 @@ public String call() throws Exception {
329
328
}
330
329
if (expectedRunCount >= 0 ) {
331
330
if (actualRunCount .incrementAndGet () > expectedRunCount ) {
332
- throw new RuntimeException (String .format ("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
333
- getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
331
+ throw new RuntimeException (String .format (
332
+ "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>" ,
333
+ getClass ().getSimpleName (), this .testName , expectedRunCount , actualRunCount .get ()));
334
334
}
335
335
}
336
336
return Thread .currentThread ().getName ();
0 commit comments