Skip to content

Commit 8ece1b1

Browse files
committed
Introduce failing/ignored tests for SPR-12738
Issue: SPR-12738
1 parent 7f0f04d commit 8ece1b1

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828

2929
import org.junit.After;
30+
import org.junit.Ignore;
3031
import org.junit.Rule;
3132
import org.junit.Test;
3233
import org.junit.rules.ExpectedException;
@@ -40,6 +41,8 @@
4041
import org.springframework.core.annotation.Order;
4142
import org.springframework.stereotype.Component;
4243
import org.springframework.tests.transaction.CallCountingTransactionManager;
44+
import org.springframework.transaction.annotation.EnableTransactionManagement;
45+
import org.springframework.transaction.annotation.Transactional;
4346
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
4447
import org.springframework.transaction.support.TransactionSynchronizationManager;
4548
import org.springframework.transaction.support.TransactionTemplate;
@@ -147,6 +150,20 @@ public void afterCommit() {
147150
getEventCollector().assertTotalEventsCount(1); // After rollback not invoked
148151
}
149152

153+
// TODO [SPR-12738] Enable test.
154+
@Ignore("Disabled until SPR-12738 is resolved")
155+
@Test
156+
public void afterCommitWithTransactionalComponentListenerProxiedViaDynamicProxy() {
157+
load(TransactionalConfiguration.class, TransactionalComponentAfterCommitTestListener.class);
158+
this.transactionTemplate.execute(status -> {
159+
getContext().publishEvent("SKIP");
160+
getEventCollector().assertNoEventReceived();
161+
return null;
162+
163+
});
164+
getEventCollector().assertNoEventReceived();
165+
}
166+
150167
@Test
151168
public void afterRollback() {
152169
load(AfterCompletionExplicitTestListener.class);
@@ -307,6 +324,16 @@ public EventCollector eventCollector() {
307324
}
308325
}
309326

327+
@EnableTransactionManagement
328+
@Configuration
329+
static class TransactionalConfiguration {
330+
331+
@Bean
332+
public CallCountingTransactionManager transactionManager() {
333+
return new CallCountingTransactionManager();
334+
}
335+
}
336+
310337

311338
protected EventCollector getEventCollector() {
312339
return eventCollector;
@@ -359,8 +386,8 @@ public void assertNoEventReceived(String... phases) {
359386
}
360387
for (String phase : phases) {
361388
List<Object> eventsForPhase = getEvents(phase);
362-
assertEquals("Expected no event for phase '" + phase + "' " +
363-
"but got " + eventsForPhase, 0, eventsForPhase.size());
389+
assertEquals("Expected no events for phase '" + phase + "' " +
390+
"but got " + eventsForPhase + ":", 0, eventsForPhase.size());
364391
}
365392
}
366393

@@ -431,6 +458,23 @@ public void handleAfterRollback(String data) {
431458
}
432459
}
433460

461+
@Transactional
462+
@Component
463+
static interface TransactionalComponentAfterCommitTestListenerInterface {
464+
465+
@TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#data)")
466+
void handleAfterCommit(String data);
467+
}
468+
469+
static class TransactionalComponentAfterCommitTestListener extends BaseTransactionalTestListener implements
470+
TransactionalComponentAfterCommitTestListenerInterface {
471+
472+
@Override
473+
public void handleAfterCommit(String data) {
474+
handleEvent(EventCollector.AFTER_COMMIT, data);
475+
}
476+
}
477+
434478
@Component
435479
static class BeforeCommitTestListener extends BaseTransactionalTestListener {
436480

0 commit comments

Comments
 (0)