Clean up warnings and polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,6 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
|
||||
|
||||
@@ -267,9 +266,11 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void listenableFutureReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
SettableListenableFuture<String> future = new SettableListenableFuture<>();
|
||||
org.springframework.util.concurrent.SettableListenableFuture<String> future =
|
||||
new org.springframework.util.concurrent.SettableListenableFuture<>();
|
||||
future.set("dummy");
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, future);
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
|
||||
@@ -433,6 +433,7 @@ class GenericApplicationContextTests {
|
||||
assertThat(context.getBeanFactory().getMergedBeanDefinition("test")
|
||||
.hasAttribute("mbdppCalled")).isTrue();
|
||||
assertThat(context.getBean("test")).isEqualTo("42");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,6 @@ import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -276,7 +275,8 @@ public class AsyncAnnotationBeanPostProcessorTests {
|
||||
|
||||
Future<Object> failWithFuture();
|
||||
|
||||
ListenableFuture<Object> failWithListenableFuture();
|
||||
@SuppressWarnings("deprecation")
|
||||
org.springframework.util.concurrent.ListenableFuture<Object> failWithListenableFuture();
|
||||
|
||||
void failWithVoid();
|
||||
|
||||
@@ -310,7 +310,8 @@ public class AsyncAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public ListenableFuture<Object> failWithListenableFuture() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public org.springframework.util.concurrent.ListenableFuture<Object> failWithListenableFuture() {
|
||||
throw new UnsupportedOperationException("failWithListenableFuture");
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@SuppressWarnings({ "resource", "deprecation" })
|
||||
public class AsyncExecutionTests {
|
||||
|
||||
private static String originalThreadName;
|
||||
|
||||
@@ -23,9 +23,6 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@@ -35,11 +32,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
public class AsyncResultTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void asyncResultWithCallbackAndValue() throws Exception {
|
||||
String value = "val";
|
||||
final Set<String> values = new HashSet<>(1);
|
||||
ListenableFuture<String> future = AsyncResult.forValue(value);
|
||||
future.addCallback(new ListenableFutureCallback<String>() {
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = AsyncResult.forValue(value);
|
||||
future.addCallback(new org.springframework.util.concurrent.ListenableFutureCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
values.add(result);
|
||||
@@ -56,11 +54,12 @@ public class AsyncResultTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void asyncResultWithCallbackAndException() throws Exception {
|
||||
IOException ex = new IOException();
|
||||
final Set<Throwable> values = new HashSet<>(1);
|
||||
ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
|
||||
future.addCallback(new ListenableFutureCallback<String>() {
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
|
||||
future.addCallback(new org.springframework.util.concurrent.ListenableFutureCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
throw new AssertionError("Success callback not expected: " + result);
|
||||
@@ -71,19 +70,20 @@ public class AsyncResultTests {
|
||||
}
|
||||
});
|
||||
assertThat(values.iterator().next()).isSameAs(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
future::get)
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future::get)
|
||||
.withCause(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
future.completable()::get)
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future.completable()::get)
|
||||
.withCause(ex);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
|
||||
String value = "val";
|
||||
final Set<String> values = new HashSet<>(1);
|
||||
ListenableFuture<String> future = AsyncResult.forValue(value);
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = AsyncResult.forValue(value);
|
||||
future.addCallback(values::add, ex -> new AssertionError("Failure callback not expected: " + ex));
|
||||
assertThat(values.iterator().next()).isSameAs(value);
|
||||
assertThat(future.get()).isSameAs(value);
|
||||
@@ -92,17 +92,18 @@ public class AsyncResultTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void asyncResultWithSeparateCallbacksAndException() throws Exception {
|
||||
IOException ex = new IOException();
|
||||
final Set<Throwable> values = new HashSet<>(1);
|
||||
ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
|
||||
future.addCallback(result -> new AssertionError("Success callback not expected: " + result), values::add);
|
||||
assertThat(values.iterator().next()).isSameAs(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
future::get)
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future::get)
|
||||
.withCause(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
future.completable()::get)
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future.completable()::get)
|
||||
.withCause(ex);
|
||||
}
|
||||
|
||||
|
||||
@@ -346,6 +346,7 @@ public class EnableAsyncTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static class AsyncBeanWithExecutorQualifiedByName {
|
||||
|
||||
@Async
|
||||
@@ -369,6 +370,7 @@ public class EnableAsyncTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static class AsyncBeanWithExecutorQualifiedByExpressionOrPlaceholder {
|
||||
|
||||
@Async("#{environment['myExecutor']}")
|
||||
|
||||
@@ -35,9 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -49,7 +47,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
abstract class AbstractSchedulingTaskExecutorTests {
|
||||
|
||||
private AsyncListenableTaskExecutor executor;
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.core.task.AsyncListenableTaskExecutor executor;
|
||||
|
||||
protected String testName;
|
||||
|
||||
@@ -65,7 +64,8 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
this.executor = buildExecutor();
|
||||
}
|
||||
|
||||
protected abstract AsyncListenableTaskExecutor buildExecutor();
|
||||
@SuppressWarnings("deprecation")
|
||||
protected abstract org.springframework.core.task.AsyncListenableTaskExecutor buildExecutor();
|
||||
|
||||
@AfterEach
|
||||
void shutdownExecutor() throws Exception {
|
||||
@@ -125,10 +125,11 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitListenableRunnable() throws Exception {
|
||||
TestTask task = new TestTask(this.testName, 1);
|
||||
// Act
|
||||
ListenableFuture<?> future = executor.submitListenable(task);
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
|
||||
future.addCallback(result -> outcome = result, ex -> outcome = ex);
|
||||
// Assert
|
||||
Awaitility.await()
|
||||
@@ -155,9 +156,10 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitFailingListenableRunnable() throws Exception {
|
||||
TestTask task = new TestTask(this.testName, 0);
|
||||
ListenableFuture<?> future = executor.submitListenable(task);
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future = executor.submitListenable(task);
|
||||
future.addCallback(result -> outcome = result, ex -> outcome = ex);
|
||||
|
||||
Awaitility.await()
|
||||
@@ -183,9 +185,10 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitListenableRunnableWithGetAfterShutdown() throws Exception {
|
||||
ListenableFuture<?> future1 = executor.submitListenable(new TestTask(this.testName, -1));
|
||||
ListenableFuture<?> future2 = executor.submitListenable(new TestTask(this.testName, -1));
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future1 = executor.submitListenable(new TestTask(this.testName, -1));
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future2 = executor.submitListenable(new TestTask(this.testName, -1));
|
||||
shutdownExecutor();
|
||||
|
||||
try {
|
||||
@@ -218,8 +221,8 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
.atMost(4, TimeUnit.SECONDS)
|
||||
.pollInterval(10, TimeUnit.MILLISECONDS)
|
||||
.untilAsserted(() ->
|
||||
assertThatExceptionOfType(TimeoutException.class).isThrownBy(() ->
|
||||
future2.get(1000, TimeUnit.MILLISECONDS)));
|
||||
assertThatExceptionOfType(TimeoutException.class)
|
||||
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,8 +237,8 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
void submitFailingCallable() throws Exception {
|
||||
TestCallable task = new TestCallable(this.testName, 0);
|
||||
Future<String> future = executor.submit(task);
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
|
||||
future.get(1000, TimeUnit.MILLISECONDS));
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(() -> future.get(1000, TimeUnit.MILLISECONDS));
|
||||
assertThat(future.isDone()).isTrue();
|
||||
}
|
||||
|
||||
@@ -255,15 +258,16 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
.atMost(4, TimeUnit.SECONDS)
|
||||
.pollInterval(10, TimeUnit.MILLISECONDS)
|
||||
.untilAsserted(() ->
|
||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() ->
|
||||
future2.get(1000, TimeUnit.MILLISECONDS)));
|
||||
assertThatExceptionOfType(CancellationException.class)
|
||||
.isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitListenableCallable() throws Exception {
|
||||
TestCallable task = new TestCallable(this.testName, 1);
|
||||
// Act
|
||||
ListenableFuture<String> future = executor.submitListenable(task);
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
|
||||
future.addCallback(result -> outcome = result, ex -> outcome = ex);
|
||||
// Assert
|
||||
Awaitility.await()
|
||||
@@ -274,10 +278,11 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitFailingListenableCallable() throws Exception {
|
||||
TestCallable task = new TestCallable(this.testName, 0);
|
||||
// Act
|
||||
ListenableFuture<String> future = executor.submitListenable(task);
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = executor.submitListenable(task);
|
||||
future.addCallback(result -> outcome = result, ex -> outcome = ex);
|
||||
// Assert
|
||||
Awaitility.await()
|
||||
@@ -289,9 +294,10 @@ abstract class AbstractSchedulingTaskExecutorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void submitListenableCallableWithGetAfterShutdown() throws Exception {
|
||||
ListenableFuture<?> future1 = executor.submitListenable(new TestCallable(this.testName, -1));
|
||||
ListenableFuture<?> future2 = executor.submitListenable(new TestCallable(this.testName, -1));
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future1 = executor.submitListenable(new TestCallable(this.testName, -1));
|
||||
org.springframework.util.concurrent.ListenableFuture<?> future2 = executor.submitListenable(new TestCallable(this.testName, -1));
|
||||
shutdownExecutor();
|
||||
assertThatExceptionOfType(CancellationException.class).isThrownBy(() -> {
|
||||
future1.get(1000, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.core.task.NoOpRunnable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
@@ -40,7 +39,8 @@ class ConcurrentTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||
|
||||
|
||||
@Override
|
||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected org.springframework.core.task.AsyncListenableTaskExecutor buildExecutor() {
|
||||
concurrentExecutor.setThreadFactory(new CustomizableThreadFactory(this.threadNamePrefix));
|
||||
return new ConcurrentTaskExecutor(concurrentExecutor);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.scheduling.concurrent;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable;
|
||||
import org.springframework.scheduling.support.TaskUtils;
|
||||
|
||||
@@ -27,7 +26,8 @@ import org.springframework.scheduling.support.TaskUtils;
|
||||
class DecoratedThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||
|
||||
@Override
|
||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected org.springframework.core.task.AsyncListenableTaskExecutor buildExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setTaskDecorator(runnable ->
|
||||
new DelegatingErrorHandlingRunnable(runnable, TaskUtils.LOG_AND_PROPAGATE_ERROR_HANDLER));
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@@ -43,7 +41,8 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||
|
||||
|
||||
@Override
|
||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected org.springframework.core.task.AsyncListenableTaskExecutor buildExecutor() {
|
||||
executor.setThreadNamePrefix(this.threadNamePrefix);
|
||||
executor.setMaxPoolSize(1);
|
||||
executor.afterPropertiesSet();
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.RepeatedTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.TriggerContext;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
@@ -46,8 +45,9 @@ class ThreadPoolTaskSchedulerTests extends AbstractSchedulingTaskExecutorTests {
|
||||
private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||
protected org.springframework.core.task.AsyncListenableTaskExecutor buildExecutor() {
|
||||
scheduler.setThreadNamePrefix(this.threadNamePrefix);
|
||||
scheduler.afterPropertiesSet();
|
||||
return scheduler;
|
||||
|
||||
Reference in New Issue
Block a user