Skip to content

Commit 5a51b58

Browse files
committed
Restore HazelcastHealthIndicatorTests
Restore `HazelcastHealthIndicatorTests` which was accidentally replaced with a version from 2.4.x. See gh-24337
1 parent d8a0509 commit 5a51b58

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,16 @@
1616

1717
package org.springframework.boot.actuate.hazelcast;
1818

19-
import com.hazelcast.core.Endpoint;
19+
import java.io.IOException;
20+
2021
import com.hazelcast.core.HazelcastException;
2122
import com.hazelcast.core.HazelcastInstance;
22-
import com.hazelcast.transaction.TransactionalTask;
2323
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.boot.actuate.health.Health;
2626
import org.springframework.boot.actuate.health.Status;
27+
import org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory;
28+
import org.springframework.core.io.ClassPathResource;
2729

2830
import static org.assertj.core.api.Assertions.assertThat;
2931
import static org.mockito.ArgumentMatchers.any;
@@ -38,28 +40,27 @@
3840
*/
3941
class HazelcastHealthIndicatorTests {
4042

41-
private final HazelcastInstance hazelcast = mock(HazelcastInstance.class);
42-
4343
@Test
44-
void hazelcastUp() {
45-
Endpoint endpoint = mock(Endpoint.class);
46-
given(this.hazelcast.getName()).willReturn("hz0-instance");
47-
given(this.hazelcast.getLocalEndpoint()).willReturn(endpoint);
48-
given(endpoint.getUuid()).willReturn("7581bb2f-879f-413f-b574-0071d7519eb0");
49-
given(this.hazelcast.executeTransaction(any())).willAnswer((invocation) -> {
50-
TransactionalTask<?> task = invocation.getArgument(0);
51-
return task.execute(null);
52-
});
53-
Health health = new HazelcastHealthIndicator(this.hazelcast).health();
54-
assertThat(health.getStatus()).isEqualTo(Status.UP);
55-
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "hz0-instance")
56-
.containsEntry("uuid", "7581bb2f-879f-413f-b574-0071d7519eb0");
44+
void hazelcastUp() throws IOException {
45+
HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast.xml"))
46+
.getHazelcastInstance();
47+
try {
48+
Health health = new HazelcastHealthIndicator(hazelcast).health();
49+
assertThat(health.getStatus()).isEqualTo(Status.UP);
50+
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name",
51+
"actuator-hazelcast");
52+
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
53+
}
54+
finally {
55+
hazelcast.shutdown();
56+
}
5757
}
5858

5959
@Test
6060
void hazelcastDown() {
61-
given(this.hazelcast.executeTransaction(any())).willReturn(new HazelcastException());
62-
Health health = new HazelcastHealthIndicator(this.hazelcast).health();
61+
HazelcastInstance hazelcast = mock(HazelcastInstance.class);
62+
given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException());
63+
Health health = new HazelcastHealthIndicator(hazelcast).health();
6364
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
6465
}
6566

0 commit comments

Comments
 (0)