Search in sources :

Example 1 with ConnectionMetaData

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");
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) ConnectionMetaData(jakarta.jms.ConnectionMetaData) Connection(jakarta.jms.Connection) Test(org.junit.jupiter.api.Test)

Example 2 with ConnectionMetaData

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();
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) ConnectionMetaData(jakarta.jms.ConnectionMetaData) Connection(jakarta.jms.Connection) JMSException(jakarta.jms.JMSException) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionMetaData

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();
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) ConnectionMetaData(jakarta.jms.ConnectionMetaData) Connection(jakarta.jms.Connection) JMSException(jakarta.jms.JMSException) Test(org.junit.jupiter.api.Test)

Example 4 with ConnectionMetaData

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();
}
Also used : ConnectionFactory(jakarta.jms.ConnectionFactory) Health(org.springframework.boot.actuate.health.Health) ConnectionMetaData(jakarta.jms.ConnectionMetaData) Connection(jakarta.jms.Connection) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (jakarta.jms.Connection)4 ConnectionFactory (jakarta.jms.ConnectionFactory)4 ConnectionMetaData (jakarta.jms.ConnectionMetaData)4 Test (org.junit.jupiter.api.Test)4 Health (org.springframework.boot.actuate.health.Health)4 JMSException (jakarta.jms.JMSException)2