use of javax.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithConnection.
@Test
public void testWithConnection() throws JMSException {
Connection con = mock(Connection.class);
SingleConnectionFactory scf = new SingleConnectionFactory(con);
Connection con1 = scf.createConnection();
con1.start();
con1.stop();
con1.close();
Connection con2 = scf.createConnection();
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 javax.jms.Connection in project spring-framework by spring-projects.
the class SingleConnectionFactoryTests method testWithConnectionFactoryAndLocalExceptionListenerWithReconnect.
@Test
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
TestConnection con = new TestConnection();
given(cf.createConnection()).willReturn(con);
TestExceptionListener listener0 = new TestExceptionListener();
TestExceptionListener listener1 = new TestExceptionListener();
TestExceptionListener listener2 = new TestExceptionListener();
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
scf.setReconnectOnException(true);
scf.setExceptionListener(listener0);
Connection con1 = scf.createConnection();
con1.setExceptionListener(listener1);
assertSame(listener1, con1.getExceptionListener());
con1.start();
Connection con2 = scf.createConnection();
con2.setExceptionListener(listener2);
assertSame(listener2, con2.getExceptionListener());
con.getExceptionListener().onException(new JMSException(""));
con2.close();
con1.getMetaData();
con.getExceptionListener().onException(new JMSException(""));
con1.close();
// should trigger actual close
scf.destroy();
assertEquals(2, con.getStartCount());
assertEquals(2, con.getCloseCount());
assertEquals(2, listener0.getCount());
assertEquals(2, listener1.getCount());
assertEquals(1, listener2.getCount());
}
use of javax.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerIsUp.
@Test
public void jmsBrokerIsUp() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
verify(connection, times(1)).close();
}
use of javax.jms.Connection in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerCouldNotRetrieveProviderMetadata.
@Test
public void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willThrow(new JMSException("test", "123"));
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
verify(connection, times(1)).close();
}
use of javax.jms.Connection in project camel by apache.
the class SjmsConsumer method createConsumer.
/**
* Creates a {@link MessageConsumerResources} with a dedicated
* {@link Session} required for transacted and InOut consumers.
*/
private MessageConsumerResources createConsumer() throws Exception {
MessageConsumerResources answer;
ConnectionResource connectionResource = getOrCreateConnectionResource();
Connection conn = connectionResource.borrowConnection();
try {
Session session = conn.createSession(isTransacted(), isTransacted() ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
MessageConsumer messageConsumer = getEndpoint().getJmsObjectFactory().createMessageConsumer(session, getEndpoint());
MessageListener handler = createMessageHandler(session);
messageConsumer.setMessageListener(handler);
answer = new MessageConsumerResources(session, messageConsumer);
} catch (Exception e) {
log.error("Unable to create the MessageConsumer", e);
throw e;
} finally {
connectionResource.returnConnection(conn);
}
return answer;
}
Aggregations