|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.jms;
|
18 | 18 |
|
| 19 | +import java.util.concurrent.CountDownLatch; |
| 20 | +import java.util.concurrent.TimeUnit; |
| 21 | + |
19 | 22 | import javax.jms.Connection;
|
20 | 23 | import javax.jms.ConnectionFactory;
|
21 | 24 | import javax.jms.ConnectionMetaData;
|
|
27 | 30 | import org.springframework.boot.actuate.health.Status;
|
28 | 31 |
|
29 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
| 33 | +import static org.assertj.core.api.Assertions.entry; |
30 | 34 | import static org.mockito.BDDMockito.given;
|
| 35 | +import static org.mockito.BDDMockito.willAnswer; |
31 | 36 | import static org.mockito.BDDMockito.willThrow;
|
32 | 37 | import static org.mockito.Mockito.mock;
|
33 | 38 | import static org.mockito.Mockito.times;
|
|
37 | 42 | * Tests for {@link JmsHealthIndicator}.
|
38 | 43 | *
|
39 | 44 | * @author Stephane Nicoll
|
| 45 | + * @author Filip Hrisafov |
40 | 46 | */
|
41 | 47 | public class JmsHealthIndicatorTests {
|
42 | 48 |
|
@@ -97,4 +103,25 @@ public void jmsBrokerUsesFailover() throws JMSException {
|
97 | 103 | assertThat(health.getDetails().get("provider")).isNull();
|
98 | 104 | }
|
99 | 105 |
|
| 106 | + @Test public void jmsBrokerUsesInfiniteFailover() throws JMSException { |
| 107 | + CountDownLatch latch = new CountDownLatch(1); |
| 108 | + ConnectionFactory connectionFactory = mock(ConnectionFactory.class); |
| 109 | + ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class); |
| 110 | + given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider"); |
| 111 | + Connection connection = mock(Connection.class); |
| 112 | + given(connection.getMetaData()).willReturn(connectionMetaData); |
| 113 | + willAnswer(invocationOnMock -> latch.await(1, TimeUnit.SECONDS)).given(connection) |
| 114 | + .start(); |
| 115 | + given(connectionFactory.createConnection()).willReturn(connection); |
| 116 | + JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory); |
| 117 | + Health health = indicator.health(); |
| 118 | + assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); |
| 119 | + assertThat(health.getDetails()).as("Health Details") |
| 120 | + .containsExactly(entry("provider", "JMS test provider"), |
| 121 | + entry("cause", "Could not connect for 100 milliseconds")); |
| 122 | + verify(connection, times(1)).close(); |
| 123 | + verify(connection, times(1)).start(); |
| 124 | + latch.countDown(); |
| 125 | + } |
| 126 | + |
100 | 127 | }
|
0 commit comments