Skip to content
Merged
17 changes: 3 additions & 14 deletions solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

protected ZkTestServer zkServer;

protected Path zkDir;

private String solrHome;

private SolrZkClient zkClient;

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

Path exampleHome = legacyExampleCollection1SolrHome();

Path tmpDir = createTempDir();
solrHome = exampleHome.toString();
String solrHome = createTempDir().toString();
System.setProperty("solr.home", solrHome);

originalSystemOut = System.out;

zkDir = tmpDir.resolve("zookeeper/server1/data");
Path zkDir = createTempDir().resolve("zookeeper/server1/data");
log.info("ZooKeeper dataDir:{}", zkDir);
zkServer = new ZkTestServer(zkDir);
zkServer.run();
Expand Down Expand Up @@ -138,7 +130,6 @@ public void testPut() throws Exception {
@Test
public void testPutCompressed() throws Exception {
// test put compressed
System.setProperty("solr.home", solrHome);
System.setProperty("minStateByteLenForCompression", "0");

String data = "my data";
Expand Down Expand Up @@ -240,7 +231,6 @@ public void testPutFileWithoutSlash() throws Exception {
@Test
public void testPutFileCompressed() throws Exception {
// test put file compressed
System.setProperty("solr.home", solrHome);
System.setProperty("minStateByteLenForCompression", "0");

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

@Test
public void testGetCompressed() throws Exception {
System.setProperty("solr.home", solrHome);
System.setProperty("minStateByteLenForCompression", "0");

String getNode = "/getNode";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.solr.handler.admin;

import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
Expand All @@ -32,12 +34,14 @@
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand All @@ -48,8 +52,13 @@ public class ShowFileRequestHandlerTest extends SolrTestCaseJ4 {

@BeforeClass
public static void beforeTest() throws Exception {
initCore("solrconfig.xml", "schema.xml");
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
EnvUtils.setProperty(
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
solrTestRule.startSolr(createTempDir());
solrTestRule
.newCollection("collection1")
.withConfigSet(ExternalPaths.DEFAULT_CONFIGSET)
.create();
}

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

public void test404Locally() {
// we need to test that executing the handler directly does not
// throw an exception, just sets the exception on the response.

// bypass TestHarness since it will throw any exception found in the
// response.
SolrCore core = h.getCore();
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler("/admin/file"), req("file", "does-not-exist-404.txt"), rsp);
assertNotNull("no exception in response", rsp.getException());
assertTrue(
"wrong type of exception: " + rsp.getException().getClass(),
rsp.getException() instanceof SolrException);
assertEquals(404, ((SolrException) rsp.getException()).code());
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req =
new SolrQueryRequestBase(core, params("file", "does-not-exist-404.txt"));
core.execute(core.getRequestHandler("/admin/file"), req, rsp);
assertNotNull("no exception in response", rsp.getException());
assertTrue(
"wrong type of exception: " + rsp.getException().getClass(),
rsp.getException() instanceof SolrException);
assertEquals(404, ((SolrException) rsp.getException()).code());
}
}

public void testDirList() throws SolrServerException, IOException {
Expand Down Expand Up @@ -119,26 +126,17 @@ public Set<String> getContentTypes() {
}

public void testContentTypeHtmlBecomesTextPlain() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method demonstrates what we have to start doing to get rid of h.getCore...

SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file");
SolrQueryRequest req =
new SolrQueryRequestBase(
h.getCore(), params("file", "schema.xml", "contentType", "text/html"));
SolrQueryResponse rsp = new SolrQueryResponse();
handler.handleRequest(req, rsp);
ContentStreamBase.FileStream content =
(ContentStreamBase.FileStream) rsp.getValues().get("content");
assertEquals("text/plain", content.getContentType());
}

public void testContentTypeHtmlDefault() {
SolrRequestHandler handler = h.getCore().getRequestHandler("/admin/file");
SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params("file", "example.html"));
SolrQueryResponse rsp = new SolrQueryResponse();
handler.handleRequest(req, rsp);
ContentStreamBase.FileStream content =
(ContentStreamBase.FileStream) rsp.getValues().get("content");
// System attempts to guess content type, but will only return XML, JSON, CSV, never HTML
assertEquals("application/xml", content.getContentType());
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whyis this called "collection1"? that's ugly. SHouldn't it be called "core1"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a while ago, we standardized on "collection1" no matter what Solr's mode is. I like it.

SolrRequestHandler handler = core.getRequestHandler("/admin/file");
SolrQueryRequest req =
new SolrQueryRequestBase(
core, params("file", "managed-schema.xml", "contentType", "text/html"));
SolrQueryResponse rsp = new SolrQueryResponse();
handler.handleRequest(req, rsp);
ContentStreamBase.FileStream content =
(ContentStreamBase.FileStream) rsp.getValues().get("content");
assertEquals("text/plain", content.getContentType());
}
}

public void testIllegalContentType() throws SolrServerException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

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

import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand All @@ -39,8 +41,13 @@ public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrTestCaseJ4

@BeforeClass
public static void beforeTest() throws Exception {
solrTestRule.startSolr(
legacyExampleCollection1SolrHome(), new Properties(), JettyConfig.builder().build());
EnvUtils.setProperty(
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
solrTestRule.startSolr(createTempDir());
solrTestRule
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
.create();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

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

import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP;

import java.util.Properties;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.RemoteSolrException;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.LogLevel;
import org.apache.solr.util.ServletFixtures.DebugServlet;
import org.apache.solr.util.SolrJettyTestRule;
Expand Down Expand Up @@ -56,7 +60,13 @@ public void testConnectToOldNodesUsingHttp1() throws Exception {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(true)
.build();
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
EnvUtils.setProperty(
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
solrTestRule
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
.create();

try (var client =
new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
Expand All @@ -79,7 +89,13 @@ public void testConnectToNewNodesUsingHttp1() throws Exception {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(false)
.build();
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
EnvUtils.setProperty(
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
solrTestRule
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
.create();

try (var client =
new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
Expand All @@ -105,7 +121,14 @@ public void testConnectToOldNodesUsingHttp2() throws Exception {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(true)
.build();
solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);

EnvUtils.setProperty(
ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString());
solrTestRule.startSolr(createTempDir(), new Properties(), jettyConfig);
solrTestRule
.newCollection(DEFAULT_TEST_COLLECTION_NAME)
.withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
.create();

System.clearProperty("solr.http1");
try (var client =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.JavaBinRequestWriter;
import org.apache.solr.client.solrj.response.JavaBinResponseParser;
import org.junit.BeforeClass;

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

@BeforeClass
public static void beforeTest() throws Exception {
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}

@Override
public SolrClient createNewSolrClient() {
return new HttpJettySolrClient.Builder(getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
return new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withRequestWriter(new JavaBinRequestWriter())
// where the magic happens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@
import org.apache.solr.client.solrj.apache.HttpSolrClient;
import org.apache.solr.client.solrj.request.JavaBinRequestWriter;
import org.apache.solr.client.solrj.response.JavaBinResponseParser;
import org.junit.BeforeClass;

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

@Override
public SolrClient createNewSolrClient() {
return new HttpSolrClient.Builder(getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
return new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
.allowMultiPartPost(random().nextBoolean())
.withRequestWriter(new JavaBinRequestWriter())
.withResponseParser(new JavaBinResponseParser())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.junit.BeforeClass;
import org.junit.Ignore;

/**
Expand All @@ -45,15 +44,11 @@
* converts them from Map to NamedList
*/
public class SolrExampleCborTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}

@Override
public SolrClient createNewSolrClient() {
return new HttpSolrClient.Builder(getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
return new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME)
.allowMultiPartPost(random().nextBoolean())
.withRequestWriter(cborRequestWriter())
.withResponseParser(cborResponseParser())
Expand Down
Loading
Loading