From 55ae5be84b4b06a512c92f6239223d01590928ee Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 5 Dec 2020 07:47:50 -0800 Subject: [PATCH] Revert "Restore HazelcastHealthIndicatorTests" This reverts commit 5a51b5853e42325cb323eab40350c20027a022d0. --- .../HazelcastHealthIndicatorTests.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicatorTests.java index ad911800527..c32d78418d8 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,14 @@ package org.springframework.boot.actuate.hazelcast; -import java.io.IOException; - +import com.hazelcast.core.Endpoint; import com.hazelcast.core.HazelcastException; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.transaction.TransactionalTask; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory; -import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -40,27 +38,28 @@ import static org.mockito.Mockito.mock; */ class HazelcastHealthIndicatorTests { + private final HazelcastInstance hazelcast = mock(HazelcastInstance.class); + @Test - void hazelcastUp() throws IOException { - HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast.xml")) - .getHazelcastInstance(); - try { - Health health = new HazelcastHealthIndicator(hazelcast).health(); - assertThat(health.getStatus()).isEqualTo(Status.UP); - assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", - "actuator-hazelcast"); - assertThat(health.getDetails().get("uuid")).asString().isNotEmpty(); - } - finally { - hazelcast.shutdown(); - } + void hazelcastUp() { + Endpoint endpoint = mock(Endpoint.class); + given(this.hazelcast.getName()).willReturn("hz0-instance"); + given(this.hazelcast.getLocalEndpoint()).willReturn(endpoint); + given(endpoint.getUuid()).willReturn("7581bb2f-879f-413f-b574-0071d7519eb0"); + given(this.hazelcast.executeTransaction(any())).willAnswer((invocation) -> { + TransactionalTask task = invocation.getArgument(0); + return task.execute(null); + }); + Health health = new HazelcastHealthIndicator(this.hazelcast).health(); + assertThat(health.getStatus()).isEqualTo(Status.UP); + assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "hz0-instance") + .containsEntry("uuid", "7581bb2f-879f-413f-b574-0071d7519eb0"); } @Test void hazelcastDown() { - HazelcastInstance hazelcast = mock(HazelcastInstance.class); - given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException()); - Health health = new HazelcastHealthIndicator(hazelcast).health(); + given(this.hazelcast.executeTransaction(any())).willReturn(new HazelcastException()); + Health health = new HazelcastHealthIndicator(this.hazelcast).health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); }