Apache Solr open-source search software
SolrTestCase: reset system properties per test (#5056)
David Smiley9d7cc2884e8a
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.javaindex 554f65b8d49..e467e583b39 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java@@ -57,12 +57,9 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;/**- * All Solr test cases should derive from this class eventually. This is originally a result of- * async logging, see: SOLR-12055 and associated. To enable async logging, we must gracefully shut- * down logging. Many Solr tests subclass LuceneTestCase.+ * All Solr test cases should derive from this class.*- * <p>Rather than add the cruft from SolrTestCaseJ4 to all the Solr tests that currently subclass- * LuceneTestCase, we'll add the shutdown to this class and subclass it.+ * <p><em>Be conservative in what's here; avoid arbitrary/misc utilities.</em>** <p>Other changes that should affect every Solr test case may go here if they don't require the* added capabilities in SolrTestCaseJ4.@@ -195,11 +192,14 @@ public class SolrTestCase extends LuceneTestCase {}@AfterClass- public static void afterClassShutdownLogging() {+ public static void afterClassSolrTestCase() {StartupLoggingUtils.shutdown();+ OpenTelemetryConfigurator.resetForTest();}- @Rule public TestRule methodRules = new LogLevelTestRule();+ @Rule+ public TestRule solrTestRules =+ RuleChain.outerRule(new SystemPropertiesRestoreRule()).around(new LogLevelTestRule());/*** Special hook for sanity checking if any tests trigger failures when an Assumption failure@@ -213,12 +213,8 @@ public class SolrTestCase extends LuceneTestCase {assumeFalse(PROP + " == true", systemPropertyAsBoolean(PROP, false));}- @AfterClass- public static void afterSolrTestCase() {- OpenTelemetryConfigurator.resetForTest();- }-// UTILITY METHODS FOLLOW+ // NOTE: be very conservative in what we add!public static void assertJSONEquals(String expected, String actual) {Object json1 = fromJSONString(expected);diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex fc9416924fa..402ce3c9633 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -22,7 +22,6 @@ import static org.hamcrest.core.StringContains.containsString;import com.carrotsearch.randomizedtesting.RandomizedContext;import com.carrotsearch.randomizedtesting.RandomizedTest;-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.StringReader;@@ -132,9 +131,6 @@ import org.apache.zookeeper.KeeperException;import org.hamcrest.Matcher;import org.junit.AfterClass;import org.junit.BeforeClass;-import org.junit.Rule;-import org.junit.rules.RuleChain;-import org.junit.rules.TestRule;import org.noggit.CharArr;import org.noggit.JSONUtil;import org.noggit.ObjectBuilder;@@ -230,8 +226,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {// thread will read the latest valuepublic static volatile SSLTestConfig sslConfig;- @Rule public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule());-@BeforeClasspublic static void setupTestCases() {if (ignoreExceptionMuter != null) {