Skip to content

Commit

Permalink
add tests for SAM files that corrupt with adam + htsjdk 0.20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
heuermh committed Sep 11, 2019
1 parent 9cd7d67 commit 4f406db
Show file tree
Hide file tree
Showing 3 changed files with 771 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/test/java/org/seqdoop/hadoop_bam/TestSAMInputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,50 @@ public void testMapReduceJob() throws Exception {
}
br.close();
}

@Test
public void testCorruptedReadNameSAM() throws Exception {
// override setup with different input
Configuration conf = new Configuration();
input = ClassLoader.getSystemClassLoader().getResource("small.sam").getFile();
conf.set("mapred.input.dir", "file://" + input);

taskAttemptContext = new TaskAttemptContextImpl(conf, mock(TaskAttemptID.class));
jobContext = new JobContextImpl(conf, taskAttemptContext.getJobID());

AnySAMInputFormat inputFormat = new AnySAMInputFormat();
List<InputSplit> splits = inputFormat.getSplits(jobContext);
assertEquals(1, splits.size());
RecordReader<LongWritable, SAMRecordWritable> reader = inputFormat
.createRecordReader(splits.get(0), taskAttemptContext);
reader.initialize(splits.get(0), taskAttemptContext);

assertTrue(reader.nextKeyValue());
SAMRecord record = reader.getCurrentValue().get();
assertEquals("1", record.getReferenceName());
assertEquals(26472784, record.getStart());
assertEquals("simread:1:26472783:false", record.getReadName());
}

@Test
public void testCorruptedHeaderSAM() throws Exception {
// override setup with different input
Configuration conf = new Configuration();
input = ClassLoader.getSystemClassLoader().getResource("flag-values.sam").getFile();
conf.set("mapred.input.dir", "file://" + input);

taskAttemptContext = new TaskAttemptContextImpl(conf, mock(TaskAttemptID.class));
jobContext = new JobContextImpl(conf, taskAttemptContext.getJobID());

AnySAMInputFormat inputFormat = new AnySAMInputFormat();
List<InputSplit> splits = inputFormat.getSplits(jobContext);
assertEquals(1, splits.size());
RecordReader<LongWritable, SAMRecordWritable> reader = inputFormat
.createRecordReader(splits.get(0), taskAttemptContext);
reader.initialize(splits.get(0), taskAttemptContext);

assertTrue(reader.nextKeyValue());
SAMRecord record = reader.getCurrentValue().get();
assertEquals("read:0", record.getReadName());
}
}
Loading

0 comments on commit 4f406db

Please sign in to comment.