diff --git a/plugins/nf-ga4gh/src/main/nextflow/ga4gh/tes/executor/TesTaskHandler.groovy b/plugins/nf-ga4gh/src/main/nextflow/ga4gh/tes/executor/TesTaskHandler.groovy index eac5cc1836..eaae5e1654 100644 --- a/plugins/nf-ga4gh/src/main/nextflow/ga4gh/tes/executor/TesTaskHandler.groovy +++ b/plugins/nf-ga4gh/src/main/nextflow/ga4gh/tes/executor/TesTaskHandler.groovy @@ -17,6 +17,7 @@ package nextflow.ga4gh.tes.executor import nextflow.ga4gh.tes.client.model.TesFileType +import nextflow.processor.TaskBean import static nextflow.processor.TaskStatus.COMPLETED import static nextflow.processor.TaskStatus.RUNNING @@ -53,7 +54,7 @@ class TesTaskHandler extends TaskHandler { final List STARTED_STATUSES = [TesState.INITIALIZING, TesState.RUNNING, TesState.PAUSED] + COMPLETE_STATUSES - final TesExecutor executor + private TesExecutor executor private final Path exitFile @@ -75,6 +76,9 @@ class TesTaskHandler extends TaskHandler { private String requestId + /** only for testing purpose -- do not use */ + protected TesTaskHandler() {} + TesTaskHandler(TaskRun task, TesExecutor executor) { super(task) this.executor = executor @@ -90,6 +94,8 @@ class TesTaskHandler extends TaskHandler { this.traceFile = task.workDir.resolve(TaskRun.CMD_TRACE) } + protected String getRequestId() { requestId } + @Override boolean checkIfRunning() { @@ -149,7 +155,7 @@ class TesTaskHandler extends TaskHandler { // create task wrapper String remoteBinDir = executor.getRemoteBinDir() - final bash = new TesBashBuilder(task, remoteBinDir) + final bash = newTesBashBuilder(task, remoteBinDir) bash.build() final body = newTesTask() @@ -160,7 +166,11 @@ class TesTaskHandler extends TaskHandler { status = TaskStatus.SUBMITTED } - protected final TesTask newTesTask() { + protected TesBashBuilder newTesBashBuilder(TaskRun task, String remoteBinDir) { + return new TesBashBuilder(task, remoteBinDir) + } + + protected TesTask newTesTask() { // the cmd list to launch it def job = new ArrayList(BashWrapperBuilder.BASH) << wrapperFile.getName() List cmd = ['/bin/bash','-c', job.join(' ') + " &> $TaskRun.CMD_LOG" ] diff --git a/plugins/nf-ga4gh/src/test/nextflow/ga4gh/tes/executor/TesTaskHandlerTest.groovy b/plugins/nf-ga4gh/src/test/nextflow/ga4gh/tes/executor/TesTaskHandlerTest.groovy index b6c278a547..6aeb1b665b 100644 --- a/plugins/nf-ga4gh/src/test/nextflow/ga4gh/tes/executor/TesTaskHandlerTest.groovy +++ b/plugins/nf-ga4gh/src/test/nextflow/ga4gh/tes/executor/TesTaskHandlerTest.groovy @@ -16,6 +16,12 @@ package nextflow.ga4gh.tes.executor +import nextflow.ga4gh.tes.client.api.TaskServiceApi +import nextflow.ga4gh.tes.client.model.TesCreateTaskResponse +import nextflow.ga4gh.tes.client.model.TesTask +import nextflow.processor.TaskStatus + +import java.nio.file.Path import java.nio.file.Paths import nextflow.processor.TaskConfig @@ -49,5 +55,33 @@ class TesTaskHandlerTest extends Specification { } + def 'should submit job' () { + + given: + def executor = Mock(TesExecutor) + def task = Mock(TaskRun) + def bashBuilder = Mock(TesBashBuilder) + def client = Mock(TaskServiceApi) + def handler = Spy(TesTaskHandler) + handler.@client = client + handler.@executor = executor + handler.task = task + + def req = Mock(TesTask) + def resp = Mock(TesCreateTaskResponse) + + when: + handler.submit() + then: + 1 * executor.getRemoteBinDir() >> Path.of("/work/bin") + 1 * handler.newTesBashBuilder(task, "/work/bin") >> bashBuilder + 1 * bashBuilder.build() >> null + 1 * handler.newTesTask() >> req + 1 * client.createTask(req) >> resp + 1 * resp.getId() >> '12345' + + handler.status == TaskStatus.SUBMITTED + handler.requestId == '12345' + } }