AnnotationAsyncExecutionAspect properly accepts ListenableFuture return type

Issue: SPR-12895
This commit is contained in:
Juergen Hoeller
2015-04-15 14:57:43 +02:00
parent c006b74e91
commit 8b2d9951e0
2 changed files with 36 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -35,6 +35,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.Matchers.not;
@@ -50,9 +51,10 @@ public class AnnotationAsyncExecutionAspectTests {
private static final long WAIT_TIME = 1000; //milliseconds
private final AsyncUncaughtExceptionHandler defaultExceptionHandler = new SimpleAsyncUncaughtExceptionHandler();
private CountingExecutor executor;
private AsyncUncaughtExceptionHandler defaultExceptionHandler = new SimpleAsyncUncaughtExceptionHandler();
@Before
public void setUp() {
@@ -62,6 +64,7 @@ public class AnnotationAsyncExecutionAspectTests {
AnnotationAsyncExecutionAspect.aspectOf().setExecutor(executor);
}
@Test
public void asyncMethodGetsRoutedAsynchronously() {
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
@@ -184,7 +187,9 @@ public class AnnotationAsyncExecutionAspectTests {
@SuppressWarnings("serial")
private static class CountingExecutor extends SimpleAsyncTaskExecutor {
int submitStartCounter;
int submitCompleteCounter;
@Override
@@ -209,6 +214,7 @@ public class AnnotationAsyncExecutionAspectTests {
static class ClassWithoutAsyncAnnotation {
int counter;
@Async public void incrementAsync() {
@@ -239,6 +245,7 @@ public class AnnotationAsyncExecutionAspectTests {
@Async
static class ClassWithAsyncAnnotation {
int counter;
public void increment() {
@@ -261,17 +268,19 @@ public class AnnotationAsyncExecutionAspectTests {
static class ClassWithQualifiedAsyncMethods {
@Async
public Future<Thread> defaultWork() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("e1")
public Future<Thread> e1Work() {
public ListenableFuture<Thread> e1Work() {
return new AsyncResult<Thread>(Thread.currentThread());
}
}
static class ClassWithException {
@Async
@@ -279,4 +288,5 @@ public class AnnotationAsyncExecutionAspectTests {
throw new UnsupportedOperationException("failWithVoid");
}
}
}