Polishing

This commit is contained in:
Juergen Hoeller
2015-07-15 00:08:11 +02:00
parent 09eb492079
commit 2934256257
5 changed files with 129 additions and 122 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.
@@ -67,17 +67,6 @@ public class EnableAsyncTests {
asyncBean.work();
}
@Configuration
@EnableAsync
static class AsyncConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Test
public void withAsyncBeanWithExecutorQualifiedByName() throws ExecutionException, InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -95,49 +84,6 @@ public class EnableAsyncTests {
assertThat(workerThread3.get().getName(), startsWith("otherExecutor-"));
}
static class AsyncBeanWithExecutorQualifiedByName {
@Async
public Future<Thread> work0() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("e1")
public Future<Thread> work() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("otherExecutor")
public Future<Thread> work2() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("e2")
public Future<Thread> work3() {
return new AsyncResult<Thread>(Thread.currentThread());
}
}
static class AsyncBean {
private Thread threadOfExecution;
@Async
public void work() {
this.threadOfExecution = Thread.currentThread();
}
@Async
public void fail() {
throw new UnsupportedOperationException();
}
public Thread getThreadOfExecution() {
return threadOfExecution;
}
}
@Test
public void asyncProcessorIsOrderedLowestPrecedenceByDefault() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -148,7 +94,6 @@ public class EnableAsyncTests {
assertThat(bpp.getOrder(), is(Ordered.LOWEST_PRECEDENCE));
}
@Test
public void orderAttributeIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -159,17 +104,6 @@ public class EnableAsyncTests {
assertThat(bpp.getOrder(), is(Ordered.HIGHEST_PRECEDENCE));
}
@Configuration
@EnableAsync(order=Ordered.HIGHEST_PRECEDENCE)
static class OrderedAsyncConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Test
public void customAsyncAnnotationIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -188,51 +122,16 @@ public class EnableAsyncTests {
assertTrue("bean was not async advised as expected", isAsyncAdvised);
}
@Configuration
@EnableAsync(annotation=CustomAsync.class)
static class CustomAsyncAnnotationConfig {
@Bean
public CustomAsyncBean asyncBean() {
return new CustomAsyncBean();
}
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface CustomAsync {
}
static class CustomAsyncBean {
@CustomAsync
public void work() {
}
}
/**
* Fails with classpath errors on trying to classload AnnotationAsyncExecutionAspect
*/
@Test(expected=BeanDefinitionStoreException.class)
@Test(expected = BeanDefinitionStoreException.class)
public void aspectModeAspectJAttemptsToRegisterAsyncAspect() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AspectJAsyncAnnotationConfig.class);
ctx.refresh();
}
@Configuration
@EnableAsync(mode=AdviceMode.ASPECTJ)
static class AspectJAsyncAnnotationConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Test
public void customExecutorIsPropagated() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -257,9 +156,111 @@ public class EnableAsyncTests {
}
static class AsyncBeanWithExecutorQualifiedByName {
@Async
public Future<Thread> work0() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("e1")
public Future<Thread> work() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("otherExecutor")
public Future<Thread> work2() {
return new AsyncResult<Thread>(Thread.currentThread());
}
@Async("e2")
public Future<Thread> work3() {
return new AsyncResult<Thread>(Thread.currentThread());
}
}
static class AsyncBean {
private Thread threadOfExecution;
@Async
public void work() {
this.threadOfExecution = Thread.currentThread();
}
@Async
public void fail() {
throw new UnsupportedOperationException();
}
public Thread getThreadOfExecution() {
return threadOfExecution;
}
}
@Configuration
@EnableAsync(annotation = CustomAsync.class)
static class CustomAsyncAnnotationConfig {
@Bean
public CustomAsyncBean asyncBean() {
return new CustomAsyncBean();
}
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface CustomAsync {
}
static class CustomAsyncBean {
@CustomAsync
public void work() {
}
}
@Configuration
@EnableAsync(order = Ordered.HIGHEST_PRECEDENCE)
static class OrderedAsyncConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Configuration
@EnableAsync(mode = AdviceMode.ASPECTJ)
static class AspectJAsyncAnnotationConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Configuration
@EnableAsync
static class AsyncConfig {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
}
}
@Configuration
@EnableAsync
static class CustomExecutorAsyncConfig implements AsyncConfigurer {
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
@@ -288,6 +289,7 @@ public class EnableAsyncTests {
@Configuration
@EnableAsync
static class AsyncWithExecutorQualifiedByNameConfig {
@Bean
public AsyncBeanWithExecutorQualifiedByName asyncBean() {
return new AsyncBeanWithExecutorQualifiedByName();
@@ -295,15 +297,14 @@ public class EnableAsyncTests {
@Bean
public Executor e1() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
return executor;
return new ThreadPoolTaskExecutor();
}
@Bean
@Qualifier("e2")
public Executor otherExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
return executor;
return new ThreadPoolTaskExecutor();
}
}
}