File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
module/spring-boot-amqp/src
main/java/org/springframework/boot/amqp/health
test/java/org/springframework/boot/amqp/health Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments