Skip to content

Commit 72afdfd

Browse files
committed
Merge branch '3.5.x'
Closes gh-48487
2 parents 35d88a7 + 927232d commit 72afdfd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

module/spring-boot-amqp/src/main/java/org/springframework/boot/amqp/health/RabbitHealthIndicator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
5252

5353
private @Nullable String getVersion() {
5454
return this.rabbitTemplate.execute((channel) -> {
55-
Object version = channel.getConnection().getServerProperties().get("version");
55+
Object version = channel.getConnection().getServerProperties().getOrDefault("version", "unknown");
5656
Assert.state(version != null, "'version' must not be null");
5757
return version.toString();
5858
});

module/spring-boot-amqp/src/test/java/org/springframework/boot/amqp/health/RabbitHealthIndicatorTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ void healthWhenConnectionSucceedsShouldReturnUpWithVersion() {
7070
assertThat(health.getDetails()).containsEntry("version", "123");
7171
}
7272

73+
@Test
74+
void healthWhenVersionIsMissingShouldReturnUpWithUnknownVersion() {
75+
givenTemplateExecutionWillInvokeCallback();
76+
Connection connection = mock(Connection.class);
77+
given(this.channel.getConnection()).willReturn(connection);
78+
given(connection.getServerProperties()).willReturn(Collections.emptyMap());
79+
Health health = new RabbitHealthIndicator(this.rabbitTemplate).health();
80+
assertThat(health.getStatus()).isEqualTo(Status.UP);
81+
assertThat(health.getDetails()).containsEntry("version", "unknown");
82+
}
83+
7384
@Test
7485
void healthWhenConnectionFailsShouldReturnDown() {
7586
givenTemplateExecutionWillInvokeCallback();

0 commit comments

Comments
 (0)