|
18 | 18 |
|
19 | 19 | import com.hazelcast.core.HazelcastException;
|
20 | 20 | 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; |
23 | 22 | import org.junit.jupiter.api.Test;
|
24 | 23 |
|
25 | 24 | import org.springframework.boot.actuate.health.Health;
|
|
32 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
33 | 32 | import static org.mockito.ArgumentMatchers.any;
|
34 | 33 | import static org.mockito.BDDMockito.given;
|
| 34 | +import static org.mockito.BDDMockito.then; |
35 | 35 | import static org.mockito.Mockito.mock;
|
36 | 36 |
|
37 | 37 | /**
|
@@ -85,25 +85,31 @@ void hazelcastShutdown() {
|
85 | 85 | }
|
86 | 86 |
|
87 | 87 | @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(); |
99 | 94 | }
|
100 | 95 |
|
101 | 96 | @Test
|
102 | 97 | void hazelcastDown() {
|
103 |
| - HazelcastInstance hazelcast = mock(HazelcastInstance.class); |
| 98 | + HazelcastInstance hazelcast = mockHazelcastInstance(true); |
104 | 99 | given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException());
|
105 | 100 | Health health = new HazelcastHealthIndicator(hazelcast).health();
|
106 | 101 | 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; |
107 | 113 | }
|
108 | 114 |
|
109 | 115 | }
|
0 commit comments