From c8de69bdce9d300ed6f36bcbc1cfdf5856ea4325 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 15 Jul 2010 15:10:37 +0000 Subject: [PATCH] SOLR-2002: assert inconsistencies in setup/teardown rather than giving an awkward IAE for maxclausecount=0 git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@964459 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/org/apache/lucene/index/TestDirectoryReader.java | 1 - .../apache/lucene/search/function/FunctionTestSetup.java | 1 - .../src/test/org/apache/lucene/util/LuceneTestCase.java | 8 +++++++- .../src/test/org/apache/lucene/util/LuceneTestCaseJ4.java | 8 ++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java index d347bcd67ea..d46d68d2c3b 100644 --- a/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java +++ b/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java @@ -68,7 +68,6 @@ public class TestDirectoryReader extends LuceneTestCase { } public void test() throws Exception { - setUp(); doTestDocument(); doTestUndeleteAll(); } diff --git a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java index 42feeb2cae4..34a12fcb107 100755 --- a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java +++ b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java @@ -93,7 +93,6 @@ public class FunctionTestSetup extends LuceneTestCaseJ4 { public void setUp() throws Exception { super.setUp(); // prepare a small index with just a few documents. - super.setUp(); dir = new RAMDirectory(); anlzr = new MockAnalyzer(); IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, anlzr)); diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java index e5d86f25a69..8a7bfff97cb 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java @@ -72,6 +72,9 @@ public abstract class LuceneTestCase extends TestCase { private volatile Thread.UncaughtExceptionHandler savedUncaughtExceptionHandler = null; + /** Used to track if setUp and tearDown are called correctly from subclasses */ + private boolean setup; + private static class UncaughtExceptionEntry { public final Thread thread; public final Throwable exception; @@ -94,7 +97,8 @@ public abstract class LuceneTestCase extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - + assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup); + setup = true; savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { @@ -128,6 +132,8 @@ public abstract class LuceneTestCase extends TestCase { @Override protected void tearDown() throws Exception { + assertTrue("ensure your setUp() calls super.setUp()!!!", setup); + setup = false; BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount); try { diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java index 396c1b9e906..f4c04546927 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.FieldCache.CacheEntry; import org.apache.lucene.util.FieldCacheSanityChecker.Insanity; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -107,6 +108,9 @@ public class LuceneTestCaseJ4 { private volatile Thread.UncaughtExceptionHandler savedUncaughtExceptionHandler = null; + /** Used to track if setUp and tearDown are called correctly from subclasses */ + private boolean setup; + private static class UncaughtExceptionEntry { public final Thread thread; public final Throwable exception; @@ -156,6 +160,8 @@ public class LuceneTestCaseJ4 { @Before public void setUp() throws Exception { + Assert.assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup); + setup = true; savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { @@ -192,6 +198,8 @@ public class LuceneTestCaseJ4 { @After public void tearDown() throws Exception { + Assert.assertTrue("ensure your setUp() calls super.setUp()!!!", setup); + setup = false; BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount); try {