Source code

Download source archive ↓

tests/FastqSafetyCheck.scala

1package xstream.galaxy
2import java.io._
3import java.nio.charset.StandardCharsets.UTF_8
4import java.util.concurrent.CancellationException
5import com.fasterxml.jackson.databind.ObjectMapper
6object FastqSafetyCheck {
7 def main(args:Array[String]):Unit={
8  val mapper=new ObjectMapper;val p=mapper.readTree("{}")
9  Seq(FastqToFasta,FastqToQual).foreach{op=>
10   Thread.currentThread.interrupt()
11   try{op.transform(new ByteArrayInputStream(Array.emptyByteArray),new ByteArrayOutputStream,p);throw new AssertionError("cancellation ignored")}
12   catch{case _:CancellationException=>()}finally Thread.interrupted()
13   var failed=false
14   try op.transform(new InputStream{def read():Int=throw new IOException("input failure")},new ByteArrayOutputStream,p)catch{case _:IOException=>failed=true};assert(failed)
15   failed=false
16   try op.transform(new ByteArrayInputStream("@r\nAC\n+\nII\n".getBytes(UTF_8)),new OutputStream{def write(b:Int):Unit=throw new IOException("output failure")},p)catch{case _:IOException=>failed=true};assert(failed)
17   val out=new ByteArrayOutputStream
18   op.transform(new ByteArrayInputStream("@one\nA\n+\nI\n@two\nC\n+two\nJ".getBytes(UTF_8)),out,p)
19   assert(out.toString("UTF-8")== (if(op==FastqToFasta)">one\nA\n>two\nC\n"else">one\n9\n>two\n10\n"))
20  }
21  println("PASS FASTQ cancellation, input/output failure propagation, multiple records and final line without newline")
22 }
23}