use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithConnectionAggregatedStartStop.
@Test
public void testWithConnectionAggregatedStartStop() throws JMSException {
Connection con = mock(Connection.class);
SingleConnectionFactory scf = new SingleConnectionFactory(con);
Connection con1 = scf.createConnection();
con1.start();
verify(con).start();
con1.stop();
verify(con).stop();
Connection con2 = scf.createConnection();
con2.start();
verify(con, times(2)).start();
con2.stop();
verify(con, times(2)).stop();
con2.start();
verify(con, times(3)).start();
con1.start();
con2.stop();
con1.stop();
verify(con, times(3)).stop();
con1.start();
verify(con, times(4)).start();
con1.close();
verify(con, times(4)).stop();
con2.close();
scf.destroy();
verify(con).close();
verifyNoMoreInteractions(con);
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithTopicConnection.
@Test
public void testWithTopicConnection() throws JMSException {
Connection con = mock(TopicConnection.class);
SingleConnectionFactory scf = new SingleConnectionFactory(con);
TopicConnection con1 = scf.createTopicConnection();
con1.start();
con1.stop();
con1.close();
TopicConnection con2 = scf.createTopicConnection();
con2.start();
con2.stop();
con2.close();
// should trigger actual close
scf.destroy();
verify(con, times(2)).start();
verify(con, times(2)).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testCachingConnectionFactory.
@Test
public void testCachingConnectionFactory() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
Session txSession = mock(Session.class);
Session nonTxSession = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
given(txSession.getTransacted()).willReturn(true);
given(con.createSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
CachingConnectionFactory scf = new CachingConnectionFactory(cf);
scf.setReconnectOnException(false);
Connection con1 = scf.createConnection();
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.getTransacted();
// should lead to rollback
session1.close();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
Connection con2 = scf.createConnection();
Session session2 = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session2.close();
session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
session2.commit();
session2.close();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(txSession).commit();
verify(txSession).close();
verify(nonTxSession).close();
verify(con).start();
verify(con).stop();
verify(con).close();
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithQueueConnectionFactoryAndJms102Usage.
@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
QueueConnection con = mock(QueueConnection.class);
given(cf.createQueueConnection()).willReturn(con);
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
Connection con1 = scf.createQueueConnection();
Connection con2 = scf.createQueueConnection();
con1.start();
con2.start();
con1.close();
con2.close();
// should trigger actual close
scf.destroy();
verify(con).start();
verify(con).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
use of jakarta.jms.Connection in project spring-framework by spring-projects.
the class JmsResourceHolder method closeAll.
/**
* Close all of this resource holder's Sessions and clear its state.
* @see Session#close()
*/
public void closeAll() {
for (Session session : this.sessions) {
try {
session.close();
} catch (Throwable ex) {
logger.debug("Could not close synchronized JMS Session after transaction", ex);
}
}
for (Connection con : this.connections) {
ConnectionFactoryUtils.releaseConnection(con, this.connectionFactory, true);
}
this.connections.clear();
this.sessions.clear();
this.sessionsPerConnection.clear();
}
Aggregations