Merge pull request #20356 from bmscomp
* pr/20356: Polish "Improve details of neo4h health indicator" Improve details of neo4h health indicator Closes gh-20356
This commit is contained in:
commit
41101f7ad4
|
@ -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.
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue