From b7e4a015c019cac359a5f5d4eee70a58f4f7e901 Mon Sep 17 00:00:00 2001 From: depristo Date: Fri, 17 Dec 2010 21:53:10 +0000 Subject: [PATCH] static thread cache reset in UnitTest git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4870 348d0f76-0448-11de-a6fe-93d51630548a --- .../fasta/CachingIndexedFastaSequenceFile.java | 16 ++++++++++++---- .../CachingIndexedFastaSequenceFileUnitTest.java | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFile.java b/java/src/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFile.java index ebafc4cb6..9b2550bfd 100644 --- a/java/src/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFile.java +++ b/java/src/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFile.java @@ -67,12 +67,20 @@ public class CachingIndexedFastaSequenceFile extends IndexedFastaSequenceFile { ReferenceSequence seq = null; } - private static ThreadLocal cache = new ThreadLocal () { - @Override protected Cache initialValue() { - return new Cache(); - } + private static ThreadLocal cache; + + static { + resetThreadLocalCache(); }; + protected static void resetThreadLocalCache() { + cache = new ThreadLocal () { + @Override protected Cache initialValue() { + return new Cache(); + } + }; + } + /** * Same as general constructor but allows one to override the default cacheSize * @param file diff --git a/java/test/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFileUnitTest.java b/java/test/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFileUnitTest.java index aa720e521..4d284d2e2 100644 --- a/java/test/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFileUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/fasta/CachingIndexedFastaSequenceFileUnitTest.java @@ -8,6 +8,8 @@ package org.broadinstitute.sting.utils.fasta; import org.testng.Assert; import org.testng.annotations.Test; import org.testng.annotations.DataProvider; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.BeforeMethod; import org.broadinstitute.sting.BaseTest; import java.io.File; @@ -30,6 +32,11 @@ public class CachingIndexedFastaSequenceFileUnitTest extends BaseTest { private static final List QUERY_SIZES = Arrays.asList(1, 10, 100, 1000); private static final List CACHE_SIZES = Arrays.asList(-1, 10, 1000); + @BeforeTest + public void clearCache() { + CachingIndexedFastaSequenceFile.resetThreadLocalCache(); + } + @DataProvider(name = "fastas") public Object[][] createData1() { List params = new ArrayList();