Skip to content

Apache Lucene open-source search software

Save/Restore BQ.maxCluseCount in LuceneTestCase

Uwe Schindlerde634b352683
diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
index caa4d6d16c8..68b96d88cef 100644
--- a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
+++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
@@ -42,9 +42,6 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
private static final IndexSearcher searcher;
static {
try {
- // set the theoretical maximum term count for 8bit (see docs for the number)
- BooleanQuery.setMaxClauseCount(3*255*2 + 255);
-
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(TEST_VERSION_CURRENT),
true, MaxFieldLength.UNLIMITED);
@@ -87,6 +84,14 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
}
}
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ // set the theoretical maximum term count for 8bit (see docs for the number)
+ // super.tearDown will restore the default
+ BooleanQuery.setMaxClauseCount(3*255*2 + 255);
+ }
+
/** test for both constant score and boolean query, the other tests only use the constant score mode */
private void testRange(int precisionStep) throws Exception {
String field="field"+precisionStep;
diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
index 263b2e04fa8..14f757aedc4 100644
--- a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
+++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
@@ -41,9 +41,6 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
private static final IndexSearcher searcher;
static {
try {
- // set the theoretical maximum term count for 8bit (see docs for the number)
- BooleanQuery.setMaxClauseCount(7*255*2 + 255);
-
directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(TEST_VERSION_CURRENT),
true, MaxFieldLength.UNLIMITED);
@@ -90,6 +87,14 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
}
}
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ // set the theoretical maximum term count for 8bit (see docs for the number)
+ // super.tearDown will restore the default
+ BooleanQuery.setMaxClauseCount(7*255*2 + 255);
+ }
+
/** test for constant score + boolean query + filter, the other tests only use the constant score mode */
private void testRange(int precisionStep) throws Exception {
String field="field"+precisionStep;
diff --git a/src/test/org/apache/lucene/util/LuceneTestCase.java b/src/test/org/apache/lucene/util/LuceneTestCase.java
index 593d2ffc1be..0abf2b9dd92 100644
--- a/src/test/org/apache/lucene/util/LuceneTestCase.java
+++ b/src/test/org/apache/lucene/util/LuceneTestCase.java
@@ -25,6 +25,7 @@ import java.util.Random;
import junit.framework.TestCase;
import org.apache.lucene.index.ConcurrentMergeScheduler;
+import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.FieldCache.CacheEntry;
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
@@ -54,6 +55,7 @@ import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
public abstract class LuceneTestCase extends TestCase {
public static final Version TEST_VERSION_CURRENT = LuceneTestCaseJ4.TEST_VERSION_CURRENT;
+ private int savedBoolMaxClauseCount;
public LuceneTestCase() {
super();
@@ -67,6 +69,7 @@ public abstract class LuceneTestCase extends TestCase {
protected void setUp() throws Exception {
super.setUp();
ConcurrentMergeScheduler.setTestMode();
+ savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();
}
/**
@@ -89,6 +92,7 @@ public abstract class LuceneTestCase extends TestCase {
@Override
protected void tearDown() throws Exception {
+ BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);
try {
// this isn't as useful as calling directly from the scope where the
// index readers are used, because they could be gc'ed just before