diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 065f8d8..90c853a 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -7,7 +7,7 @@
com.github.harti2006
integration-tests
- 0.2-SNAPSHOT
+ 1.1-SNAPSHOT
1.8
@@ -82,6 +82,7 @@
${neo4j-server.password}
${neo4j-server.version}
true
+ 5
diff --git a/src/main/java/com/github/harti2006/neo4j/Neo4jServerMojoSupport.java b/src/main/java/com/github/harti2006/neo4j/Neo4jServerMojoSupport.java
index 6d94d02..e270952 100644
--- a/src/main/java/com/github/harti2006/neo4j/Neo4jServerMojoSupport.java
+++ b/src/main/java/com/github/harti2006/neo4j/Neo4jServerMojoSupport.java
@@ -66,6 +66,17 @@ public abstract class Neo4jServerMojoSupport extends AbstractMojo {
@Parameter(required = true, property = "neo4j-server.deleteDb", defaultValue = "false")
protected boolean deleteDb;
+ /**
+ * Makes this number of attempts to wait for server ready conditions when the Neo4j server is started
+ * in {@link StartNeo4jServerMojo}. After the start command, we check the server by connecting it via
+ * BOLT. If that doesn't work, we start making a connection attempt every second, until we connect it
+ * successfully or we reach a number of attempts equal to this parameter. The time spent this way can be
+ * configured and adapted to your particular situation, e.g., in some busy servers Neo4j can take over
+ * 1 min to start.
+ */
+ @Parameter(required = true, property = "neo4j-server.serverReadyAttempts", defaultValue = "10")
+ protected int serverReadyAttempts = 10;
+
protected Path getServerLocation() {
return Paths.get(directory, ARTIFACT_NAME + version);
}
diff --git a/src/main/java/com/github/harti2006/neo4j/StartNeo4jServerMojo.java b/src/main/java/com/github/harti2006/neo4j/StartNeo4jServerMojo.java
index ea7ff1f..28e1428 100644
--- a/src/main/java/com/github/harti2006/neo4j/StartNeo4jServerMojo.java
+++ b/src/main/java/com/github/harti2006/neo4j/StartNeo4jServerMojo.java
@@ -49,6 +49,9 @@
@Mojo(name = "start", defaultPhase = PRE_INTEGRATION_TEST)
public class StartNeo4jServerMojo extends Neo4jServerMojoSupport {
+ private static final int INITIAL_WAIT_MILLIS = 1500;
+ private static final int WAIT_MILLIS = 1000;
+
public void execute() throws MojoExecutionException {
installNeo4jServer();
configureNeo4jServer();
@@ -145,26 +148,30 @@ private void startNeo4jServer() throws MojoExecutionException {
}
}
+ /**
+ * @see Neo4jServerMojoSupport#serverReadyAttempts
+ */
private void checkServerReady() throws MojoExecutionException, InterruptedException {
// If the deleteDb parameter is true, at this point we have created a new server, which have the
// default
// password, and we're about to change this.
//
String pwd = deleteDb ? "neo4j" : password;
- int maxAttempts = 10;
- Thread.sleep(1500); // It takes some time anyway
+ Thread.sleep(INITIAL_WAIT_MILLIS); // It takes some time anyway
- for (int attempts = 1; attempts <= maxAttempts; attempts++) {
+ for (int attempts = 1; attempts <= serverReadyAttempts; attempts++) {
getLog().debug("Trying to connect Neo4j, attempt " + attempts);
- try (Driver driver = GraphDatabase.driver("bolt://127.0.0.1:" + boltPort,
- AuthTokens.basic("neo4j", pwd));) {
+ try (Driver ignored = GraphDatabase.driver("bolt://127.0.0.1:" + boltPort,
+ AuthTokens.basic("neo4j", pwd))) {
return;
- } catch (ServiceUnavailableException ex) {
- Thread.sleep(1000);
+ } catch (ServiceUnavailableException ignored) {
+ Thread.sleep(WAIT_MILLIS);
}
}
- throw new MojoExecutionException("Server doesn't result started after waiting for its boot");
+ throw new MojoExecutionException(
+ format("Server doesn't result started after waiting %sms for its boot",
+ INITIAL_WAIT_MILLIS + serverReadyAttempts * WAIT_MILLIS));
}
private void setNewPassword() {
@@ -174,7 +181,7 @@ private void setNewPassword() {
try (Driver driver = GraphDatabase.driver("bolt://127.0.0.1:" + boltPort,
AuthTokens.basic("neo4j", "neo4j"));
- Session session = driver.session();) {
+ Session session = driver.session()) {
session.run("CALL dbms.changePassword( '" + password + "' )");
}
}