Test meta-@Async executor qualification
Prove that Async#value is respected even when using @Async as a meta
annotation.
Issue: SPR-9443
Backport-Issue: SPR-6847
Backport-Commit: 37e024c6eb
This commit is contained in:
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package org.springframework.scheduling.annotation;
|
package org.springframework.scheduling.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
@@ -25,7 +28,7 @@ import static org.junit.Assert.*;
|
|||||||
* Unit tests for {@link AnnotationAsyncExecutionInterceptor}.
|
* Unit tests for {@link AnnotationAsyncExecutionInterceptor}.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 3.1.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class AnnotationAsyncExecutionInterceptorTests {
|
public class AnnotationAsyncExecutionInterceptorTests {
|
||||||
|
|
||||||
@@ -33,21 +36,29 @@ public class AnnotationAsyncExecutionInterceptorTests {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void testGetExecutorQualifier() throws SecurityException, NoSuchMethodException {
|
public void testGetExecutorQualifier() throws SecurityException, NoSuchMethodException {
|
||||||
AnnotationAsyncExecutionInterceptor i = new AnnotationAsyncExecutionInterceptor(null);
|
AnnotationAsyncExecutionInterceptor i = new AnnotationAsyncExecutionInterceptor(null);
|
||||||
{
|
{ // method level
|
||||||
class C { @Async("qMethod") void m() { } }
|
class C { @Async("qMethod") void m() { } }
|
||||||
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
||||||
}
|
}
|
||||||
{
|
{ // class level
|
||||||
@Async("qClass") class C { void m() { } }
|
@Async("qClass") class C { void m() { } }
|
||||||
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qClass"));
|
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qClass"));
|
||||||
}
|
}
|
||||||
{
|
{ // method and class level -> method value overrides
|
||||||
@Async("qClass") class C { @Async("qMethod") void m() { } }
|
@Async("qClass") class C { @Async("qMethod") void m() { } }
|
||||||
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
||||||
}
|
}
|
||||||
{
|
{ // method and class level -> method value, even if empty, overrides
|
||||||
@Async("qClass") class C { @Async void m() { } }
|
@Async("qClass") class C { @Async void m() { } }
|
||||||
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is(""));
|
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is(""));
|
||||||
}
|
}
|
||||||
|
{ // meta annotation with qualifier
|
||||||
|
@MyAsync class C { void m() { } }
|
||||||
|
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMeta"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Async("qMeta")
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@interface MyAsync { }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user