Add support for Hazelcast
This commit upgrades to Hazelcast 4.0.3, yet keeping compatibility with Hazelcast 3.x. Closes gh-20856 Closes gh-23475
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.actuate.hazelcast;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
|
||||
@@ -54,14 +53,14 @@ public class HazelcastHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private String extractUuid() {
|
||||
try {
|
||||
return this.hazelcast.getLocalEndpoint().getUuid();
|
||||
return this.hazelcast.getLocalEndpoint().getUuid().toString();
|
||||
}
|
||||
catch (NoSuchMethodError ex) {
|
||||
// Hazelcast 4
|
||||
// Hazelcast 3
|
||||
Method endpointAccessor = ReflectionUtils.findMethod(HazelcastInstance.class, "getLocalEndpoint");
|
||||
Object endpoint = ReflectionUtils.invokeMethod(endpointAccessor, this.hazelcast);
|
||||
Method uuidAccessor = ReflectionUtils.findMethod(endpoint.getClass(), "getUuid");
|
||||
return ((UUID) ReflectionUtils.invokeMethod(uuidAccessor, endpoint)).toString();
|
||||
return (String) ReflectionUtils.invokeMethod(uuidAccessor, endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,24 +35,24 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link HazelcastHealthIndicator} with Hazelcast 4.
|
||||
* Tests for {@link HazelcastHealthIndicator} with Hazelcast 3.
|
||||
*
|
||||
* @author Dmytro Nosan
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ClassPathExclusions("hazelcast*.jar")
|
||||
@ClassPathOverrides("com.hazelcast:hazelcast:4.0")
|
||||
class Hazelcast4HazelcastHealthIndicatorTests {
|
||||
@ClassPathOverrides("com.hazelcast:hazelcast:3.12.8")
|
||||
class Hazelcast3HazelcastHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
void hazelcastUp() throws IOException {
|
||||
HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast-4.xml"))
|
||||
HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast-3.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-4");
|
||||
"actuator-hazelcast-3");
|
||||
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
|
||||
}
|
||||
finally {
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.actuate.metrics.cache;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import com.hazelcast.core.IMap;
|
||||
import com.hazelcast.map.IMap;
|
||||
import com.hazelcast.spring.cache.HazelcastCache;
|
||||
import io.micrometer.core.instrument.binder.MeterBinder;
|
||||
import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.hazelcast.com/schema/config
|
||||
http://www.hazelcast.com/schema/config/hazelcast-config-4.0.xsd">
|
||||
<instance-name>actuator-hazelcast-4</instance-name>
|
||||
http://www.hazelcast.com/schema/config/hazelcast-config-3.12.xsd">
|
||||
<instance-name>actuator-hazelcast-3</instance-name>
|
||||
<map name="defaultCache"/>
|
||||
<network>
|
||||
<join>
|
||||
@@ -1,7 +1,7 @@
|
||||
<hazelcast
|
||||
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.12.xsd"
|
||||
xmlns="http://www.hazelcast.com/schema/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.hazelcast.com/schema/config
|
||||
http://www.hazelcast.com/schema/config/hazelcast-config-4.0.xsd">
|
||||
<instance-name>actuator-hazelcast</instance-name>
|
||||
<map name="defaultCache" />
|
||||
<network>
|
||||
|
||||
Reference in New Issue
Block a user