LUCENE-2656: if tests fail, don't report about unclosed resources

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@999016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-09-20 17:27:15 +00:00
parent 6c6a675a4a
commit 30f83250d9
1 changed files with 11 additions and 6 deletions

View File

@ -287,6 +287,7 @@ public abstract class LuceneTestCase extends Assert {
savedTimeZone = TimeZone.getDefault();
timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(seedRnd) : TimeZone.getTimeZone(TEST_TIMEZONE);
TimeZone.setDefault(timeZone);
testsFailed = false;
}
@AfterClass
@ -297,16 +298,19 @@ public abstract class LuceneTestCase extends Assert {
System.clearProperty("solr.solr.home");
System.clearProperty("solr.data.dir");
// now look for unclosed resources
for (MockDirectoryWrapper d : stores.keySet()) {
if (d.isOpen()) {
StackTraceElement elements[] = stores.get(d);
StackTraceElement element = (elements.length > 1) ? elements[1] : null;
fail("directory of test was not closed, opened from: " + element);
if (!testsFailed)
for (MockDirectoryWrapper d : stores.keySet()) {
if (d.isOpen()) {
StackTraceElement elements[] = stores.get(d);
StackTraceElement element = (elements.length > 1) ? elements[1] : null;
fail("directory of test was not closed, opened from: " + element);
}
}
}
stores = null;
}
private static boolean testsFailed; /* true if any tests failed */
// This is how we get control when errors occur.
// Think of this as start/end/success/failed
// events.
@ -315,6 +319,7 @@ public abstract class LuceneTestCase extends Assert {
@Override
public void failed(Throwable e, FrameworkMethod method) {
testsFailed = true;
reportAdditionalFailureInfo();
super.failed(e, method);
}