Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {

private @Nullable String getVersion() {
return this.rabbitTemplate.execute((channel) -> {
Object version = channel.getConnection().getServerProperties().get("version");
Assert.state(version != null, "'version' must not be null");
Object version = channel.getConnection().getServerProperties().getOrDefault("version", "unknown");
return version.toString();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ void healthWhenConnectionFailsShouldReturnDown() {
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}

@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");
}

private void givenTemplateExecutionWillInvokeCallback() {
given(this.rabbitTemplate.execute(any())).willAnswer((invocation) -> {
ChannelCallback<?> callback = invocation.getArgument(0);
Expand Down
Loading