Skip to content

Commit d6b7303

Browse files
committed
Set the version to 'unknown' when "version" is missing.
Signed-off-by: Huang Xiao <[email protected]>
1 parent 7347d7e commit d6b7303

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +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");
56-
Assert.state(version != null, "'version' must not be null");
55+
Object version = channel.getConnection().getServerProperties().getOrDefault("version", "unknown");
5756
return version.toString();
5857
});
5958
}

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
@@ -78,6 +78,17 @@ void healthWhenConnectionFailsShouldReturnDown() {
7878
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
7979
}
8080

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

0 commit comments

Comments
 (0)