Avoid transaction listener execution without transaction management setup
Closes gh-32319
This commit is contained in:
@@ -269,8 +269,7 @@ class TransactionalEventListenerTests {
|
||||
|
||||
@Test
|
||||
void noTransaction() {
|
||||
load(BeforeCommitTestListener.class, AfterCompletionTestListener.class,
|
||||
AfterCompletionExplicitTestListener.class);
|
||||
load(BeforeCommitTestListener.class, AfterCompletionTestListener.class, AfterCompletionExplicitTestListener.class);
|
||||
this.context.publishEvent("test");
|
||||
getEventCollector().assertTotalEventsCount(0);
|
||||
}
|
||||
@@ -318,6 +317,24 @@ class TransactionalEventListenerTests {
|
||||
getEventCollector().assertTotalEventsCount(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noTransactionManagementWithFallbackExecution() {
|
||||
doLoad(PlainConfiguration.class, FallbackExecutionTestListener.class);
|
||||
this.context.publishEvent("test");
|
||||
this.eventCollector.assertEvents(EventCollector.BEFORE_COMMIT, "test");
|
||||
this.eventCollector.assertEvents(EventCollector.AFTER_COMMIT, "test");
|
||||
this.eventCollector.assertEvents(EventCollector.AFTER_ROLLBACK, "test");
|
||||
this.eventCollector.assertEvents(EventCollector.AFTER_COMPLETION, "test");
|
||||
getEventCollector().assertTotalEventsCount(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noTransactionManagementWithoutFallbackExecution() {
|
||||
doLoad(PlainConfiguration.class, BeforeCommitTestListener.class, AfterCommitMetaAnnotationTestListener.class);
|
||||
this.context.publishEvent("test");
|
||||
this.eventCollector.assertNoEventReceived();
|
||||
}
|
||||
|
||||
@Test
|
||||
void conditionFoundOnTransactionalEventListener() {
|
||||
load(ImmediateTestListener.class);
|
||||
@@ -401,6 +418,31 @@ class TransactionalEventListenerTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class PlainConfiguration {
|
||||
|
||||
@Bean
|
||||
public EventCollector eventCollector() {
|
||||
return new EventCollector();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean testBean(ApplicationEventPublisher eventPublisher) {
|
||||
return new TestBean(eventPublisher);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CallCountingTransactionManager transactionManager() {
|
||||
return new CallCountingTransactionManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransactionTemplate transactionTemplate() {
|
||||
return new TransactionTemplate(transactionManager());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class MulticasterWithCustomExecutor {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user