Skip to content

Commit 41101f7

Browse files
committed
Merge pull request #20356 from bmscomp
* pr/20356: Polish "Improve details of neo4h health indicator" Improve details of neo4h health indicator Closes gh-20356
2 parents 89e5c28 + 51c2922 commit 41101f7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicator.java

Lines changed: 4 additions & 3 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.
@@ -40,7 +40,8 @@ public class Neo4jHealthIndicator extends AbstractHealthIndicator {
4040
/**
4141
* The Cypher statement used to verify Neo4j is up.
4242
*/
43-
static final String CYPHER = "match (n) return count(n) as nodes";
43+
static final String CYPHER = "CALL dbms.components() YIELD versions, edition"
44+
+ " UNWIND versions as version return version, edition";
4445

4546
private final SessionFactory sessionFactory;
4647

@@ -69,7 +70,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
6970
*/
7071
protected void extractResult(Session session, Health.Builder builder) throws Exception {
7172
Result result = session.query(CYPHER, Collections.emptyMap());
72-
builder.up().withDetail("nodes", result.queryResults().iterator().next().get("nodes"));
73+
builder.up().withDetails(result.queryResults().iterator().next());
7374
}
7475

7576
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/neo4j/Neo4jHealthIndicatorTests.java

Lines changed: 9 additions & 5 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.
@@ -61,17 +61,21 @@ void before() {
6161
void neo4jUp() {
6262
Result result = mock(Result.class);
6363
given(this.session.query(Neo4jHealthIndicator.CYPHER, Collections.emptyMap())).willReturn(result);
64-
int nodeCount = 500;
6564
Map<String, Object> expectedCypherDetails = new HashMap<>();
66-
expectedCypherDetails.put("nodes", nodeCount);
65+
String edition = "community";
66+
String version = "4.0.0";
67+
expectedCypherDetails.put("edition", edition);
68+
expectedCypherDetails.put("version", version);
6769
List<Map<String, Object>> queryResults = new ArrayList<>();
6870
queryResults.add(expectedCypherDetails);
6971
given(result.queryResults()).willReturn(queryResults);
7072
Health health = this.neo4jHealthIndicator.health();
7173
assertThat(health.getStatus()).isEqualTo(Status.UP);
7274
Map<String, Object> details = health.getDetails();
73-
int nodeCountFromDetails = (int) details.get("nodes");
74-
assertThat(nodeCountFromDetails).isEqualTo(nodeCount);
75+
String editionFromDetails = details.get("edition").toString();
76+
String versionFromDetails = details.get("version").toString();
77+
assertThat(editionFromDetails).isEqualTo(edition);
78+
assertThat(versionFromDetails).isEqualTo(version);
7579
}
7680

7781
@Test

0 commit comments

Comments
 (0)