|
| 1 | +package com.marklogic.gradle.task |
| 2 | + |
| 3 | +import com.marklogic.client.eval.EvalResult |
| 4 | +import com.marklogic.client.eval.EvalResultIterator |
| 5 | +import com.marklogic.client.io.DocumentMetadataHandle |
| 6 | +import com.marklogic.hub.HubConfig |
| 7 | +import org.gradle.testkit.runner.UnexpectedBuildFailure |
| 8 | +import org.gradle.testkit.runner.UnexpectedBuildSuccess |
| 9 | + |
| 10 | +import java.nio.file.Paths |
| 11 | + |
| 12 | +import static org.gradle.testkit.runner.TaskOutcome.FAILED |
| 13 | +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS |
| 14 | + |
| 15 | +class JobDeleteTaskTest extends BaseTest { |
| 16 | + private final int JOB_COUNT = 3 |
| 17 | + |
| 18 | + def setupSpec() { |
| 19 | + createGradleFiles() |
| 20 | + runTask('hubInit') |
| 21 | + runTask('mlUndeploy') |
| 22 | + println(runTask('mlDeploy', '-i').getOutput()) |
| 23 | + |
| 24 | + println(runTask('hubCreateHarmonizeFlow', '-PentityName=test-entity', '-PflowName=test-harmonize-flow', '-PdataFormat=xml', '-PpluginFormat=xqy').getOutput()) |
| 25 | + println(runTask('mlReLoadModules')) |
| 26 | + |
| 27 | + clearDatabases(HubConfig.DEFAULT_STAGING_NAME, HubConfig.DEFAULT_FINAL_NAME) |
| 28 | + DocumentMetadataHandle meta = new DocumentMetadataHandle(); |
| 29 | + meta.getCollections().add("test-entity"); |
| 30 | + installStagingDoc("/employee1.xml", meta, new File("src/test/resources/run-flow-test/employee1.xml").text) |
| 31 | + installStagingDoc("/employee2.xml", meta, new File("src/test/resources/run-flow-test/employee2.xml").text) |
| 32 | + installModule("/entities/my-new-entity/harmonize/my-new-harmonize-flow/content/content.xqy", "run-flow-test/content.xqy") |
| 33 | + |
| 34 | + } |
| 35 | + |
| 36 | + def setup() { |
| 37 | + propertiesFile.delete() |
| 38 | + createFullPropertiesFile() |
| 39 | + clearDatabases(HubConfig.DEFAULT_JOB_NAME, HubConfig.DEFAULT_TRACE_NAME) |
| 40 | + |
| 41 | + |
| 42 | + for (int i = 0; i < JOB_COUNT; i++) { |
| 43 | + println(runTask('hubRunFlow', '-PentityName=test-entity', '-PflowName=test-harmonize-flow', '-i')) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + def cleanupSpec() { |
| 48 | + runTask('mlUndeploy') |
| 49 | + } |
| 50 | + |
| 51 | + def getJobIds() { |
| 52 | + EvalResultIterator resultItr = runInDatabase("cts:values(cts:element-reference(xs:QName(\"jobId\")))", HubConfig.DEFAULT_JOB_NAME) |
| 53 | + if (resultItr == null || ! resultItr.hasNext()) { |
| 54 | + throw new Exception("Did not find any job IDs") |
| 55 | + } |
| 56 | + return resultItr |
| 57 | + } |
| 58 | + |
| 59 | + def "delete one job"() { |
| 60 | + when: |
| 61 | + EvalResultIterator resultItr = getJobIds() |
| 62 | + EvalResult res = resultItr.next() |
| 63 | + String jobId = res.getString() |
| 64 | + |
| 65 | + def result = runTask('hubDeleteJobs', '-PjobIds=' + jobId) |
| 66 | + |
| 67 | + then: |
| 68 | + result.task(":hubDeleteJobs").outcome == SUCCESS |
| 69 | + getDocCount(HubConfig.DEFAULT_JOB_NAME, null) == JOB_COUNT - 1 |
| 70 | + } |
| 71 | + |
| 72 | + def "delete multiple jobs"() { |
| 73 | + when: |
| 74 | + EvalResultIterator resultItr = getJobIds() |
| 75 | + EvalResult res = resultItr.next() |
| 76 | + String firstJobId = res.getString() |
| 77 | + if (!resultItr.hasNext()) { |
| 78 | + throw new Exception("Did not find enough job IDs to run multiple job delete test") |
| 79 | + } |
| 80 | + res = resultItr.next() |
| 81 | + String jobIds = firstJobId + ',' + res.getString() |
| 82 | + |
| 83 | + def result = runTask('hubDeleteJobs', '-PjobIds=' + jobIds) |
| 84 | + |
| 85 | + then: |
| 86 | + result.task(":hubDeleteJobs").outcome == SUCCESS |
| 87 | + getDocCount(HubConfig.DEFAULT_JOB_NAME, null) == JOB_COUNT - 2 |
| 88 | + } |
| 89 | + |
| 90 | + def "delete with empty string job id"() { |
| 91 | + given: |
| 92 | + propertiesFile << """ |
| 93 | + ext { |
| 94 | + jobIds= |
| 95 | + } |
| 96 | + """ |
| 97 | + |
| 98 | + when: |
| 99 | + def result = runTask('hubDeleteJobs') |
| 100 | + |
| 101 | + then: |
| 102 | + result.task(":hubDeleteJobs").outcome == SUCCESS |
| 103 | + getDocCount(HubConfig.DEFAULT_JOB_NAME, null) == JOB_COUNT |
| 104 | + } |
| 105 | + |
| 106 | + def "delete with invalid job id"() { |
| 107 | + given: |
| 108 | + propertiesFile << """ |
| 109 | + ext { |
| 110 | + jobIds=no-such-id |
| 111 | + } |
| 112 | + """ |
| 113 | + |
| 114 | + when: |
| 115 | + def result = runTask('hubDeleteJobs') |
| 116 | + |
| 117 | + then: |
| 118 | + result.task(":hubDeleteJobs").outcome == SUCCESS |
| 119 | + getDocCount(HubConfig.DEFAULT_JOB_NAME, null) == JOB_COUNT |
| 120 | + } |
| 121 | + |
| 122 | + def "delete with missing job id"() { |
| 123 | + |
| 124 | + when: |
| 125 | + def result = runFailTask('hubDeleteJobs') |
| 126 | + |
| 127 | + then: |
| 128 | + notThrown(UnexpectedBuildSuccess) |
| 129 | + result.output.contains('jobIds property is required') |
| 130 | + result.task(":hubDeleteJobs").outcome == FAILED |
| 131 | + getDocCount(HubConfig.DEFAULT_JOB_NAME, null) == JOB_COUNT |
| 132 | + } |
| 133 | +} |
0 commit comments