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:
Stéphane Nicoll
2025-12-10 10:19:26 +01:00
2 changed files with 15 additions and 2 deletions
@@ -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());
}
}
@@ -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();