Skip to content

Commit e9771ff

Browse files
committed
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
2 parents bf4092b + 26fc091 commit e9771ff

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
@@ -67,6 +67,17 @@ void healthWhenConnectionSucceedsShouldReturnUpWithVersion() {
6767
assertThat(health.getDetails()).containsEntry("version", "123");
6868
}
6969

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

0 commit comments

Comments
 (0)