Skip to content

Commit 2fc349c

Browse files
authored
Deal with properties that are needed for ONE test, but pollute all our tests. (#3987)
This PR addresses test pollution by isolating system property usage that was only needed by a single test but was being set globally across 33 different test locations. The solution creates a dedicated test class TestConfigPropertySubstitution for the one test that actually requires the solr.test.sys.prop1 and solr.test.sys.prop2 properties, and removes the unnecessary property setup/teardown from 32 other test locations.
1 parent ac3d79d commit 2fc349c

29 files changed

+106
-129
lines changed

solr/core/src/test-files/solr/collection1/conf/solrconfig-analytics-query.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@
217217
</httpCaching>
218218
</requestDispatcher>
219219

220-
<!-- test getting system property -->
221-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
222-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
223-
224220
<queryParser name="count" class="org.apache.solr.search.AnalyticsTestQParserPlugin"/>
225221

226222
<updateRequestProcessorChain name="uniq-fields">

solr/core/src/test-files/solr/collection1/conf/solrconfig-collapseqparser.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@
220220
</httpCaching>
221221
</requestDispatcher>
222222

223-
<!-- test getting system property -->
224-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
225-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
226-
227223
<queryParser name="foo" class="FooQParserPlugin"/>
228224

229225
<updateRequestProcessorChain name="uniq-fields">

solr/core/src/test-files/solr/collection1/conf/solrconfig-elevate.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@
120120
</httpCaching>
121121
</requestDispatcher>
122122

123-
<!-- test getting system property -->
124-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
125-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
126-
127123
<queryParser name="foo" class="FooQParserPlugin"/>
128124

129125
<initParams path="/elevate,/dataElevate">

solr/core/src/test-files/solr/collection1/conf/solrconfig-minhash.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,6 @@
434434
</lst>
435435
</requestHandler>
436436

437-
<!-- test getting system property -->
438-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
439-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
440-
441437
<queryParser name="foo" class="FooQParserPlugin"/>
442438

443439
<updateRequestProcessorChain name="uniq-fields">

solr/core/src/test-files/solr/collection1/conf/solrconfig-plugcollector.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,6 @@
430430
</httpCaching>
431431
</requestDispatcher>
432432

433-
<!-- test getting system property -->
434-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
435-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
436-
437433
<queryParser name="rank" class="org.apache.solr.search.RankQueryTestPlugin"/>
438434

439435
<updateRequestProcessorChain name="uniq-fields">

solr/core/src/test-files/solr/collection1/conf/solrconfig-test-misc.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@
2828
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.MockDirectoryFactory}"/>
2929
<schemaFactory class="ClassicIndexSchemaFactory"/>
3030

31-
<!-- see TestConfig.testJavaProperty -->
32-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
33-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
34-
3531
<!-- see TestConfig.testDisableRequetsHandler -->
3632
<requestHandler name="/disabled" class="solr.SearchHandler" enable="false"/>
3733
<requestHandler name="/enabled" class="solr.SearchHandler" enable="true"/>
3834

39-
40-
4135
</config>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" ?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
-->
19+
20+
<!--
21+
A minimal solrconfig specifically for testing property substitution functionality.
22+
This config is used by TestConfigPropertySubstitution.testJavaPropertySubstitution() to test
23+
that system property substitution works correctly in Solr configuration files.
24+
-->
25+
<config>
26+
<luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
27+
<dataDir>${solr.data.dir:}</dataDir>
28+
<xi:include href="solrconfig.snippet.randomindexconfig.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
29+
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.MockDirectoryFactory}"/>
30+
<schemaFactory class="ClassicIndexSchemaFactory"/>
31+
32+
<!-- This element is specifically for testing property substitution -->
33+
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
34+
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
35+
36+
<requestHandler name="/select" class="solr.SearchHandler" />
37+
</config>

solr/core/src/test-files/solr/collection1/conf/solrconfig.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,6 @@
467467
</lst>
468468
</requestHandler>
469469

470-
<!-- test getting system property -->
471-
<propTest attr1="${solr.test.sys.prop1}-$${literal}"
472-
attr2="${non.existent.sys.prop:default-from-config}">prefix-${solr.test.sys.prop2}-suffix</propTest>
473-
474470
<queryParser name="foo" class="FooQParserPlugin"/>
475471

476472
<updateRequestProcessorChain name="uniq-fields">

solr/core/src/test/org/apache/solr/cloud/TestRequestForwarding.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,13 @@ public class TestRequestForwarding extends SolrTestCaseJ4 {
3535
@Override
3636
public void setUp() throws Exception {
3737
super.setUp();
38-
System.setProperty("solr.test.sys.prop1", "propone");
39-
System.setProperty("solr.test.sys.prop2", "proptwo");
4038
solrCluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build());
4139
solrCluster.uploadConfigSet(TEST_PATH().resolve("collection1/conf"), "conf1");
4240
}
4341

4442
@Override
4543
public void tearDown() throws Exception {
4644
solrCluster.shutdown();
47-
System.clearProperty("solr.test.sys.prop1");
48-
System.clearProperty("solr.test.sys.prop2");
49-
5045
super.tearDown();
5146
}
5247

solr/core/src/test/org/apache/solr/core/TestConfig.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import java.io.InputStream;
2121
import java.util.Collections;
2222
import java.util.LinkedHashMap;
23-
import java.util.List;
2423
import org.apache.lucene.index.ConcurrentMergeScheduler;
2524
import org.apache.lucene.index.IndexWriterConfig;
2625
import org.apache.lucene.index.TieredMergePolicy;
2726
import org.apache.lucene.util.InfoStream;
2827
import org.apache.solr.SolrTestCaseJ4;
29-
import org.apache.solr.common.ConfigNode;
3028
import org.apache.solr.schema.IndexSchema;
3129
import org.apache.solr.schema.IndexSchemaFactory;
3230
import org.apache.solr.search.CacheConfig;
@@ -63,30 +61,6 @@ public void testDisableRequetsHandler() {
6361
assertNotNull(h.getCore().getRequestHandler("/enabled"));
6462
}
6563

66-
@Test
67-
public void testJavaProperty() {
68-
// property values defined in build.xml
69-
70-
String s = solrConfig.get("propTest").txt();
71-
assertEquals("prefix-proptwo-suffix", s);
72-
73-
s = solrConfig.get("propTest").attr("attr1", "default");
74-
assertEquals("propone-${literal}", s);
75-
76-
s = solrConfig.get("propTest").attr("attr2", "default");
77-
assertEquals("default-from-config", s);
78-
79-
assertEquals(
80-
"prefix-proptwo-suffix",
81-
solrConfig.get("propTest", it -> "default-from-config".equals(it.attr("attr2"))).txt());
82-
83-
List<ConfigNode> nl = solrConfig.root.getAll("propTest");
84-
assertEquals(1, nl.size());
85-
assertEquals("prefix-proptwo-suffix", nl.get(0).txt());
86-
87-
assertEquals("prefix-proptwo-suffix", solrConfig.get("propTest").txt());
88-
}
89-
9064
@Test
9165
public void testCacheEnablingDisabling() throws Exception {
9266
// ensure if cache is not defined in the config then cache is disabled

0 commit comments

Comments
 (0)