Skip to content

Commit 375b0b8

Browse files
committed
Polish contribution
See gh-46877
1 parent 2496202 commit 375b0b8

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/hazelcast/HazelcastHealthIndicatorTests.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import com.hazelcast.core.HazelcastException;
2020
import com.hazelcast.core.HazelcastInstance;
21-
import com.hazelcast.instance.impl.HazelcastInstanceProxy;
22-
import com.hazelcast.instance.impl.OutOfMemoryHandlerHelper;
21+
import com.hazelcast.core.LifecycleService;
2322
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.boot.actuate.health.Health;
@@ -32,6 +31,7 @@
3231
import static org.assertj.core.api.Assertions.assertThat;
3332
import static org.mockito.ArgumentMatchers.any;
3433
import static org.mockito.BDDMockito.given;
34+
import static org.mockito.BDDMockito.then;
3535
import static org.mockito.Mockito.mock;
3636

3737
/**
@@ -85,25 +85,31 @@ void hazelcastShutdown() {
8585
}
8686

8787
@Test
88-
void hazelcastOOMShutdown() {
89-
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class))
90-
.withPropertyValues("spring.hazelcast.config=hazelcast.xml")
91-
.run((context) -> {
92-
HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class);
93-
HazelcastInstance original = ((HazelcastInstanceProxy) hazelcast).getOriginal();
94-
OutOfMemoryHandlerHelper.tryCloseConnections(original);
95-
OutOfMemoryHandlerHelper.tryShutdown(original);
96-
Health health = new HazelcastHealthIndicator(hazelcast).health();
97-
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
98-
});
88+
void hazelcastLifecycleNotRunning() {
89+
HazelcastInstance hazelcast = mockHazelcastInstance(false);
90+
Health health = new HazelcastHealthIndicator(hazelcast).health();
91+
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
92+
then(hazelcast).should().getLifecycleService();
93+
then(hazelcast).shouldHaveNoMoreInteractions();
9994
}
10095

10196
@Test
10297
void hazelcastDown() {
103-
HazelcastInstance hazelcast = mock(HazelcastInstance.class);
98+
HazelcastInstance hazelcast = mockHazelcastInstance(true);
10499
given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException());
105100
Health health = new HazelcastHealthIndicator(hazelcast).health();
106101
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
102+
then(hazelcast).should().getLifecycleService();
103+
then(hazelcast).should().executeTransaction(any());
104+
then(hazelcast).shouldHaveNoMoreInteractions();
105+
}
106+
107+
private static HazelcastInstance mockHazelcastInstance(boolean isRunning) {
108+
LifecycleService lifecycleService = mock(LifecycleService.class);
109+
given(lifecycleService.isRunning()).willReturn(isRunning);
110+
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
111+
given(hazelcastInstance.getLifecycleService()).willReturn(lifecycleService);
112+
return hazelcastInstance;
107113
}
108114

109115
}

0 commit comments

Comments
 (0)