PipelineStatusTest.scala 7.94 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    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")))

    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")))

    val compressJobsGvLines = getLinesFromFile(compressJobsGvFile)
    require(compressJobsGvLines.exists(_.contains("cat -> gzip")))
    require(compressJobsGvLines.exists(_.contains("gzip -> zcat")))
    require(compressJobsGvLines.forall(!_.contains("cat -> zcat")))

    val compressMainJobsGvLines = getLinesFromFile(compressMainJobsGvFile)
    require(compressMainJobsGvLines.exists(_.contains("cat -> zcat")))
    require(compressMainJobsGvLines.forall(!_.contains("cat -> gzip")))
    require(compressMainJobsGvLines.forall(!_.contains("gzip -> zcat")))

69 70 71 72 73 74
  }

}

object PipelineStatusTest {

75 76 77 78
  object Status extends Enumeration {
    val Failed, Done, Pending = Value
  }

79 80 81 82 83 84 85 86 87 88 89 90 91 92
  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" : {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
       |    "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
       |    },
123 124 125 126 127 128 129
       |    "gzip_1" : {
       |      "fail_files" : [
       |        "$outputDir/.file.out.gz.fail",
       |        "$outputDir/..file.out.gz.Gzip.out.fail"
       |      ],
       |      "done_at_start" : false,
       |      "output_used_by_jobs" : [
130
       |        "zcat_1"
131 132 133 134 135
       |      ],
       |      "outputs" : [
       |        "$outputDir/file.out.gz",
       |        "$outputDir/.file.out.gz.Gzip.out"
       |      ],
136
       |      "command" : "'/bin/gzip'  -c  '$outputDir/file.out'  >  '$outputDir/file.out.gz' ",
137 138 139 140 141 142 143 144 145
       |      "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"
       |      ],
146
       |      "intermediate" : true,
147 148 149 150
       |      "done_files" : [
       |        "$outputDir/.file.out.gz.done",
       |        "$outputDir/..file.out.gz.Gzip.out.done"
       |      ],
151
       |      "main_job" : false
152 153 154 155 156 157 158 159 160 161 162 163 164 165
       |    },
       |    "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"
       |      ],
166
       |      "command" : "'/bin/cat'  'test.deps'  >  '$outputDir/file.out' ",
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 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
       |      "stdout_file" : "$outputDir/.file.out.Cat.out",
       |      "depends_on_intermediate" : false,
       |      "fail_at_start" : false,
       |      "inputs" : [
       |        "test.deps"
       |      ],
       |      "depends_on_jobs" : [
       |        
       |      ],
       |      "intermediate" : false,
       |      "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,
       |      "intermediate" : false
       |    },
       |    {
       |      "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
}