use of jakarta.jms.ConnectionMetaData in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method whenConnectionStartIsUnresponsiveStatusIsDown.
@Test
void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
UnresponsiveStartAnswer unresponsiveStartAnswer = new UnresponsiveStartAnswer();
willAnswer(unresponsiveStartAnswer).given(connection).start();
willAnswer((invocation) -> {
unresponsiveStartAnswer.connectionClosed();
return null;
}).given(connection).close();
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((String) health.getDetails().get("error")).contains("Connection closed");
}
use of jakarta.jms.ConnectionMetaData in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerUsesFailover.
@Test
void jmsBrokerUsesFailover() throws JMSException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
Connection connection = mock(Connection.class);
given(connection.getMetaData()).willReturn(connectionMetaData);
willThrow(new JMSException("Could not start", "123")).given(connection).start();
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();
}
use of jakarta.jms.ConnectionMetaData in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerCouldNotRetrieveProviderMetadata.
@Test
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();
then(connection).should().close();
}
use of jakarta.jms.ConnectionMetaData in project spring-boot by spring-projects.
the class JmsHealthIndicatorTests method jmsBrokerIsUp.
@Test
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");
then(connection).should().close();
}
Aggregations