Clean up after deprecation of AsyncResult

See gh-33809
This commit is contained in:
Sam Brannen
2024-12-15 15:53:33 +01:00
parent 8a8df90a46
commit bf80485cc3
2 changed files with 24 additions and 36 deletions

View File

@@ -27,11 +27,6 @@ import org.springframework.lang.Nullable;
* A pass-through {@code Future} handle that can be used for method signatures
* which are declared with a {@code Future} return type for asynchronous execution.
*
* <p>As of Spring 4.1, this class implements {@code ListenableFuture}, not just
* plain {@link java.util.concurrent.Future}, along with the corresponding support
* in {@code @Async} processing. As of 7.0, this will be turned back to a plain
* {@code Future} in order to focus on compatibility with existing common usage.
*
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @since 3.0
@@ -123,20 +118,4 @@ public class AsyncResult<V> implements Future<V> {
return new AsyncResult<>(null, ex);
}
/**
* Determine the exposed exception: either the cause of a given
* {@link ExecutionException}, or the original exception as-is.
* @param original the original as given to {@link #forExecutionException}
* @return the exposed exception
*/
private static Throwable exposedException(Throwable original) {
if (original instanceof ExecutionException) {
Throwable cause = original.getCause();
if (cause != null) {
return cause;
}
}
return original;
}
}

View File

@@ -82,17 +82,17 @@ class AsyncExecutionTests {
CompletableFuture<String> completableFuture = asyncTest.returnSomethingCompletable(20);
assertThat(completableFuture.get()).isEqualTo("20");
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
asyncTest.returnSomething(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> asyncTest.returnSomething(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
asyncTest.returnSomething(-1).get())
.withCauseInstanceOf(IOException.class);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> asyncTest.returnSomething(-1).get())
.withCauseInstanceOf(IOException.class);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
asyncTest.returnSomethingCompletable(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -165,13 +165,13 @@ class AsyncExecutionTests {
CompletableFuture<String> completableFuture = asyncTest.returnSomethingCompletable(20);
assertThat(completableFuture.get()).isEqualTo("20");
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
asyncTest.returnSomething(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> asyncTest.returnSomething(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() ->
asyncTest.returnSomethingCompletable(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> asyncTest.returnSomethingCompletable(0).get())
.withCauseInstanceOf(IllegalArgumentException.class);
}
@Test
@@ -390,6 +390,7 @@ class AsyncExecutionTests {
}
@Async
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
if (i == 0) {
@@ -435,12 +436,14 @@ class AsyncExecutionTests {
}
@MyAsync
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
assertThat(Thread.currentThread().getName()).startsWith("e2-");
return new AsyncResult<>(Integer.toString(i));
}
@SuppressWarnings("deprecation")
public Future<String> returnSomething2(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
assertThat(Thread.currentThread().getName()).startsWith("e0-");
@@ -467,6 +470,7 @@ class AsyncExecutionTests {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
}
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
if (i == 0) {
@@ -507,6 +511,7 @@ class AsyncExecutionTests {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -531,6 +536,7 @@ class AsyncExecutionTests {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -542,6 +548,7 @@ class AsyncExecutionTests {
private final AsyncInterface proxy;
@SuppressWarnings("deprecation")
public DynamicAsyncInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
@@ -598,6 +605,7 @@ class AsyncExecutionTests {
}
@Override
@SuppressWarnings("deprecation")
public Future<String> returnSomething(int i) {
assertThat(Thread.currentThread().getName()).isNotEqualTo(originalThreadName);
return new AsyncResult<>(Integer.toString(i));
@@ -609,6 +617,7 @@ class AsyncExecutionTests {
private final AsyncMethodsInterface proxy;
@SuppressWarnings("deprecation")
public DynamicAsyncMethodsInterfaceBean() {
ProxyFactory pf = new ProxyFactory(new HashMap<>());
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {