Skip to content

Commit 55ae5be

Browse files
committed
Revert "Restore HazelcastHealthIndicatorTests"
This reverts commit 5a51b58.
1 parent 5a51b58 commit 55ae5be

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2019 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,16 +16,14 @@
1616

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

19-
import java.io.IOException;
20-
19+
import com.hazelcast.core.Endpoint;
2120
import com.hazelcast.core.HazelcastException;
2221
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;
2927

3028
import static org.assertj.core.api.Assertions.assertThat;
3129
import static org.mockito.ArgumentMatchers.any;
@@ -40,27 +38,28 @@
4038
*/
4139
class HazelcastHealthIndicatorTests {
4240

41+
private final HazelcastInstance hazelcast = mock(HazelcastInstance.class);
42+
4343
@Test
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-
}
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");
5757
}
5858

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

0 commit comments

Comments
 (0)