only emit a warning if the tribble index is out of date, don't remove and replace it for them. Added a test case where the log4j appender checks the logging messages for the appropriate output.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3393 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
017ab6b690
commit
ca386439be
|
|
@ -138,6 +138,11 @@ public class TribbleRMDTrackBuilder extends PluginManager<FeatureCodec> implemen
|
||||||
try {
|
try {
|
||||||
// if the file exists, and we can read it, load the index from disk
|
// if the file exists, and we can read it, load the index from disk
|
||||||
if (indexFile.exists() && indexFile.canRead() && obtainedLock) {
|
if (indexFile.exists() && indexFile.canRead() && obtainedLock) {
|
||||||
|
|
||||||
|
// check to see if the index file is out of date
|
||||||
|
if (indexFile.lastModified() < inputFile.lastModified())
|
||||||
|
logger.warn("Tribble index file " + indexFile + " is older than the track file " + inputFile + ", this can lead to unexpected behavior");
|
||||||
|
|
||||||
logger.info("Loading Tribble index from disk for file " + inputFile);
|
logger.info("Loading Tribble index from disk for file " + inputFile);
|
||||||
return LinearIndex.createIndex(indexFile);
|
return LinearIndex.createIndex(indexFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
package org.broadinstitute.sting.gatk.refdata.tracks.builders;
|
package org.broadinstitute.sting.gatk.refdata.tracks.builders;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.log4j.AppenderSkeleton;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.log4j.spi.LoggingEvent;
|
||||||
import org.broad.tribble.vcf.VCFCodec;
|
import org.broad.tribble.vcf.VCFCodec;
|
||||||
import org.broadinstitute.sting.BaseTest;
|
import org.broadinstitute.sting.BaseTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
@ -71,4 +74,55 @@ public class TribbleRMDTrackBuilderUnitTest extends BaseTest {
|
||||||
Assert.assertTrue(Math.abs(1274210993000l - new File(vcfFile + TribbleRMDTrackBuilder.linearIndexExtension).lastModified()) < 100);
|
Assert.assertTrue(Math.abs(1274210993000l - new File(vcfFile + TribbleRMDTrackBuilder.linearIndexExtension).lastModified()) < 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuilderIndexOutOfDate() {
|
||||||
|
Logger logger = Logger.getLogger(TribbleRMDTrackBuilder.class);
|
||||||
|
ValidationAppender appender = new ValidationAppender("Tribble index file /humgen/gsa-hpprojects/GATK/data/Validation_Data/ROD_validation/newerTribbleTrack.vcf.idx is older than the track file /humgen/gsa-hpprojects/GATK/data/Validation_Data/ROD_validation/newerTribbleTrack.vcf, this can lead to unexpected behavior");
|
||||||
|
logger.addAppender(appender);
|
||||||
|
File vcfFile = new File(validationDataLocation + "/ROD_validation/newerTribbleTrack.vcf");
|
||||||
|
try {
|
||||||
|
builder.loadIndex(vcfFile,new VCFCodec(), true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail("IO exception unexpected" + e.getMessage());
|
||||||
|
}
|
||||||
|
// check to make sure the appender saw the target string
|
||||||
|
Assert.assertTrue(appender.foundString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this appender looks for a specific message in the log4j stream.
|
||||||
|
* It can be used to verify that a specific message was generated to the logging system.
|
||||||
|
*/
|
||||||
|
class ValidationAppender extends AppenderSkeleton {
|
||||||
|
|
||||||
|
private boolean foundString = false;
|
||||||
|
private String targetString = "";
|
||||||
|
|
||||||
|
public ValidationAppender(String target) {
|
||||||
|
targetString = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void append(LoggingEvent loggingEvent) {
|
||||||
|
if (loggingEvent.getMessage().equals(targetString))
|
||||||
|
foundString = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresLayout() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean foundString() {
|
||||||
|
return foundString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue