Java Code Examples for org.springframework.jms.core.JmsTemplate#execute()
The following examples show how to use
org.springframework.jms.core.JmsTemplate#execute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsTransactionManagerTests.java From java-technology-stack with MIT License | 7 votes |
@Test public void testTransactionRollback() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute(new SessionCallback<Void>() { @Override public Void doInJms(Session sess) { assertTrue(sess == session); return null; } }); tm.rollback(ts); verify(session).rollback(); verify(session).close(); verify(con).close(); }
Example 2
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testTransactionCommit() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
Example 3
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testTransactionRollback() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); tm.rollback(ts); verify(session).rollback(); verify(session).close(); verify(con).close(); }
Example 4
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testSuspendedTransaction() throws JMSException { final ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); final Session session2 = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); given(con.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(session2); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); final JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); TransactionTemplate tt = new TransactionTemplate(tm); tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jt.execute((SessionCallback<Void>) sess -> { assertNotSame(sess, session); return null; }); } }); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(session2).close(); verify(con, times(2)).close(); }
Example 5
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testLazyTransactionalSession() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); JmsTransactionManager tm = new JmsTransactionManager(cf); tm.setLazyResourceRetrieval(true); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
Example 6
Source File: JmsTransactionManagerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testTransactionCommit() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute(new SessionCallback<Void>() { @Override public Void doInJms(Session sess) { assertTrue(sess == session); return null; } }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
Example 7
Source File: JmsTransactionManagerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testTransactionCommit() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute(new SessionCallback<Void>() { @Override public Void doInJms(Session sess) { assertTrue(sess == session); return null; } }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
Example 8
Source File: JmsTransactionManagerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testTransactionRollback() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); JmsTemplate jt = new JmsTemplate(cf); jt.execute(new SessionCallback<Void>() { @Override public Void doInJms(Session sess) { assertTrue(sess == session); return null; } }); tm.rollback(ts); verify(session).rollback(); verify(session).close(); verify(con).close(); }
Example 9
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testParticipatingTransactionWithCommit() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); final JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); TransactionTemplate tt = new TransactionTemplate(tm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); } }); tm.commit(ts); verify(session).commit(); verify(session).close(); verify(con).close(); }
Example 10
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testParticipatingTransactionWithRollbackOnly() throws JMSException { ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); final JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); TransactionTemplate tt = new TransactionTemplate(tm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); status.setRollbackOnly(); } }); try { tm.commit(ts); fail("Should have thrown UnexpectedRollbackException"); } catch (UnexpectedRollbackException ex) { // expected } verify(session).rollback(); verify(session).close(); verify(con).close(); }
Example 11
Source File: JmsTransactionManagerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testTransactionSuspension() throws JMSException { final ConnectionFactory cf = mock(ConnectionFactory.class); Connection con = mock(Connection.class); final Session session = mock(Session.class); final Session session2 = mock(Session.class); given(cf.createConnection()).willReturn(con); given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session, session2); JmsTransactionManager tm = new JmsTransactionManager(cf); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); final JmsTemplate jt = new JmsTemplate(cf); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); TransactionTemplate tt = new TransactionTemplate(tm); tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jt.execute((SessionCallback<Void>) sess -> { assertNotSame(sess, session); return null; }); } }); jt.execute((SessionCallback<Void>) sess -> { assertSame(sess, session); return null; }); tm.commit(ts); verify(session).commit(); verify(session2).commit(); verify(session).close(); verify(session2).close(); verify(con, times(2)).close(); }