Merge branch '3.5.x'

Closes gh-48487
This commit is contained in:
Stéphane Nicoll
2025-12-10 10:24:08 +01:00
2 changed files with 12 additions and 1 deletions
@@ -52,7 +52,7 @@ public class RabbitHealthIndicator extends AbstractHealthIndicator {
private @Nullable String getVersion() {
return this.rabbitTemplate.execute((channel) -> {
Object version = channel.getConnection().getServerProperties().get("version");
Object version = channel.getConnection().getServerProperties().getOrDefault("version", "unknown");
Assert.state(version != null, "'version' must not be null");
return version.toString();
});
@@ -70,6 +70,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();