mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Merge branch '4.1.x'
Closes gh-51434
This commit is contained in:
+10
-4
@@ -96,7 +96,7 @@ public class JmsHealthIndicator extends AbstractHealthIndicator {
|
||||
}
|
||||
|
||||
void start() throws JMSException {
|
||||
new Thread(() -> {
|
||||
Thread watchdog = new Thread(() -> {
|
||||
try {
|
||||
Duration startTimeout1 = JmsHealthIndicator.this.startTimeout;
|
||||
if (!this.latch.await(startTimeout1.toNanos(), TimeUnit.NANOSECONDS)) {
|
||||
@@ -109,9 +109,15 @@ public class JmsHealthIndicator extends AbstractHealthIndicator {
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}, "jms-health-indicator").start();
|
||||
this.connection.start();
|
||||
this.latch.countDown();
|
||||
}, "jms-health-indicator");
|
||||
watchdog.setDaemon(true);
|
||||
watchdog.start();
|
||||
try {
|
||||
this.connection.start();
|
||||
}
|
||||
finally {
|
||||
this.latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeConnection() {
|
||||
|
||||
+13
@@ -35,6 +35,7 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.BDDMockito.willAnswer;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.after;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -123,6 +124,18 @@ class JmsHealthIndicatorTests {
|
||||
assertThat(health.getDetails()).doesNotContainKey("provider");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenConnectionStartThrowsWatchdogThreadDoesNotAlsoCloseConnection() throws JMSException {
|
||||
Connection connection = mock(Connection.class);
|
||||
willThrow(new JMSException("Could not start", "123")).given(connection).start();
|
||||
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);
|
||||
then(connection).should(after(Duration.ofSeconds(5).plusMillis(500).toMillis()).times(1)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
|
||||
Health health = healthWhenConnectionStartIsUnresponsive(Duration.ofSeconds(5));
|
||||
|
||||
Reference in New Issue
Block a user