Skip to content

Commit

Permalink
Add QuietTestWrapper to suppress excessive test output that exceeds C…
Browse files Browse the repository at this point in the history
…I server log output threshold. (#1541)

* Our test output logs were approaching the max size in travis and this reduces test spam to keep them under the threshold.
  • Loading branch information
cmnbroad authored Mar 9, 2021
1 parent 12fa23d commit 39b18c7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 61 deletions.
68 changes: 31 additions & 37 deletions src/test/java/htsjdk/samtools/cram/build/ContainerFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import htsjdk.samtools.SAMRecordQueryNameComparator;
import htsjdk.samtools.cram.ref.ReferenceContext;
import htsjdk.samtools.cram.structure.*;
import htsjdk.samtools.util.QuietTestWrapper;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand All @@ -18,13 +19,6 @@

public class ContainerFactoryTest extends HtsjdkTest {

// wrapper class to suppress expansion/serialization of lists of records during test execution
private static class RecordSupplier implements Supplier<List<SAMRecord>> {
final List<SAMRecord> samRecords;
public RecordSupplier(final List<SAMRecord> samRecords) { this.samRecords = samRecords; }
@Override public List<SAMRecord> get() { return samRecords; }
}

@DataProvider(name="singleContainerSliceDistribution")
private Object[][] getSingleContainerSliceDistribution() {
final int RECORDS_PER_SLICE = 100;
Expand All @@ -33,59 +27,59 @@ private Object[][] getSingleContainerSliceDistribution() {
// expected record count/slice, expected slice refContexts,
{
// 1 full single-ref slice with 1 rec
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(1, 0)),
RECORDS_PER_SLICE, 1,
new ReferenceContext(0),
1, Arrays.asList(1), Arrays.asList(new ReferenceContext(0))
},
{
// 1 full single-ref slice with 1 rec, but allow > 1 slices/container
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(1, 0)),
RECORDS_PER_SLICE, 2,
new ReferenceContext(0),
1, Arrays.asList(1), Arrays.asList(new ReferenceContext(0))
},
{
// 1 full single-ref slice with RECORDS_PER_SLICE - 1 records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE - 1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE - 1, 0)),
RECORDS_PER_SLICE, 1,
new ReferenceContext(0),
1, Arrays.asList(RECORDS_PER_SLICE - 1), Arrays.asList(new ReferenceContext(0))
},
{
// 1 full single-ref slice with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE, 0)),
RECORDS_PER_SLICE, 1,
new ReferenceContext(0),
1, Arrays.asList(RECORDS_PER_SLICE), Arrays.asList(new ReferenceContext(0))
},
{
// 2 single-ref slices, one with RECORDS_PER_SLICE records, one with 1 record
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE + 1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE + 1, 0)),
RECORDS_PER_SLICE, 2,
new ReferenceContext(0),
2, Arrays.asList(RECORDS_PER_SLICE, 1),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0))
},
{
// 2 single-ref slices, one with RECORDS_PER_SLICE records, one with RECORDS_PER_SLICE - 1
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped((RECORDS_PER_SLICE * 2) - 1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped((RECORDS_PER_SLICE * 2) - 1, 0)),
RECORDS_PER_SLICE, 2,
new ReferenceContext(0),
2, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE - 1),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0))
},
{
// 2 full single-ref slices, each with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 2, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 2, 0)),
RECORDS_PER_SLICE, 2,
new ReferenceContext(0),
2, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0))
},
{
// 3 single-ref slices, two with RECORDS_PER_SLICE records, one with 1 record
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped((RECORDS_PER_SLICE * 2) + 1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped((RECORDS_PER_SLICE * 2) + 1, 0)),
RECORDS_PER_SLICE, 3,
new ReferenceContext(0),
3, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE, 1),
Expand All @@ -96,7 +90,7 @@ private Object[][] getSingleContainerSliceDistribution() {
},
{
// 3 full single-ref slices, each with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 3, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 3, 0)),
RECORDS_PER_SLICE, 3,
new ReferenceContext(0),
3, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE, RECORDS_PER_SLICE),
Expand All @@ -106,51 +100,51 @@ private Object[][] getSingleContainerSliceDistribution() {
// now repeat the tests, but using unmapped records
{
// 1 full single-ref (unmapped) slice with 1 rec
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(1)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(1)),
RECORDS_PER_SLICE, 1,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
1, Arrays.asList(1), Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 1 full single-ref (unmapped) slice with 1 rec, but allow > 1 slices/container
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(1)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(1)),
RECORDS_PER_SLICE, 2,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
1, Arrays.asList(1), Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 1 full single-ref (unmapped) slice with RECORDS_PER_SLICE - 1 records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE - 1)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE - 1)),
RECORDS_PER_SLICE, 1,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
1, Arrays.asList(RECORDS_PER_SLICE - 1), Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 1 full single-ref (unmapped) slice with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE)),
RECORDS_PER_SLICE, 1,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
1, Arrays.asList(RECORDS_PER_SLICE), Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 2 single-ref (unmapped) slices, one with RECORDS_PER_SLICE records, one with 1 record
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE + 1)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE + 1)),
RECORDS_PER_SLICE, 2,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
2, Arrays.asList(RECORDS_PER_SLICE, 1),
Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT, ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 2 full single-ref (unmapped) slices, each with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE * 2)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE * 2)),
RECORDS_PER_SLICE, 2,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
2, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE),
Arrays.asList(ReferenceContext.UNMAPPED_UNPLACED_CONTEXT, ReferenceContext.UNMAPPED_UNPLACED_CONTEXT)
},
{
// 3 full single-ref (unmapped) slices, each with RECORDS_PER_SLICE records
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE * 3)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE * 3)),
RECORDS_PER_SLICE, 3,
ReferenceContext.UNMAPPED_UNPLACED_CONTEXT,
3, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE, RECORDS_PER_SLICE),
Expand All @@ -165,7 +159,7 @@ private Object[][] getSingleContainerSliceDistribution() {
// reference context would be more correctly called a "placed" reference context
{
// 1 full single-ref mapped slice with RECORDS_PER_SLICE records
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
Collections.singletonList(CRAMStructureTestHelper.createSAMRecordUnmappedPlaced(0, 1)),
CRAMStructureTestHelper.createSAMRecordsMapped((RECORDS_PER_SLICE / 2) - 2, 0),
Collections.singletonList(CRAMStructureTestHelper.createSAMRecordUnmappedPlaced(0, 1)))
Expand All @@ -179,15 +173,15 @@ private Object[][] getSingleContainerSliceDistribution() {
// now queryname sorted
{
// 1 full single-ref slice with RECORDS_PER_SLICE-1 records
new RecordSupplier(CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE - 1,0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE - 1,0)),
RECORDS_PER_SLICE, 1,
new ReferenceContext(0),
1, Arrays.asList(RECORDS_PER_SLICE - 1),
Arrays.asList(new ReferenceContext(0))
},
{
// 2 full single-ref slices, one with with RECORDS_PER_SLICE records and one record
new RecordSupplier(CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE + 1,0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE + 1,0)),
RECORDS_PER_SLICE, 2,
new ReferenceContext(0),
2, Arrays.asList(RECORDS_PER_SLICE, 1),
Expand All @@ -196,7 +190,7 @@ private Object[][] getSingleContainerSliceDistribution() {
{
// use a small number of records from multiple (not coordinate-ordered) reference contexts to
// force creation of a multi-ref container
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(2,1),
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(2,0),
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(2,1))
Expand All @@ -214,7 +208,7 @@ private Object[][] getSingleContainerSliceDistribution() {

@Test(dataProvider = "singleContainerSliceDistribution")
public void testSingleContainerSliceDistribution(
final Supplier<List<SAMRecord>> samRecordSupplier,
final QuietTestWrapper<List<SAMRecord>> samRecordSupplier,
final int readsPerSlice,
final int slicesPerContainer,
final ReferenceContext expectedContainerReferenceContext,
Expand Down Expand Up @@ -257,21 +251,21 @@ private Object[][] getMultipleContainerSliceDistribution() {
// expected slices per container
{
// this generates two containers since it has two containers worth of records mapped to a single ref
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 2, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 2, 0)),
RECORDS_PER_SLICE, 1,
2, Arrays.asList(RECORDS_PER_SLICE, RECORDS_PER_SLICE),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0)),
Arrays.asList(1, 1)
},
{
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 3 + 1, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 3 + 1, 0)),
RECORDS_PER_SLICE, 2,
2, Arrays.asList(RECORDS_PER_SLICE * 2, RECORDS_PER_SLICE+ 1),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0)),
Arrays.asList(2, 2)
},
{
new RecordSupplier(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 4, 0)),
new QuietTestWrapper<>(CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 4, 0)),
RECORDS_PER_SLICE, 2,
2, Arrays.asList(RECORDS_PER_SLICE * 2, RECORDS_PER_SLICE * 2),
Arrays.asList(new ReferenceContext(0), new ReferenceContext(0)),
Expand All @@ -280,7 +274,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
{
// this generates one container because although it has records mapped to two different reference
// contigs, there aren't enough records to reach the minimum single ref threshold
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE - 1, 0),
CRAMStructureTestHelper.createSAMRecordsMapped(1, 1))
.flatMap(List::stream)
Expand All @@ -293,7 +287,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
{
// this generates one container because it has some mapped (but not enough to reach the
// minimum single ref threshold), and one unmapped
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE - 1, 0),
CRAMStructureTestHelper.createSAMRecordsUnmapped(1))
.flatMap(List::stream)
Expand All @@ -305,7 +299,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
},
{
// this generates two containers since it has some mapped and one unmapped
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE * 2, 0),
CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE))
.flatMap(List::stream)
Expand All @@ -318,7 +312,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
{
// this generates two containers since it has some mapped, but not enough to emit a single
// ref container, and one unmapped, which goes into a second container
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE / 2, 0),
CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE))
.flatMap(List::stream)
Expand All @@ -334,7 +328,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
// even though we allow 2 slices/container, this generates two containers since it has
// some mapped and one unmapped, and we won't emit a second single-ref slice into the
// first container once we've emitted the multi-ref slice!
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createSAMRecordsMapped(RECORDS_PER_SLICE / 2, 0),
CRAMStructureTestHelper.createSAMRecordsUnmapped(RECORDS_PER_SLICE))
.flatMap(List::stream)
Expand All @@ -353,7 +347,7 @@ private Object[][] getMultipleContainerSliceDistribution() {
// use records from multiple (not coordinate-ordered) reference contexts to
// force creation of one multi-ref (after name sorting, the first container has a mix of
// ref 0 and ref 1), and one single ref container
new RecordSupplier(Stream.of(
new QuietTestWrapper<>(Stream.of(
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE/2,1),
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE/2,0),
CRAMStructureTestHelper.createQueryNameSortedSAMRecords(RECORDS_PER_SLICE,1))
Expand Down
Loading

0 comments on commit 39b18c7

Please sign in to comment.