-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jorge Aguilera <jagedn@gmail.com>
- Loading branch information
Showing
6 changed files
with
413 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
plugins/nf-nomad/src/test/nextflow/nomad/NomadConfigSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.nomad | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* Unit test for Nomad Config | ||
* | ||
* @author : Jorge Aguilera <jagedn@gmail.com> | ||
*/ | ||
class NomadConfigSpec extends Specification { | ||
|
||
void "should create a default config"() { | ||
given: | ||
def config = new NomadConfig() | ||
|
||
expect: | ||
config.jobOpts | ||
config.clientOpts | ||
} | ||
|
||
void "should use localhost as default address"() { | ||
given: | ||
def config = new NomadConfig([:]) | ||
|
||
expect: | ||
config.clientOpts.address == "http://127.0.0.1:4646/v1" | ||
} | ||
|
||
void "should use address if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
client: [address: "http://nomad"] | ||
]) | ||
|
||
expect: | ||
config.clientOpts.address == "http://nomad/v1" | ||
} | ||
|
||
void "should normalize address if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
client: [address: "http://nomad/"] | ||
]) | ||
|
||
expect: | ||
config.clientOpts.address == "http://nomad/v1" | ||
} | ||
|
||
void "should use token if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
client: [token: "theToken"] | ||
]) | ||
|
||
expect: | ||
config.clientOpts.token == "theToken" | ||
} | ||
|
||
void "should use an empty list if no datacenters is provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
jobs: [:] | ||
]) | ||
|
||
expect: | ||
!config.jobOpts.datacenters.size() | ||
} | ||
|
||
void "should use datacenters #dc with size #size if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
jobs: [datacenters: dc] | ||
]) | ||
|
||
expect: | ||
config.jobOpts.datacenters.size() == size | ||
|
||
where: | ||
dc | size | ||
[] | 0 | ||
"dc1" | 1 | ||
['dc1'] | 1 | ||
"dc1,dc2" | 2 | ||
['dc1', 'dc2'] | 2 | ||
['dc1', 'dc1'] | 1 | ||
} | ||
|
||
void "should use region if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
jobs: [region: "theRegion"] | ||
]) | ||
|
||
expect: | ||
config.jobOpts.region == "theRegion" | ||
} | ||
|
||
void "should use namespace if provided"() { | ||
given: | ||
def config = new NomadConfig([ | ||
jobs: [namespace: "namespace"] | ||
]) | ||
|
||
expect: | ||
config.jobOpts.namespace == "namespace" | ||
} | ||
} |
190 changes: 190 additions & 0 deletions
190
plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nextflow.nomad.executor | ||
|
||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
import nextflow.nomad.NomadConfig | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import spock.lang.Specification | ||
|
||
/** | ||
* Unit test for Nomad Service | ||
* | ||
* Validate requests using a Mock WebServer | ||
* | ||
* @author : Jorge Aguilera <jagedn@gmail.com> | ||
*/ | ||
class NomadServiceSpec extends Specification{ | ||
|
||
MockWebServer mockWebServer | ||
|
||
def setup() { | ||
mockWebServer = new MockWebServer() | ||
mockWebServer.start() | ||
} | ||
|
||
def cleanup() { | ||
mockWebServer.shutdown() | ||
} | ||
|
||
void "submit a task"(){ | ||
given: | ||
def config = new NomadConfig( | ||
client:[ | ||
address : "http://${mockWebServer.hostName}:${mockWebServer.port}" | ||
] | ||
) | ||
def service = new NomadService(config) | ||
|
||
String id = "theId" | ||
String name = "theName" | ||
String image = "theImage" | ||
List<String> args = ["theCommand", "theArgs"] | ||
String workingDir = "theWorkingDir" | ||
Map<String, String>env = [test:"test"] | ||
|
||
mockWebServer.enqueue(new MockResponse() | ||
.setBody(JsonOutput.toJson(["EvalID":"test"]).toString()) | ||
.addHeader("Content-Type", "application/json")); | ||
when: | ||
|
||
def idJob = service.submitTask(id, name, image, args, workingDir,env) | ||
def recordedRequest = mockWebServer.takeRequest(); | ||
def body = new JsonSlurper().parseText(recordedRequest.body.readUtf8()) | ||
|
||
then: | ||
idJob | ||
|
||
and: | ||
recordedRequest.method == "POST" | ||
recordedRequest.path == "/v1/jobs" | ||
|
||
and: | ||
body.Job | ||
body.Job.ID == id | ||
body.Job.Name == name | ||
body.Job.Datacenters == [] | ||
body.Job.Type == "batch" | ||
body.Job.TaskGroups.size() == 1 | ||
body.Job.TaskGroups[0].Name == "group" | ||
body.Job.TaskGroups[0].Tasks.size() == 1 | ||
body.Job.TaskGroups[0].Tasks[0].Name == "nf-task" | ||
body.Job.TaskGroups[0].Tasks[0].Driver == "docker" | ||
body.Job.TaskGroups[0].Tasks[0].Config.image == image | ||
body.Job.TaskGroups[0].Tasks[0].Config.work_dir == workingDir | ||
body.Job.TaskGroups[0].Tasks[0].Config.command == args[0] | ||
body.Job.TaskGroups[0].Tasks[0].Config.args == args.drop(1) | ||
|
||
!body.Job.TaskGroups[0].Tasks[0].Config.mount | ||
} | ||
|
||
void "submit a task with docker volume"(){ | ||
given: | ||
def config = new NomadConfig( | ||
client:[ | ||
address : "http://${mockWebServer.hostName}:${mockWebServer.port}" | ||
], | ||
jobs:[ | ||
dockerVolume:'test' | ||
] | ||
) | ||
def service = new NomadService(config) | ||
|
||
String id = "theId" | ||
String name = "theName" | ||
String image = "theImage" | ||
List<String> args = ["theCommand", "theArgs"] | ||
String workingDir = "a/b/c" | ||
Map<String, String>env = [test:"test"] | ||
|
||
mockWebServer.enqueue(new MockResponse() | ||
.setBody(JsonOutput.toJson(["EvalID":"test"]).toString()) | ||
.addHeader("Content-Type", "application/json")); | ||
when: | ||
|
||
def idJob = service.submitTask(id, name, image, args, workingDir,env) | ||
def recordedRequest = mockWebServer.takeRequest(); | ||
def body = new JsonSlurper().parseText(recordedRequest.body.readUtf8()) | ||
|
||
then: | ||
idJob | ||
|
||
and: | ||
recordedRequest.method == "POST" | ||
recordedRequest.path == "/v1/jobs" | ||
|
||
and: | ||
body.Job | ||
body.Job.ID == id | ||
body.Job.Name == name | ||
body.Job.Datacenters == [] | ||
body.Job.Type == "batch" | ||
body.Job.TaskGroups.size() == 1 | ||
body.Job.TaskGroups[0].Name == "group" | ||
body.Job.TaskGroups[0].Tasks.size() == 1 | ||
body.Job.TaskGroups[0].Tasks[0].Name == "nf-task" | ||
body.Job.TaskGroups[0].Tasks[0].Driver == "docker" | ||
body.Job.TaskGroups[0].Tasks[0].Config.image == image | ||
body.Job.TaskGroups[0].Tasks[0].Config.work_dir == workingDir | ||
body.Job.TaskGroups[0].Tasks[0].Config.command == args[0] | ||
body.Job.TaskGroups[0].Tasks[0].Config.args == args.drop(1) | ||
|
||
body.Job.TaskGroups[0].Tasks[0].Config.mount == [type:"volume", target:"a", source:"test", readonly:false] | ||
} | ||
|
||
void "should check the state"(){ | ||
given: | ||
def config = new NomadConfig( | ||
client:[ | ||
address : "http://${mockWebServer.hostName}:${mockWebServer.port}" | ||
] | ||
) | ||
def service = new NomadService(config) | ||
|
||
when: | ||
mockWebServer.enqueue(new MockResponse() | ||
.addHeader("Content-Type", "application/json")); | ||
|
||
def state = service.state("theId") | ||
def recordedRequest = mockWebServer.takeRequest(); | ||
|
||
then: | ||
recordedRequest.method == "GET" | ||
recordedRequest.path == "/v1/job/theId/summary" | ||
|
||
and: | ||
state == "Unknown" | ||
|
||
when: | ||
mockWebServer.enqueue(new MockResponse() | ||
.setBody(JsonOutput.toJson(["JobID":"test","Summary":[ | ||
test:[Starting:1] | ||
]]).toString()) | ||
.addHeader("Content-Type", "application/json")); | ||
|
||
state = service.state("theId") | ||
recordedRequest = mockWebServer.takeRequest(); | ||
|
||
then: | ||
recordedRequest.method == "GET" | ||
recordedRequest.path == "/v1/job/theId/summary" | ||
|
||
and: | ||
state == "Starting" | ||
|
||
} | ||
} |
Oops, something went wrong.