mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-24 18:29:03 +00:00
Merge pull request #48484 from youngledo
* pr/48484: Polish "Use 'unknown' when RabbitMQ version is missing" Use 'unknown' when RabbitMQ version is missing Closes gh-48484
This commit is contained in:
+4
-2
@@ -45,8 +45,10 @@ public class RabbitHealthIndicator extends AbstractHealthIndicator {
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
return this.rabbitTemplate
|
||||
.execute((channel) -> channel.getConnection().getServerProperties().get("version").toString());
|
||||
return this.rabbitTemplate.execute((channel) -> channel.getConnection()
|
||||
.getServerProperties()
|
||||
.getOrDefault("version", "unknown")
|
||||
.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
@@ -67,6 +67,17 @@ class RabbitHealthIndicatorTests {
|
||||
assertThat(health.getDetails()).containsEntry("version", "123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthWhenVersionIsMissingShouldReturnUpWithUnknownVersion() {
|
||||
givenTemplateExecutionWillInvokeCallback();
|
||||
Connection connection = mock(Connection.class);
|
||||
given(this.channel.getConnection()).willReturn(connection);
|
||||
given(connection.getServerProperties()).willReturn(Collections.emptyMap());
|
||||
Health health = new RabbitHealthIndicator(this.rabbitTemplate).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsEntry("version", "unknown");
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthWhenConnectionFailsShouldReturnDown() {
|
||||
givenTemplateExecutionWillInvokeCallback();
|
||||
|
||||
Reference in New Issue
Block a user