Skip to content

Commit 8f4c6ab

Browse files
authored
Merge pull request #871 from tobias-johansson/neo4j-launcher-improvements
Rewrite neo4j launcher tasks
2 parents 67dbb55 + 541e28b commit 8f4c6ab

File tree

4 files changed

+128
-59
lines changed

4 files changed

+128
-59
lines changed
Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import ch.kk7.gradle.spawn.KillTask
2+
import ch.kk7.gradle.spawn.SpawnTask
3+
14
apply plugin: 'ch.kk7.spawn'
25

36
description = 'Okapi - Neo4j IO test utils'
@@ -16,50 +19,45 @@ dependencies {
1619
servicesCompile group: 'org.neo4j.test', name: 'neo4j-harness-enterprise', version: ver.neo4j.harness
1720
}
1821

19-
20-
def neo4jStartedMarker() { 'neo4j started' }
21-
22-
def neo4jCommandLine(int instances) {
23-
def java = System.getProperty('java.home') + '/bin/java'
24-
def classpath = sourceSets.services.runtimeClasspath.collect { it.absolutePath }.join(':')
25-
def main = 'org.opencypher.testing.services.Neo4j'
26-
return [java, '-cp', classpath, main, neo4jStartedMarker(), instances.toString()]
27-
}
28-
29-
task neo4jStart(type: ch.kk7.gradle.spawn.SpawnTask) {
30-
description "Launches a Neo4j instance in a separate JVM."
31-
group "services"
32-
33-
dependsOn sourceSets.services.runtimeClasspath
34-
35-
commandLine = neo4jCommandLine(1)
36-
waitFor = neo4jStartedMarker()
37-
doLast { println getStdoutFile().text }
22+
def neo4jLauncher(String launcher, int instances, String starter, String stopper, String status) {
23+
task(starter, type: SpawnTask) {
24+
description "Launches $launcher (x$instances) in a separate JVM"
25+
group "services"
26+
27+
dependsOn project.sourceSets.services.runtimeClasspath
28+
29+
String java = System.getProperty('java.home') + '/bin/java'
30+
String classpath = project.sourceSets.services.runtimeClasspath.collect { it.absolutePath }.join(':')
31+
String main = "org.opencypher.testing.services.$launcher"
32+
String marker = 'neo4j started'
33+
34+
commandLine = [java, '-cp', classpath, main, marker, instances.toString()]
35+
waitFor = marker
36+
doLast { println getStdoutFile().text }
37+
}
38+
39+
task(stopper, type: KillTask) {
40+
description "Stops $launcher"
41+
group "services"
42+
kills tasks[starter]
43+
}
44+
45+
task(status) {
46+
description "Prints status on $launcher"
47+
group "services"
48+
doLast {
49+
def res = [pid: 'unknown', status: 'unknown']
50+
if (tasks[starter].pidFile.exists()) {
51+
res.pid = tasks[starter].pidFile.text
52+
res.status = tasks[starter].kill('-0', res.pid) ? 'running' : 'stopped'
53+
}
54+
println res
55+
}
56+
}
3857
}
3958

40-
task neo4jStop(type: ch.kk7.gradle.spawn.KillTask) {
41-
description "Stops Neo4j instances started by 'neo4jStart'."
42-
group "services"
43-
kills tasks.neo4jStart
44-
}
45-
46-
47-
task neo4jStartTwoInstances(type: ch.kk7.gradle.spawn.SpawnTask) {
48-
description "Launches two Neo4j instances in a separate JVM (used for examples)."
49-
group "services"
50-
51-
dependsOn sourceSets.services.runtimeClasspath
52-
53-
commandLine = neo4jCommandLine(2)
54-
waitFor = neo4jStartedMarker()
55-
doLast { println getStdoutFile().text }
56-
}
57-
58-
task neo4jStopTwoInstances(type: ch.kk7.gradle.spawn.KillTask) {
59-
description "Stops Neo4j instances started by 'neo4jStartTwoInstances'."
60-
group "services"
61-
kills tasks.neo4jStartTwoInstances
62-
}
59+
neo4jLauncher('Neo4jEnterprise', 1, 'neo4jStart', 'neo4jStop', 'neo4jStatus')
60+
neo4jLauncher('Neo4jCommunity', 2, 'neo4jStartTwoInstances', 'neo4jStopTwoInstances', 'neo4jStatusTwoInstances')
6361

6462
tasks.test.dependsOn(tasks.neo4jStart)
6563
tasks.test.finalizedBy(tasks.neo4jStop)

okapi-neo4j-io-testing/src/services/scala/org/opencypher/testing/services/Neo4j.scala renamed to okapi-neo4j-io-testing/src/services/scala/org/opencypher/testing/services/Neo4jCommunity.scala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,9 @@
2626
*/
2727
package org.opencypher.testing.services
2828

29-
import org.neo4j.harness.EnterpriseTestServerBuilders
29+
import org.neo4j.harness.{TestServerBuilder, TestServerBuilders}
3030

31-
object Neo4j extends App {
32-
val Array(marker, instances) = args
33-
34-
Range(0, instances.toInt).foreach { i =>
35-
val bolt = 7687 + i
36-
val http = 7474 + i
37-
val server = EnterpriseTestServerBuilders.newInProcessBuilder()
38-
.withConfig("dbms.connector.bolt.listen_address", s"127.0.0.1:$bolt")
39-
.withConfig("dbms.connector.http.listen_address", s"127.0.0.1:$http")
40-
.newServer()
41-
42-
println(s"bolt: ${server.boltURI()}")
43-
println(s"http: ${server.httpURI()}")
44-
}
45-
46-
println(marker)
4731

32+
object Neo4jCommunity extends Neo4jLauncher {
33+
override def builder: TestServerBuilder = TestServerBuilders.newInProcessBuilder()
4834
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2016-2019 "Neo4j Sweden, AB" [https://neo4j.com]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Attribution Notice under the terms of the Apache License 2.0
17+
*
18+
* This work was created by the collective efforts of the openCypher community.
19+
* Without limiting the terms of Section 6, any Derivative Work that is not
20+
* approved by the public consensus process of the openCypher Implementers Group
21+
* should not be described as “Cypher” (and Cypher® is a registered trademark of
22+
* Neo4j Inc.) or as "openCypher". Extensions by implementers or prototypes or
23+
* proposals for change that have been documented or implemented should only be
24+
* described as "implementation extensions to Cypher" or as "proposed changes to
25+
* Cypher that are not yet approved by the openCypher community".
26+
*/
27+
package org.opencypher.testing.services
28+
29+
import org.neo4j.harness.{EnterpriseTestServerBuilders, TestServerBuilder}
30+
31+
object Neo4jEnterprise extends Neo4jLauncher {
32+
override def builder: TestServerBuilder = EnterpriseTestServerBuilders.newInProcessBuilder()
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2016-2019 "Neo4j Sweden, AB" [https://neo4j.com]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Attribution Notice under the terms of the Apache License 2.0
17+
*
18+
* This work was created by the collective efforts of the openCypher community.
19+
* Without limiting the terms of Section 6, any Derivative Work that is not
20+
* approved by the public consensus process of the openCypher Implementers Group
21+
* should not be described as “Cypher” (and Cypher® is a registered trademark of
22+
* Neo4j Inc.) or as "openCypher". Extensions by implementers or prototypes or
23+
* proposals for change that have been documented or implemented should only be
24+
* described as "implementation extensions to Cypher" or as "proposed changes to
25+
* Cypher that are not yet approved by the openCypher community".
26+
*/
27+
package org.opencypher.testing.services
28+
29+
import org.neo4j.harness.TestServerBuilder
30+
31+
trait Neo4jLauncher {
32+
33+
def builder: TestServerBuilder
34+
35+
def main(args: Array[String]): Unit = {
36+
val Array(marker, instances) = args
37+
38+
Range(0, instances.toInt).foreach { i =>
39+
val bolt = 7687 + i
40+
val http = 7474 + i
41+
val server = builder
42+
.withConfig("dbms.connector.bolt.listen_address", s"127.0.0.1:$bolt")
43+
.withConfig("dbms.connector.http.listen_address", s"127.0.0.1:$http")
44+
.newServer()
45+
46+
println(s"bolt: ${server.boltURI()}")
47+
println(s"http: ${server.httpURI()}")
48+
}
49+
50+
println(marker)
51+
}
52+
}

0 commit comments

Comments
 (0)