1
+ import ch.kk7.gradle.spawn.KillTask
2
+ import ch.kk7.gradle.spawn.SpawnTask
3
+
1
4
apply plugin : ' ch.kk7.spawn'
2
5
3
6
description = ' Okapi - Neo4j IO test utils'
@@ -16,50 +19,45 @@ dependencies {
16
19
servicesCompile group : ' org.neo4j.test' , name : ' neo4j-harness-enterprise' , version : ver. neo4j. harness
17
20
}
18
21
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
+ }
38
57
}
39
58
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' )
63
61
64
62
tasks. test. dependsOn(tasks. neo4jStart)
65
63
tasks. test. finalizedBy(tasks. neo4jStop)
0 commit comments