use of org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy in project spring-framework by spring-projects.
the class JmsTemplateTests method testSessionCallbackWithinSynchronizedTransaction.
@Test
public void testSessionCallbackWithinSynchronizedTransaction() throws Exception {
SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory);
JmsTemplate template = createTemplate();
template.setConnectionFactory(scf);
TransactionSynchronizationManager.initSynchronization();
try {
template.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
session.getTransacted();
return null;
}
});
template.execute(new SessionCallback<Void>() {
@Override
public Void doInJms(Session session) throws JMSException {
session.getTransacted();
return null;
}
});
assertSame(session, ConnectionFactoryUtils.getTransactionalSession(scf, null, false));
assertSame(session, ConnectionFactoryUtils.getTransactionalSession(scf, scf.createConnection(), false));
TransactionAwareConnectionFactoryProxy tacf = new TransactionAwareConnectionFactoryProxy(scf);
Connection tac = tacf.createConnection();
Session tas = tac.createSession(false, Session.AUTO_ACKNOWLEDGE);
tas.getTransacted();
tas.close();
tac.close();
List<TransactionSynchronization> synchs = TransactionSynchronizationManager.getSynchronizations();
assertEquals(1, synchs.size());
TransactionSynchronization synch = synchs.get(0);
synch.beforeCommit(false);
synch.beforeCompletion();
synch.afterCommit();
synch.afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
} finally {
TransactionSynchronizationManager.clearSynchronization();
scf.destroy();
}
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
verify(connection).start();
if (useTransactedTemplate()) {
verify(session).commit();
}
verify(session).close();
verify(connection).stop();
verify(connection).close();
}
Aggregations