PipelineStatusTest.scala 8.83 KB
Newer Older
1 2 3 4 5 6 7 8
package nl.lumc.sasc.biopet.core

import java.io.{File, PrintWriter}

import com.google.common.io.Files
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
9 10
import PipelineStatusTest.Status
import nl.lumc.sasc.biopet.utils.IoUtils._
11 12 13 14 15 16 17 18 19 20 21 22

/**
  * Created by pjvan_thof on 10-1-17.
  */
class PipelineStatusTest extends TestNGSuite with Matchers {
  @Test
  def testDefault: Unit = {
    val outputDir = Files.createTempDir()
    outputDir.deleteOnExit()
    PipelineStatusTest.writeDeps(outputDir)

    PipelineStatus.main(Array("-o", outputDir.toString, "-d", outputDir.toString))
23
    checkOutput(outputDir)
24 25 26 27 28 29 30 31 32
  }

  @Test
  def testDepsFileArg: Unit = {
    val outputDir = Files.createTempDir()
    outputDir.deleteOnExit()
    val depsfile = PipelineStatusTest.writeDeps(outputDir)

    PipelineStatus.main(Array("-o", outputDir.toString, "-d", outputDir.toString, "--depsFile", depsfile.toString))
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    checkOutput(outputDir)
  }

  def checkOutput(outputDir: File,
                  cat: Status.Value = Status.Pending,
                  gzip: Status.Value = Status.Pending,
                  zcat: Status.Value = Status.Pending): Unit = {
    val jobsGvFile = new File(outputDir, "jobs.gv")
    val mainJobsGvFile = new File(outputDir, "main_jobs.gv")
    val compressJobsGvFile = new File(outputDir, "compress.jobs.gv")
    val compressMainJobsGvFile = new File(outputDir, "compress.main_jobs.gv")
    jobsGvFile should exist
    mainJobsGvFile should exist
    compressJobsGvFile should exist
    compressMainJobsGvFile should exist

    val jobsGvLines = getLinesFromFile(jobsGvFile)
    require(jobsGvLines.exists(_.contains("cat_1 -> gzip_1")))
    require(jobsGvLines.exists(_.contains("gzip_1 -> zcat_1")))
    require(jobsGvLines.forall(!_.contains("cat_1 -> zcat_1")))
Peter van 't Hof's avatar
Peter van 't Hof committed
53 54 55
    require(jobsGvLines.exists(_.contains("cat_1 [style = dashed]")))
    require(jobsGvLines.forall(!_.contains("gzip_1 [style = dashed]")))
    require(jobsGvLines.forall(!_.contains("zcat_1 [style = dashed]")))
56 57 58 59 60

    val mainJobsGvLines = getLinesFromFile(mainJobsGvFile)
    require(mainJobsGvLines.exists(_.contains("cat_1 -> zcat_1")))
    require(mainJobsGvLines.forall(!_.contains("cat_1 -> gzip_1")))
    require(mainJobsGvLines.forall(!_.contains("gzip_1 -> zcat_1")))
Peter van 't Hof's avatar
Peter van 't Hof committed
61 62 63
    require(mainJobsGvLines.exists(_.contains("cat_1 [style = dashed]")))
    require(mainJobsGvLines.forall(!_.contains("gzip_1 [style = dashed]")))
    require(mainJobsGvLines.forall(!_.contains("zcat_1 [style = dashed]")))
64 65 66 67 68

    val compressJobsGvLines = getLinesFromFile(compressJobsGvFile)
    require(compressJobsGvLines.exists(_.contains("cat -> gzip")))
    require(compressJobsGvLines.exists(_.contains("gzip -> zcat")))
    require(compressJobsGvLines.forall(!_.contains("cat -> zcat")))
Peter van 't Hof's avatar
Peter van 't Hof committed
69 70 71
    require(compressJobsGvLines.exists(_.contains("cat [style = dashed]")))
    require(compressJobsGvLines.forall(!_.contains("gzip [style = dashed]")))
    require(compressJobsGvLines.forall(!_.contains("zcat [style = dashed]")))
72 73 74 75 76

    val compressMainJobsGvLines = getLinesFromFile(compressMainJobsGvFile)
    require(compressMainJobsGvLines.exists(_.contains("cat -> zcat")))
    require(compressMainJobsGvLines.forall(!_.contains("cat -> gzip")))
    require(compressMainJobsGvLines.forall(!_.contains("gzip -> zcat")))
Peter van 't Hof's avatar
Peter van 't Hof committed
77 78 79
    require(compressMainJobsGvLines.exists(_.contains("cat [style = dashed]")))
    require(compressMainJobsGvLines.forall(!_.contains("gzip [style = dashed]")))
    require(compressMainJobsGvLines.forall(!_.contains("zcat [style = dashed]")))
80

81 82 83 84 85 86
  }

}

object PipelineStatusTest {

87 88 89 90
  object Status extends Enumeration {
    val Failed, Done, Pending = Value
  }

91 92 93 94 95 96 97 98 99 100 101 102 103 104
  def writeDeps(outputDir: File): File = {
    require(outputDir.exists())
    val depsFile = new File(outputDir, ".log/test.1234567890/graph/deps.json")
    depsFile.getParentFile.mkdirs()
    val writer = new PrintWriter(depsFile)
    writer.println(defaultDeps(outputDir))
    writer.close()
    depsFile
  }

  def defaultDeps(outputDir: File) =
    s"""
       |{
       |  "jobs" : {
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
       |    "zcat_1" : {
       |      "fail_files" : [
       |        "$outputDir/.file.out.zcat.fail",
       |        "$outputDir/..file.out.zcat.Zcat.out.fail"
       |      ],
       |      "done_at_start" : false,
       |      "output_used_by_jobs" : [
       |
       |      ],
       |      "outputs" : [
       |        "$outputDir/file.out.zcat",
       |        "$outputDir/.file.out.zcat.Zcat.out"
       |      ],
       |      "command" : "'/bin/zcat'  '$outputDir/file.out.gz'  >  '$outputDir/file.out.zcat' ",
       |      "stdout_file" : "$outputDir/.file.out.zcat.Zcat.out",
       |      "depends_on_intermediate" : false,
       |      "fail_at_start" : false,
       |      "inputs" : [
       |        "$outputDir/file.out.gz"
       |      ],
       |      "depends_on_jobs" : [
       |        "gzip_1"
       |      ],
       |      "intermediate" : false,
       |      "done_files" : [
       |        "$outputDir/.file.out.zcat.done",
       |        "$outputDir/..file.out.zcat.Zcat.out.done"
       |      ],
       |      "main_job" : true
       |    },
135 136 137 138 139 140 141
       |    "gzip_1" : {
       |      "fail_files" : [
       |        "$outputDir/.file.out.gz.fail",
       |        "$outputDir/..file.out.gz.Gzip.out.fail"
       |      ],
       |      "done_at_start" : false,
       |      "output_used_by_jobs" : [
142
       |        "zcat_1"
143 144 145 146 147
       |      ],
       |      "outputs" : [
       |        "$outputDir/file.out.gz",
       |        "$outputDir/.file.out.gz.Gzip.out"
       |      ],
148
       |      "command" : "'/bin/gzip'  -c  '$outputDir/file.out'  >  '$outputDir/file.out.gz' ",
149 150 151 152 153 154 155 156 157
       |      "stdout_file" : "$outputDir/.file.out.gz.Gzip.out",
       |      "depends_on_intermediate" : false,
       |      "fail_at_start" : false,
       |      "inputs" : [
       |        "$outputDir/file.out"
       |      ],
       |      "depends_on_jobs" : [
       |        "cat_1"
       |      ],
Peter van 't Hof's avatar
Peter van 't Hof committed
158
       |      "intermediate" : false,
159 160 161 162
       |      "done_files" : [
       |        "$outputDir/.file.out.gz.done",
       |        "$outputDir/..file.out.gz.Gzip.out.done"
       |      ],
163
       |      "main_job" : false
164 165 166 167 168 169 170 171 172 173 174 175 176 177
       |    },
       |    "cat_1" : {
       |      "fail_files" : [
       |        "$outputDir/.file.out.fail",
       |        "$outputDir/..file.out.Cat.out.fail"
       |      ],
       |      "done_at_start" : false,
       |      "output_used_by_jobs" : [
       |        "gzip_1"
       |      ],
       |      "outputs" : [
       |        "$outputDir/file.out",
       |        "$outputDir/.file.out.Cat.out"
       |      ],
178
       |      "command" : "'/bin/cat'  'test.deps'  >  '$outputDir/file.out' ",
179 180 181 182 183 184 185 186 187
       |      "stdout_file" : "$outputDir/.file.out.Cat.out",
       |      "depends_on_intermediate" : false,
       |      "fail_at_start" : false,
       |      "inputs" : [
       |        "test.deps"
       |      ],
       |      "depends_on_jobs" : [
       |        
       |      ],
Peter van 't Hof's avatar
Peter van 't Hof committed
188
       |      "intermediate" : true,
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
       |      "done_files" : [
       |        "$outputDir/.file.out.done",
       |        "$outputDir/..file.out.Cat.out.done"
       |      ],
       |      "main_job" : true
       |    }
       |  },
       |  "files" : [
       |    {
       |      "output_jobs" : [
       |        "cat_1"
       |      ],
       |      "path" : "$outputDir/file.out",
       |      "input_jobs" : [
       |        "gzip_1"
       |      ],
       |      "exists_at_start" : false,
       |      "pipeline_input" : false,
Peter van 't Hof's avatar
Peter van 't Hof committed
207
       |      "intermediate" : true
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
       |    },
       |    {
       |      "output_jobs" : [
       |        "gzip_1"
       |      ],
       |      "path" : "$outputDir/.file.out.gz.Gzip.out",
       |      "input_jobs" : [
       |        
       |      ],
       |      "exists_at_start" : false,
       |      "pipeline_input" : false,
       |      "intermediate" : false
       |    },
       |    {
       |      "output_jobs" : [
       |        "gzip_1"
       |      ],
       |      "path" : "$outputDir/file.out.gz",
       |      "input_jobs" : [
       |        
       |      ],
       |      "exists_at_start" : false,
       |      "pipeline_input" : false,
       |      "intermediate" : false
       |    },
       |    {
       |      "output_jobs" : [
       |        
       |      ],
       |      "path" : "$outputDir/test.deps",
       |      "input_jobs" : [
       |        "cat_1"
       |      ],
       |      "exists_at_start" : false,
       |      "pipeline_input" : true,
       |      "intermediate" : false
       |    },
       |    {
       |      "output_jobs" : [
       |        "cat_1"
       |      ],
       |      "path" : "$outputDir/.file.out.Cat.out",
       |      "input_jobs" : [
       |        
       |      ],
       |      "exists_at_start" : false,
       |      "pipeline_input" : false,
       |      "intermediate" : false
       |    }
       |  ]
       |}
     """.stripMargin
}