Manage asynchronous EventListener with replies

This commit makes sure to reject an `@EventListener` annotated method
that also uses `@Async`. In such scenario, the method is invoked in a
separate thread and the infrastructure has no handle on the actual reply,
if any.

The documentation has been improved to refer to that scenario.

Issue: SPR-14113
This commit is contained in:
Stephane Nicoll
2016-04-12 09:06:48 +02:00
parent 44a9c495ab
commit bee1b77af5
3 changed files with 68 additions and 2 deletions

View File

@@ -155,6 +155,19 @@ public class AnnotationDrivenEventListenerTests {
failingContext.refresh();
}
@Test
public void asyncWithReplyEventListener() {
AnnotationConfigApplicationContext failingContext =
new AnnotationConfigApplicationContext();
failingContext.register(BasicConfiguration.class,
InvalidAsyncEventListener.class);
this.thrown.expect(BeanInitializationException.class);
this.thrown.expectMessage(InvalidAsyncEventListener.class.getName());
this.thrown.expectMessage("asyncCannotUseReply");
failingContext.refresh();
}
@Test
public void simpleReply() {
load(TestEventListener.class, ReplyEventListener.class);
@@ -656,6 +669,17 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
static class InvalidAsyncEventListener {
@EventListener
@Async
public Integer asyncCannotUseReply(String payload) {
return 42;
}
}
@Component
static class ReplyEventListener extends AbstractTestEventListener {
@@ -766,6 +790,7 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.addEvent(this, event);
this.countDownLatch.countDown();
}
}
@@ -869,7 +894,6 @@ public class AnnotationDrivenEventListenerTests {
}
@EventListener
@Retention(RetentionPolicy.RUNTIME)
public @interface ConditionalEvent {