Skip to content

Commit bf99361

Browse files
committed
Merge branch '6.0.x'
2 parents 464b676 + 0b7a24f commit bf99361

File tree

4 files changed

+92
-93
lines changed

4 files changed

+92
-93
lines changed

Diff for: spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java

+67-70
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
5858

5959

6060
@BeforeEach
61-
void setUp(TestInfo testInfo) {
61+
void setup(TestInfo testInfo) {
6262
this.testName = testInfo.getTestMethod().get().getName();
6363
this.threadNamePrefix = this.testName + "-";
6464
this.executor = buildExecutor();
@@ -88,11 +88,11 @@ void executeFailingRunnable() {
8888
TestTask task = new TestTask(this.testName, 0);
8989
executor.execute(task);
9090
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>"));
9696
}
9797

9898
@Test
@@ -105,7 +105,7 @@ void submitRunnable() throws Exception {
105105
}
106106

107107
@Test
108-
void submitFailingRunnable() throws Exception {
108+
void submitFailingRunnable() {
109109
TestTask task = new TestTask(this.testName, 0);
110110
Future<?> future = executor.submit(task);
111111
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
@@ -126,61 +126,61 @@ void submitRunnableWithGetAfterShutdown() throws Exception {
126126

127127
@Test
128128
@SuppressWarnings("deprecation")
129-
void submitListenableRunnable() throws Exception {
129+
void submitListenableRunnable() {
130130
TestTask task = new TestTask(this.testName, 1);
131131
// Act
132132
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
133133
future.addCallback(result -> outcome = result, ex -> outcome = ex);
134134
// Assert
135135
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);
139139
assertThat(outcome).isNull();
140140
assertThreadNamePrefix(task);
141141
}
142142

143143
@Test
144-
void submitCompletableRunnable() throws Exception {
144+
void submitCompletableRunnable() {
145145
TestTask task = new TestTask(this.testName, 1);
146146
// Act
147147
CompletableFuture<Void> future = executor.submitCompletable(task);
148148
future.whenComplete(this::storeOutcome);
149149
// Assert
150150
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);
154154
assertThat(outcome).isNull();
155155
assertThreadNamePrefix(task);
156156
}
157157

158158
@Test
159159
@SuppressWarnings("deprecation")
160-
void submitFailingListenableRunnable() throws Exception {
160+
void submitFailingListenableRunnable() {
161161
TestTask task = new TestTask(this.testName, 0);
162162
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
163163
future.addCallback(result -> outcome = result, ex -> outcome = ex);
164164

165165
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);
170170
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
171171
}
172172

173173
@Test
174-
void submitFailingCompletableRunnable() throws Exception {
174+
void submitFailingCompletableRunnable() {
175175
TestTask task = new TestTask(this.testName, 0);
176176
CompletableFuture<?> future = executor.submitCompletable(task);
177177
future.whenComplete(this::storeOutcome);
178178

179179
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);
184184
assertThat(outcome.getClass()).isSameAs(CompletionException.class);
185185
}
186186

@@ -195,14 +195,13 @@ void submitListenableRunnableWithGetAfterShutdown() throws Exception {
195195
future1.get(1000, TimeUnit.MILLISECONDS);
196196
}
197197
catch (Exception ex) {
198-
/* ignore */
198+
// ignore
199199
}
200200
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)));
206205
}
207206

208207
@Test
@@ -215,14 +214,13 @@ void submitCompletableRunnableWithGetAfterShutdown() throws Exception {
215214
future1.get(1000, TimeUnit.MILLISECONDS);
216215
}
217216
catch (Exception ex) {
218-
/* ignore */
217+
// ignore
219218
}
220219
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)));
226224
}
227225

228226
@Test
@@ -234,11 +232,11 @@ void submitCallable() throws Exception {
234232
}
235233

236234
@Test
237-
void submitFailingCallable() throws Exception {
235+
void submitFailingCallable() {
238236
TestCallable task = new TestCallable(this.testName, 0);
239237
Future<String> future = executor.submit(task);
240238
assertThatExceptionOfType(ExecutionException.class)
241-
.isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
239+
.isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
242240
assertThat(future.isDone()).isTrue();
243241
}
244242

@@ -252,44 +250,43 @@ void submitCallableWithGetAfterShutdown() throws Exception {
252250
future1.get(1000, TimeUnit.MILLISECONDS);
253251
}
254252
catch (Exception ex) {
255-
/* ignore */
253+
// ignore
256254
}
257255
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)));
263260
}
264261

265262
@Test
266263
@SuppressWarnings("deprecation")
267-
void submitListenableCallable() throws Exception {
264+
void submitListenableCallable() {
268265
TestCallable task = new TestCallable(this.testName, 1);
269266
// Act
270267
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
271268
future.addCallback(result -> outcome = result, ex -> outcome = ex);
272269
// Assert
273270
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);
277274
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
278275
}
279276

280277
@Test
281278
@SuppressWarnings("deprecation")
282-
void submitFailingListenableCallable() throws Exception {
279+
void submitFailingListenableCallable() {
283280
TestCallable task = new TestCallable(this.testName, 0);
284281
// Act
285282
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
286283
future.addCallback(result -> outcome = result, ex -> outcome = ex);
287284
// Assert
288285
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);
293290
assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
294291
}
295292

@@ -306,31 +303,31 @@ void submitListenableCallableWithGetAfterShutdown() throws Exception {
306303
}
307304

308305
@Test
309-
void submitCompletableCallable() throws Exception {
306+
void submitCompletableCallable() {
310307
TestCallable task = new TestCallable(this.testName, 1);
311308
// Act
312309
CompletableFuture<String> future = this.executor.submitCompletable(task);
313310
future.whenComplete(this::storeOutcome);
314311
// Assert
315312
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);
319316
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
320317
}
321318

322319
@Test
323-
void submitFailingCompletableCallable() throws Exception {
320+
void submitFailingCompletableCallable() {
324321
TestCallable task = new TestCallable(this.testName, 0);
325322
// Act
326323
CompletableFuture<String> future = this.executor.submitCompletable(task);
327324
future.whenComplete(this::storeOutcome);
328325
// Assert
329326
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);
334331
assertThat(outcome.getClass()).isSameAs(CompletionException.class);
335332
}
336333

@@ -355,8 +352,6 @@ else if (t != null) {
355352
}
356353
}
357354

358-
359-
360355
protected void assertThreadNamePrefix(TestTask task) {
361356
assertThat(task.lastThread.getName().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
362357
}
@@ -406,8 +401,9 @@ public void run() {
406401
}
407402
if (expectedRunCount >= 0) {
408403
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()));
411407
this.exception.set(exception);
412408
throw exception;
413409
}
@@ -439,8 +435,9 @@ public String call() throws Exception {
439435
}
440436
if (expectedRunCount >= 0) {
441437
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()));
444441
}
445442
}
446443
return Thread.currentThread().getName();

Diff for: spring-context/src/test/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutorTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,24 @@ void lateSetConcurrentExecutorCallRespectsConfiguredTaskDecorator() {
9292

9393

9494
private static class DecoratedRunnable implements Runnable {
95+
9596
@Override
9697
public void run() {
9798
}
9899
}
99100

101+
100102
private static class RunnableDecorator implements TaskDecorator {
103+
101104
@Override
102105
public Runnable decorate(Runnable runnable) {
103106
return new DecoratedRunnable();
104107
}
105108
}
106109

110+
107111
private static class DecoratedExecutor implements Executor {
112+
108113
@Override
109114
public void execute(Runnable command) {
110115
Assert.state(command instanceof DecoratedRunnable, "TaskDecorator not applied");

0 commit comments

Comments
 (0)