Use virtual threads in JmsHealthIndicator if enabled
Closes gh-36694
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.actuate.jms;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import jakarta.jms.Connection;
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.ConnectionMetaData;
|
||||
@@ -26,6 +28,8 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -41,6 +45,10 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
class JmsHealthIndicatorTests {
|
||||
|
||||
private static final Duration TIMEOUT = Duration.ofMillis(100);
|
||||
|
||||
private final AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
|
||||
|
||||
@Test
|
||||
void jmsBrokerIsUp() throws JMSException {
|
||||
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
|
||||
@@ -49,7 +57,7 @@ class JmsHealthIndicatorTests {
|
||||
given(connection.getMetaData()).willReturn(connectionMetaData);
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory, this.taskExecutor, TIMEOUT);
|
||||
Health health = indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsEntry("provider", "JMS test provider");
|
||||
@@ -60,7 +68,7 @@ class JmsHealthIndicatorTests {
|
||||
void jmsBrokerIsDown() throws JMSException {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willThrow(new JMSException("test", "123"));
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory, this.taskExecutor, TIMEOUT);
|
||||
Health health = indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(health.getDetails()).doesNotContainKey("provider");
|
||||
@@ -74,7 +82,7 @@ class JmsHealthIndicatorTests {
|
||||
given(connection.getMetaData()).willReturn(connectionMetaData);
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory, this.taskExecutor, TIMEOUT);
|
||||
Health health = indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(health.getDetails()).doesNotContainKey("provider");
|
||||
@@ -90,7 +98,7 @@ class JmsHealthIndicatorTests {
|
||||
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);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory, this.taskExecutor, TIMEOUT);
|
||||
Health health = indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(health.getDetails()).doesNotContainKey("provider");
|
||||
@@ -109,7 +117,7 @@ class JmsHealthIndicatorTests {
|
||||
}).given(connection).close();
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willReturn(connection);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory, this.taskExecutor, TIMEOUT);
|
||||
Health health = indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat((String) health.getDetails().get("error")).contains("Connection closed");
|
||||
|
||||
Reference in New Issue
Block a user