Commit b09d5d27 authored by Said BOUDJELDA's avatar Said BOUDJELDA Committed by Stephane Nicoll

Improve details of neo4h health indicator

This commit changes the neo4j health indicator to provide the version
and edition of the neo4j database.

See gh-20356
parent 89e5c285
......@@ -40,7 +40,8 @@ public class Neo4jHealthIndicator extends AbstractHealthIndicator {
/**
* The Cypher statement used to verify Neo4j is up.
*/
static final String CYPHER = "match (n) return count(n) as nodes";
static final String CYPHER = "CALL dbms.components() YIELD versions, edition"
+ " UNWIND versions as version return version, edition";
private final SessionFactory sessionFactory;
......@@ -69,7 +70,7 @@ public class Neo4jHealthIndicator extends AbstractHealthIndicator {
*/
protected void extractResult(Session session, Health.Builder builder) throws Exception {
Result result = session.query(CYPHER, Collections.emptyMap());
builder.up().withDetail("nodes", result.queryResults().iterator().next().get("nodes"));
builder.up().withDetails(result.queryResults().iterator().next());
}
}
......@@ -61,17 +61,21 @@ class Neo4jHealthIndicatorTests {
void neo4jUp() {
Result result = mock(Result.class);
given(this.session.query(Neo4jHealthIndicator.CYPHER, Collections.emptyMap())).willReturn(result);
int nodeCount = 500;
Map<String, Object> expectedCypherDetails = new HashMap<>();
expectedCypherDetails.put("nodes", nodeCount);
String edition = "community";
String version = "4.0.0";
expectedCypherDetails.put("edition", edition);
expectedCypherDetails.put("version", version);
List<Map<String, Object>> queryResults = new ArrayList<>();
queryResults.add(expectedCypherDetails);
given(result.queryResults()).willReturn(queryResults);
Health health = this.neo4jHealthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
Map<String, Object> details = health.getDetails();
int nodeCountFromDetails = (int) details.get("nodes");
assertThat(nodeCountFromDetails).isEqualTo(nodeCount);
String editionFromDetails = details.get("edition").toString();
String versionFromDetails = details.get("version").toString();
assertThat(editionFromDetails).isEqualTo(edition);
assertThat(versionFromDetails).isEqualTo(version);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment