Skip to content

Commit 3054503

Browse files
epughdsmiley
andcommitted
SOLR-15788: Remove the use of legacyExampleCollection1SolrHome() in test setup (#4147)
Co-authored-by: David Smiley <dsmiley@apache.org> (cherry picked from commit f80dc74)
1 parent d0ff2b9 commit 3054503

29 files changed

+249
-337
lines changed

solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@
4949
import org.slf4j.Logger;
5050
import org.slf4j.LoggerFactory;
5151

52-
// TODO: This test would be a lot faster if it used a solrhome with fewer config
53-
// files - there are a lot of them to upload
5452
public class ZkSubcommandsTest extends SolrTestCaseJ4 {
5553
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5654

5755
protected ZkTestServer zkServer;
5856

59-
protected Path zkDir;
60-
61-
private String solrHome;
62-
6357
private SolrZkClient zkClient;
6458

6559
private PrintStream originalSystemOut;
@@ -78,14 +72,12 @@ public void setUp() throws Exception {
7872
log.info("####SETUP_START {}", getTestName());
7973
}
8074

81-
Path exampleHome = legacyExampleCollection1SolrHome();
82-
83-
Path tmpDir = createTempDir();
84-
solrHome = exampleHome.toString();
75+
String solrHome = createTempDir().toString();
76+
System.setProperty("solr.home", solrHome);
8577

8678
originalSystemOut = System.out;
8779

88-
zkDir = tmpDir.resolve("zookeeper/server1/data");
80+
Path zkDir = createTempDir().resolve("zookeeper/server1/data");
8981
log.info("ZooKeeper dataDir:{}", zkDir);
9082
zkServer = new ZkTestServer(zkDir);
9183
zkServer.run();
@@ -138,7 +130,6 @@ public void testPut() throws Exception {
138130
@Test
139131
public void testPutCompressed() throws Exception {
140132
// test put compressed
141-
System.setProperty("solr.home", solrHome);
142133
System.setProperty("minStateByteLenForCompression", "0");
143134

144135
String data = "my data";
@@ -240,7 +231,6 @@ public void testPutFileWithoutSlash() throws Exception {
240231
@Test
241232
public void testPutFileCompressed() throws Exception {
242233
// test put file compressed
243-
System.setProperty("solr.home", solrHome);
244234
System.setProperty("minStateByteLenForCompression", "0");
245235

246236
String[] args =
@@ -459,7 +449,6 @@ public void testGet() throws Exception {
459449

460450
@Test
461451
public void testGetCompressed() throws Exception {
462-
System.setProperty("solr.home", solrHome);
463452
System.setProperty("minStateByteLenForCompression", "0");
464453

465454
String getNode = "/getNode";

solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.solr.handler.admin;
1818

19+
import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;
20+
1921
import java.io.IOException;
2022
import java.io.InputStream;
2123
import java.util.Set;
@@ -32,12 +34,14 @@
3234
import org.apache.solr.common.params.ModifiableSolrParams;
3335
import org.apache.solr.common.params.SolrParams;
3436
import org.apache.solr.common.util.ContentStreamBase;
37+
import org.apache.solr.common.util.EnvUtils;
3538
import org.apache.solr.common.util.NamedList;
3639
import org.apache.solr.core.SolrCore;
3740
import org.apache.solr.request.SolrQueryRequest;
3841
import org.apache.solr.request.SolrQueryRequestBase;
3942
import org.apache.solr.request.SolrRequestHandler;
4043
import org.apache.solr.response.SolrQueryResponse;
44+
import org.apache.solr.util.ExternalPaths;
4145
import org.apache.solr.util.SolrJettyTestRule;
4246
import org.junit.BeforeClass;
4347
import org.junit.ClassRule;
@@ -48,8 +52,13 @@ public class ShowFileRequestHandlerTest extends SolrTestCaseJ4 {
4852

4953
@BeforeClass
5054
public static void beforeTest() throws Exception {
51-
initCore("solrconfig.xml", "schema.xml");
52-
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
55+
EnvUtils.setProperty(
56+
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
57+
solrTestRule.startSolr(createTempDir());
58+
solrTestRule
59+
.newCollection("collection1")
60+
.withConfigSet(ExternalPaths.DEFAULT_CONFIGSET)
61+
.create();
5362
}
5463

5564
private GenericSolrRequest createShowFileRequest(SolrParams params) {
@@ -66,19 +75,17 @@ public void test404ViaHttp() {
6675
}
6776

6877
public void test404Locally() {
69-
// we need to test that executing the handler directly does not
70-
// throw an exception, just sets the exception on the response.
71-
72-
// bypass TestHarness since it will throw any exception found in the
73-
// response.
74-
SolrCore core = h.getCore();
75-
SolrQueryResponse rsp = new SolrQueryResponse();
76-
core.execute(core.getRequestHandler("/admin/file"), req("file", "does-not-exist-404.txt"), rsp);
77-
assertNotNull("no exception in response", rsp.getException());
78-
assertTrue(
79-
"wrong type of exception: " + rsp.getException().getClass(),
80-
rsp.getException() instanceof SolrException);
81-
assertEquals(404, ((SolrException) rsp.getException()).code());
78+
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
79+
SolrQueryResponse rsp = new SolrQueryResponse();
80+
SolrQueryRequest req =
81+
new SolrQueryRequestBase(core, params("file", "does-not-exist-404.txt"));
82+
core.execute(core.getRequestHandler("/admin/file"), req, rsp);
83+
assertNotNull("no exception in response", rsp.getException());
84+
assertTrue(
85+
"wrong type of exception: " + rsp.getException().getClass(),
86+
rsp.getException() instanceof SolrException);
87+
assertEquals(404, ((SolrException) rsp.getException()).code());
88+
}
8289
}
8390

8491
public void testDirList() throws SolrServerException, IOException {
@@ -119,26 +126,17 @@ public Set<String> getContentTypes() {
119126
}
120127

121128
public void testContentTypeHtmlBecomesTextPlain() {
122-
SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file");
123-
SolrQueryRequest req =
124-
new SolrQueryRequestBase(
125-
h.getCore(), params("file", "schema.xml", "contentType", "text/html"));
126-
SolrQueryResponse rsp = new SolrQueryResponse();
127-
handler.handleRequest(req, rsp);
128-
ContentStreamBase.FileStream content =
129-
(ContentStreamBase.FileStream) rsp.getValues().get("content");
130-
assertEquals("text/plain", content.getContentType());
131-
}
132-
133-
public void testContentTypeHtmlDefault() {
134-
SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file");
135-
SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params("file", "example.html"));
136-
SolrQueryResponse rsp = new SolrQueryResponse();
137-
handler.handleRequest(req, rsp);
138-
ContentStreamBase.FileStream content =
139-
(ContentStreamBase.FileStream) rsp.getValues().get("content");
140-
// System attempts to guess content type, but will only return XML, JSON, CSV, never HTML
141-
assertEquals("application/xml", content.getContentType());
129+
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
130+
SolrRequestHandler handler = core.getRequestHandler("/admin/file");
131+
SolrQueryRequest req =
132+
new SolrQueryRequestBase(
133+
core, params("file", "managed-schema.xml", "contentType", "text/html"));
134+
SolrQueryResponse rsp = new SolrQueryResponse();
135+
handler.handleRequest(req, rsp);
136+
ContentStreamBase.FileStream content =
137+
(ContentStreamBase.FileStream) rsp.getValues().get("content");
138+
assertEquals("text/plain", content.getContentType());
139+
}
142140
}
143141

144142
public void testIllegalContentType() throws SolrServerException, IOException {

solr/solrj-jetty/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientBadInputTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.solr.client.solrj.jetty;
1919

20+
import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;
21+
2022
import java.util.ArrayList;
2123
import java.util.List;
22-
import java.util.Properties;
2324
import org.apache.solr.SolrTestCaseJ4;
24-
import org.apache.solr.embedded.JettyConfig;
25+
import org.apache.solr.common.util.EnvUtils;
26+
import org.apache.solr.util.ExternalPaths;
2527
import org.apache.solr.util.SolrJettyTestRule;
2628
import org.junit.BeforeClass;
2729
import org.junit.ClassRule;
@@ -39,8 +41,13 @@ public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrTestCaseJ4
3941

4042
@BeforeClass
4143
public static void beforeTest() throws Exception {
42-
solrTestRule.startSolr(
43-
legacyExampleCollection1SolrHome(), new Properties(), JettyConfig.builder().build());
44+
EnvUtils.setProperty(
45+
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
46+
solrTestRule.startSolr(createTempDir());
47+
solrTestRule
48+
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
49+
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
50+
.create();
4451
}
4552

4653
@Test

solr/solrj-jetty/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientCompatibilityTest.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package org.apache.solr.client.solrj.jetty;
1919

20+
import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;
21+
2022
import java.util.Properties;
2123
import org.apache.solr.SolrTestCaseJ4;
2224
import org.apache.solr.client.solrj.RemoteSolrException;
2325
import org.apache.solr.client.solrj.SolrRequest;
2426
import org.apache.solr.client.solrj.SolrServerException;
2527
import org.apache.solr.client.solrj.request.SolrQuery;
28+
import org.apache.solr.common.util.EnvUtils;
2629
import org.apache.solr.embedded.JettyConfig;
30+
import org.apache.solr.util.ExternalPaths;
2731
import org.apache.solr.util.LogLevel;
2832
import org.apache.solr.util.ServletFixtures.DebugServlet;
2933
import org.apache.solr.util.SolrJettyTestRule;
@@ -56,7 +60,13 @@ public void testConnectToOldNodesUsingHttp1() throws Exception {
5660
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
5761
.useOnlyHttp1(true)
5862
.build();
59-
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
63+
EnvUtils.setProperty(
64+
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
65+
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
66+
solrTestRule
67+
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
68+
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
69+
.create();
6070

6171
try (var client =
6272
new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
@@ -79,7 +89,13 @@ public void testConnectToNewNodesUsingHttp1() throws Exception {
7989
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
8090
.useOnlyHttp1(false)
8191
.build();
82-
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
92+
EnvUtils.setProperty(
93+
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
94+
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
95+
solrTestRule
96+
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
97+
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
98+
.create();
8399

84100
try (var client =
85101
new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
@@ -105,7 +121,14 @@ public void testConnectToOldNodesUsingHttp2() throws Exception {
105121
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
106122
.useOnlyHttp1(true)
107123
.build();
108-
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
124+
125+
EnvUtils.setProperty(
126+
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
127+
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
128+
solrTestRule
129+
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
130+
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
131+
.create();
109132

110133
System.clearProperty("solr.http1");
111134
try (var client =

solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
2323
import org.apache.solr.client.solrj.request.JavaBinRequestWriter;
2424
import org.apache.solr.client.solrj.response.JavaBinResponseParser;
25-
import org.junit.BeforeClass;
2625

2726
/**
2827
* A subclass of SolrExampleTests that explicitly uses the HTTP2 client and the binary codec for
@@ -31,15 +30,10 @@
3130
@SolrTestCaseJ4.SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
3231
public class SolrExampleBinaryHttp2Test extends SolrExampleTests {
3332

34-
@BeforeClass
35-
public static void beforeTest() throws Exception {
36-
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
37-
}
38-
3933
@Override
4034
public SolrClient createNewSolrClient() {
41-
return new HttpJettySolrClient.Builder(getBaseUrl())
42-
.withDefaultCollection(DEFAULT_TEST_CORENAME)
35+
return new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl())
36+
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
4337
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
4438
.withRequestWriter(new JavaBinRequestWriter())
4539
// where the magic happens

solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,18 @@
2020
import org.apache.solr.client.solrj.apache.HttpSolrClient;
2121
import org.apache.solr.client.solrj.request.JavaBinRequestWriter;
2222
import org.apache.solr.client.solrj.response.JavaBinResponseParser;
23-
import org.junit.BeforeClass;
2423

2524
/**
2625
* A subclass of SolrExampleTests that explicitly uses the HTTP1 client and the binary codec for
2726
* communication.
2827
*/
2928
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
3029
public class SolrExampleBinaryTest extends SolrExampleTests {
31-
@BeforeClass
32-
public static void beforeTest() throws Exception {
33-
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
34-
}
3530

3631
@Override
3732
public SolrClient createNewSolrClient() {
38-
return new HttpSolrClient.Builder(getBaseUrl())
39-
.withDefaultCollection(DEFAULT_TEST_CORENAME)
33+
return new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
34+
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
4035
.allowMultiPartPost(random().nextBoolean())
4136
.withRequestWriter(new JavaBinRequestWriter())
4237
.withResponseParser(new JavaBinResponseParser())

solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleCborTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.solr.common.SolrDocumentList;
3737
import org.apache.solr.common.SolrInputDocument;
3838
import org.apache.solr.common.util.NamedList;
39-
import org.junit.BeforeClass;
4039
import org.junit.Ignore;
4140

4241
/**
@@ -45,15 +44,11 @@
4544
* converts them from Map to NamedList
4645
*/
4746
public class SolrExampleCborTest extends SolrExampleTests {
48-
@BeforeClass
49-
public static void beforeTest() throws Exception {
50-
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
51-
}
5247

5348
@Override
5449
public SolrClient createNewSolrClient() {
55-
return new HttpSolrClient.Builder(getBaseUrl())
56-
.withDefaultCollection(DEFAULT_TEST_CORENAME)
50+
return new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
51+
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
5752
.allowMultiPartPost(random().nextBoolean())
5853
.withRequestWriter(cborRequestWriter())
5954
.withResponseParser(cborResponseParser())

0 commit comments

Comments
 (0)