Polishing

This commit is contained in:
Juergen Hoeller 2023-07-08 00:58:20 +02:00
parent 75b540f25c
commit 0b7a24fc14
4 changed files with 92 additions and 93 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
@BeforeEach @BeforeEach
void setUp(TestInfo testInfo) { void setup(TestInfo testInfo) {
this.testName = testInfo.getTestMethod().get().getName(); this.testName = testInfo.getTestMethod().get().getName();
this.threadNamePrefix = this.testName + "-"; this.threadNamePrefix = this.testName + "-";
this.executor = buildExecutor(); this.executor = buildExecutor();
@ -88,11 +88,11 @@ abstract class AbstractSchedulingTaskExecutorTests {
TestTask task = new TestTask(this.testName, 0); TestTask task = new TestTask(this.testName, 0);
executor.execute(task); executor.execute(task);
Awaitility.await() Awaitility.await()
.dontCatchUncaughtExceptions() .dontCatchUncaughtExceptions()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> task.exception.get() != null && task.exception.get().getMessage().equals( .until(() -> task.exception.get() != null && task.exception.get().getMessage().equals(
"TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>")); "TestTask failure for test 'executeFailingRunnable': expectedRunCount:<0>, actualRunCount:<1>"));
} }
@Test @Test
@ -105,7 +105,7 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
@Test @Test
void submitFailingRunnable() throws Exception { void submitFailingRunnable() {
TestTask task = new TestTask(this.testName, 0); TestTask task = new TestTask(this.testName, 0);
Future<?> future = executor.submit(task); Future<?> future = executor.submit(task);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
@ -126,61 +126,61 @@ abstract class AbstractSchedulingTaskExecutorTests {
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void submitListenableRunnable() throws Exception { void submitListenableRunnable() {
TestTask task = new TestTask(this.testName, 1); TestTask task = new TestTask(this.testName, 1);
// Act // Act
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task); org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
future.addCallback(result -> outcome = result, ex -> outcome = ex); future.addCallback(result -> outcome = result, ex -> outcome = ex);
// Assert // Assert
Awaitility.await() Awaitility.await()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(future::isDone); .until(future::isDone);
assertThat(outcome).isNull(); assertThat(outcome).isNull();
assertThreadNamePrefix(task); assertThreadNamePrefix(task);
} }
@Test @Test
void submitCompletableRunnable() throws Exception { void submitCompletableRunnable() {
TestTask task = new TestTask(this.testName, 1); TestTask task = new TestTask(this.testName, 1);
// Act // Act
CompletableFuture<Void> future = executor.submitCompletable(task); CompletableFuture<Void> future = executor.submitCompletable(task);
future.whenComplete(this::storeOutcome); future.whenComplete(this::storeOutcome);
// Assert // Assert
Awaitility.await() Awaitility.await()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(future::isDone); .until(future::isDone);
assertThat(outcome).isNull(); assertThat(outcome).isNull();
assertThreadNamePrefix(task); assertThreadNamePrefix(task);
} }
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void submitFailingListenableRunnable() throws Exception { void submitFailingListenableRunnable() {
TestTask task = new TestTask(this.testName, 0); TestTask task = new TestTask(this.testName, 0);
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task); org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
future.addCallback(result -> outcome = result, ex -> outcome = ex); future.addCallback(result -> outcome = result, ex -> outcome = ex);
Awaitility.await() Awaitility.await()
.dontCatchUncaughtExceptions() .dontCatchUncaughtExceptions()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.getClass()).isSameAs(RuntimeException.class); assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
} }
@Test @Test
void submitFailingCompletableRunnable() throws Exception { void submitFailingCompletableRunnable() {
TestTask task = new TestTask(this.testName, 0); TestTask task = new TestTask(this.testName, 0);
CompletableFuture<?> future = executor.submitCompletable(task); CompletableFuture<?> future = executor.submitCompletable(task);
future.whenComplete(this::storeOutcome); future.whenComplete(this::storeOutcome);
Awaitility.await() Awaitility.await()
.dontCatchUncaughtExceptions() .dontCatchUncaughtExceptions()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.getClass()).isSameAs(CompletionException.class); assertThat(outcome.getClass()).isSameAs(CompletionException.class);
} }
@ -195,14 +195,13 @@ abstract class AbstractSchedulingTaskExecutorTests {
future1.get(1000, TimeUnit.MILLISECONDS); future1.get(1000, TimeUnit.MILLISECONDS);
} }
catch (Exception ex) { catch (Exception ex) {
/* ignore */ // ignore
} }
Awaitility.await() Awaitility.await()
.atMost(4, TimeUnit.SECONDS) .atMost(4, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.untilAsserted(() -> .untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
future2.get(1000, TimeUnit.MILLISECONDS)));
} }
@Test @Test
@ -215,14 +214,13 @@ abstract class AbstractSchedulingTaskExecutorTests {
future1.get(1000, TimeUnit.MILLISECONDS); future1.get(1000, TimeUnit.MILLISECONDS);
} }
catch (Exception ex) { catch (Exception ex) {
/* ignore */ // ignore
} }
Awaitility.await() Awaitility.await()
.atMost(4, TimeUnit.SECONDS) .atMost(4, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.untilAsserted(() -> .untilAsserted(() -> assertThatExceptionOfType(TimeoutException.class)
assertThatExceptionOfType(TimeoutException.class) .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
} }
@Test @Test
@ -234,11 +232,11 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
@Test @Test
void submitFailingCallable() throws Exception { void submitFailingCallable() {
TestCallable task = new TestCallable(this.testName, 0); TestCallable task = new TestCallable(this.testName, 0);
Future<String> future = executor.submit(task); Future<String> future = executor.submit(task);
assertThatExceptionOfType(ExecutionException.class) assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS)); .isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
assertThat(future.isDone()).isTrue(); assertThat(future.isDone()).isTrue();
} }
@ -252,44 +250,43 @@ abstract class AbstractSchedulingTaskExecutorTests {
future1.get(1000, TimeUnit.MILLISECONDS); future1.get(1000, TimeUnit.MILLISECONDS);
} }
catch (Exception ex) { catch (Exception ex) {
/* ignore */ // ignore
} }
Awaitility.await() Awaitility.await()
.atMost(4, TimeUnit.SECONDS) .atMost(4, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.untilAsserted(() -> .untilAsserted(() -> assertThatExceptionOfType(CancellationException.class)
assertThatExceptionOfType(CancellationException.class) .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
} }
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void submitListenableCallable() throws Exception { void submitListenableCallable() {
TestCallable task = new TestCallable(this.testName, 1); TestCallable task = new TestCallable(this.testName, 1);
// Act // Act
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task); org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
future.addCallback(result -> outcome = result, ex -> outcome = ex); future.addCallback(result -> outcome = result, ex -> outcome = ex);
// Assert // Assert
Awaitility.await() Awaitility.await()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
} }
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void submitFailingListenableCallable() throws Exception { void submitFailingListenableCallable() {
TestCallable task = new TestCallable(this.testName, 0); TestCallable task = new TestCallable(this.testName, 0);
// Act // Act
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task); org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
future.addCallback(result -> outcome = result, ex -> outcome = ex); future.addCallback(result -> outcome = result, ex -> outcome = ex);
// Assert // Assert
Awaitility.await() Awaitility.await()
.dontCatchUncaughtExceptions() .dontCatchUncaughtExceptions()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.getClass()).isSameAs(RuntimeException.class); assertThat(outcome.getClass()).isSameAs(RuntimeException.class);
} }
@ -306,31 +303,31 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
@Test @Test
void submitCompletableCallable() throws Exception { void submitCompletableCallable() {
TestCallable task = new TestCallable(this.testName, 1); TestCallable task = new TestCallable(this.testName, 1);
// Act // Act
CompletableFuture<String> future = this.executor.submitCompletable(task); CompletableFuture<String> future = this.executor.submitCompletable(task);
future.whenComplete(this::storeOutcome); future.whenComplete(this::storeOutcome);
// Assert // Assert
Awaitility.await() Awaitility.await()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); assertThat(outcome.toString().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
} }
@Test @Test
void submitFailingCompletableCallable() throws Exception { void submitFailingCompletableCallable() {
TestCallable task = new TestCallable(this.testName, 0); TestCallable task = new TestCallable(this.testName, 0);
// Act // Act
CompletableFuture<String> future = this.executor.submitCompletable(task); CompletableFuture<String> future = this.executor.submitCompletable(task);
future.whenComplete(this::storeOutcome); future.whenComplete(this::storeOutcome);
// Assert // Assert
Awaitility.await() Awaitility.await()
.dontCatchUncaughtExceptions() .dontCatchUncaughtExceptions()
.atMost(1, TimeUnit.SECONDS) .atMost(1, TimeUnit.SECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> future.isDone() && outcome != null); .until(() -> future.isDone() && outcome != null);
assertThat(outcome.getClass()).isSameAs(CompletionException.class); assertThat(outcome.getClass()).isSameAs(CompletionException.class);
} }
@ -355,8 +352,6 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
} }
protected void assertThreadNamePrefix(TestTask task) { protected void assertThreadNamePrefix(TestTask task) {
assertThat(task.lastThread.getName().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix); assertThat(task.lastThread.getName().substring(0, this.threadNamePrefix.length())).isEqualTo(this.threadNamePrefix);
} }
@ -406,8 +401,9 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
if (expectedRunCount >= 0) { if (expectedRunCount >= 0) {
if (actualRunCount.incrementAndGet() > expectedRunCount) { if (actualRunCount.incrementAndGet() > expectedRunCount) {
RuntimeException exception = new RuntimeException(String.format("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>", RuntimeException exception = new RuntimeException(String.format(
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get())); "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
this.exception.set(exception); this.exception.set(exception);
throw exception; throw exception;
} }
@ -439,8 +435,9 @@ abstract class AbstractSchedulingTaskExecutorTests {
} }
if (expectedRunCount >= 0) { if (expectedRunCount >= 0) {
if (actualRunCount.incrementAndGet() > expectedRunCount) { if (actualRunCount.incrementAndGet() > expectedRunCount) {
throw new RuntimeException(String.format("%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>", throw new RuntimeException(String.format(
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get())); "%s failure for test '%s': expectedRunCount:<%d>, actualRunCount:<%d>",
getClass().getSimpleName(), this.testName, expectedRunCount, actualRunCount.get()));
} }
} }
return Thread.currentThread().getName(); return Thread.currentThread().getName();

View File

@ -89,19 +89,24 @@ class ConcurrentTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
private static class DecoratedRunnable implements Runnable { private static class DecoratedRunnable implements Runnable {
@Override @Override
public void run() { public void run() {
} }
} }
private static class RunnableDecorator implements TaskDecorator { private static class RunnableDecorator implements TaskDecorator {
@Override @Override
public Runnable decorate(Runnable runnable) { public Runnable decorate(Runnable runnable) {
return new DecoratedRunnable(); return new DecoratedRunnable();
} }
} }
private static class DecoratedExecutor implements Executor { private static class DecoratedExecutor implements Executor {
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {
Assert.state(command instanceof DecoratedRunnable, "TaskDecorator not applied"); Assert.state(command instanceof DecoratedRunnable, "TaskDecorator not applied");

View File

@ -41,14 +41,14 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
class ScheduledExecutorFactoryBeanTests { class ScheduledExecutorFactoryBeanTests {
@Test @Test
void throwsExceptionIfPoolSizeIsLessThanZero() throws Exception { void throwsExceptionIfPoolSizeIsLessThanZero() {
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean(); ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
assertThatIllegalArgumentException().isThrownBy(() -> factory.setPoolSize(-1)); assertThatIllegalArgumentException().isThrownBy(() -> factory.setPoolSize(-1));
} }
@Test @Test
@SuppressWarnings("serial") @SuppressWarnings("serial")
void shutdownNowIsPropagatedToTheExecutorOnDestroy() throws Exception { void shutdownNowIsPropagatedToTheExecutorOnDestroy() {
final ScheduledExecutorService executor = mock(); final ScheduledExecutorService executor = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() { ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@ -66,7 +66,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@SuppressWarnings("serial") @SuppressWarnings("serial")
void shutdownIsPropagatedToTheExecutorOnDestroy() throws Exception { void shutdownIsPropagatedToTheExecutorOnDestroy() {
final ScheduledExecutorService executor = mock(); final ScheduledExecutorService executor = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() { ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@ -85,7 +85,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@EnabledForTestGroups(LONG_RUNNING) @EnabledForTestGroups(LONG_RUNNING)
void oneTimeExecutionIsSetUpAndFiresCorrectly() throws Exception { void oneTimeExecutionIsSetUpAndFiresCorrectly() {
Runnable runnable = mock(); Runnable runnable = mock();
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean(); ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
@ -99,7 +99,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@EnabledForTestGroups(LONG_RUNNING) @EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception { void fixedRepeatedExecutionIsSetUpAndFiresCorrectly() {
Runnable runnable = mock(); Runnable runnable = mock();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable); ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
@ -117,7 +117,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@EnabledForTestGroups(LONG_RUNNING) @EnabledForTestGroups(LONG_RUNNING)
void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception { void fixedRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() {
Runnable runnable = mock(); Runnable runnable = mock();
willThrow(new IllegalStateException()).given(runnable).run(); willThrow(new IllegalStateException()).given(runnable).run();
@ -137,7 +137,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@EnabledForTestGroups(LONG_RUNNING) @EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception { void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() {
Runnable runnable = mock(); Runnable runnable = mock();
ScheduledExecutorTask task = new ScheduledExecutorTask(runnable); ScheduledExecutorTask task = new ScheduledExecutorTask(runnable);
@ -157,7 +157,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@EnabledForTestGroups(LONG_RUNNING) @EnabledForTestGroups(LONG_RUNNING)
void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception { void withInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() {
Runnable runnable = mock(); Runnable runnable = mock();
willThrow(new IllegalStateException()).given(runnable).run(); willThrow(new IllegalStateException()).given(runnable).run();
@ -179,7 +179,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@SuppressWarnings("serial") @SuppressWarnings("serial")
void settingThreadFactoryToNullForcesUseOfDefaultButIsOtherwiseCool() throws Exception { void settingThreadFactoryToNullForcesUseOfDefaultButIsOtherwiseCool() {
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() { ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override @Override
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@ -197,7 +197,7 @@ class ScheduledExecutorFactoryBeanTests {
@Test @Test
@SuppressWarnings("serial") @SuppressWarnings("serial")
void settingRejectedExecutionHandlerToNullForcesUseOfDefaultButIsOtherwiseCool() throws Exception { void settingRejectedExecutionHandlerToNullForcesUseOfDefaultButIsOtherwiseCool() {
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() { ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override @Override
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@ -211,7 +211,7 @@ class ScheduledExecutorFactoryBeanTests {
} }
@Test @Test
void objectTypeReportsCorrectType() throws Exception { void objectTypeReportsCorrectType() {
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean(); ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean();
assertThat(factory.getObjectType()).isEqualTo(ScheduledExecutorService.class); assertThat(factory.getObjectType()).isEqualTo(ScheduledExecutorService.class);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,8 +24,8 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.type; import static org.assertj.core.api.InstanceOfAssertFactories.type;
/** /**
@ -66,8 +66,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
assertThat(executor.getCorePoolSize()).isEqualTo(1); assertThat(executor.getCorePoolSize()).isEqualTo(1);
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1); assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
assertThatThrownBy(() -> executor.setCorePoolSize(-1)) assertThatIllegalArgumentException().isThrownBy(() -> executor.setCorePoolSize(-1));
.isInstanceOf(IllegalArgumentException.class);
assertThat(executor.getCorePoolSize()).isEqualTo(1); assertThat(executor.getCorePoolSize()).isEqualTo(1);
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1); assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
@ -89,8 +88,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
assertThat(executor.getMaxPoolSize()).isEqualTo(1); assertThat(executor.getMaxPoolSize()).isEqualTo(1);
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1); assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
assertThatThrownBy(() -> executor.setMaxPoolSize(0)) assertThatIllegalArgumentException().isThrownBy(() -> executor.setMaxPoolSize(0));
.isInstanceOf(IllegalArgumentException.class);
assertThat(executor.getMaxPoolSize()).isEqualTo(1); assertThat(executor.getMaxPoolSize()).isEqualTo(1);
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1); assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
@ -112,8 +110,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60); assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60); assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
assertThatThrownBy(() -> executor.setKeepAliveSeconds(-10)) assertThatIllegalArgumentException().isThrownBy(() -> executor.setKeepAliveSeconds(-10));
.isInstanceOf(IllegalArgumentException.class);
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60); assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60); assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
@ -123,8 +120,8 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
void queueCapacityDefault() { void queueCapacityDefault() {
assertThat(executor.getQueueCapacity()).isEqualTo(Integer.MAX_VALUE); assertThat(executor.getQueueCapacity()).isEqualTo(Integer.MAX_VALUE);
assertThat(executor.getThreadPoolExecutor().getQueue()) assertThat(executor.getThreadPoolExecutor().getQueue())
.asInstanceOf(type(LinkedBlockingQueue.class)) .asInstanceOf(type(LinkedBlockingQueue.class))
.extracting(BlockingQueue::remainingCapacity).isEqualTo(Integer.MAX_VALUE); .extracting(BlockingQueue::remainingCapacity).isEqualTo(Integer.MAX_VALUE);
} }
@Test @Test
@ -134,8 +131,8 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
assertThat(executor.getQueueCapacity()).isZero(); assertThat(executor.getQueueCapacity()).isZero();
assertThat(executor.getThreadPoolExecutor().getQueue()) assertThat(executor.getThreadPoolExecutor().getQueue())
.asInstanceOf(type(SynchronousQueue.class)) .asInstanceOf(type(SynchronousQueue.class))
.extracting(BlockingQueue::remainingCapacity).isEqualTo(0); .extracting(BlockingQueue::remainingCapacity).isEqualTo(0);
} }
@Test @Test