Skip to content

Commit 4c863c5

Browse files
youngledosnicoll
authored andcommitted
Use 'unknown' when RabbitMQ version is missing
See gh-48484 Signed-off-by: Huang Xiao <[email protected]>
1 parent bf4092b commit 4c863c5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/amqp/RabbitHealthIndicator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
4545
}
4646

4747
private String getVersion() {
48-
return this.rabbitTemplate
49-
.execute((channel) -> channel.getConnection().getServerProperties().get("version").toString());
48+
return this.rabbitTemplate.execute((channel) -> channel.getConnection()
49+
.getServerProperties()
50+
.getOrDefault("version", "unknown")
51+
.toString());
5052
}
5153

5254
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/amqp/RabbitHealthIndicatorTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ void healthWhenConnectionFailsShouldReturnDown() {
7575
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
7676
}
7777

78+
@Test
79+
void healthWhenVersionIsMissingShouldReturnUpWithUnknownVersion() {
80+
givenTemplateExecutionWillInvokeCallback();
81+
Connection connection = mock(Connection.class);
82+
given(this.channel.getConnection()).willReturn(connection);
83+
given(connection.getServerProperties()).willReturn(Collections.emptyMap());
84+
Health health = new RabbitHealthIndicator(this.rabbitTemplate).health();
85+
assertThat(health.getStatus()).isEqualTo(Status.UP);
86+
assertThat(health.getDetails()).containsEntry("version", "unknown");
87+
}
88+
7889
private void givenTemplateExecutionWillInvokeCallback() {
7990
given(this.rabbitTemplate.execute(any())).willAnswer((invocation) -> {
8091
ChannelCallback<?> callback = invocation.getArgument(0);

0 commit comments

Comments
 (0)