Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Migrate Solr tests from SolrJettyTestBase to using SolrJettyTestRule (#3947)

Eric Pugh6b82523c3836
diff --git a/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java b/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
index 4173d80d5ab..488c00ea753 100644
--- a/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
+++ b/solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java
@@ -36,7 +36,7 @@ import org.junit.Test;
*/
public class TestCustomCoreProperties extends SolrTestCaseJ4 {
- @ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
// TODO these properties files don't work with configsets
@@ -49,7 +49,6 @@ public class TestCustomCoreProperties extends SolrTestCaseJ4 {
Files.createDirectories(confDir);
- Files.copy(SolrTestCaseJ4.TEST_HOME().resolve("solr.xml"), homeDir.resolve("solr.xml"));
String src_dir = TEST_HOME() + "/collection1/conf";
Files.copy(Path.of(src_dir, "schema-tiny.xml"), confDir.resolve("schema.xml"));
Files.copy(
@@ -79,7 +78,7 @@ public class TestCustomCoreProperties extends SolrTestCaseJ4 {
nodeProperties.setProperty("solr.data.dir", createTempDir().toRealPath().toString());
}
- solrClientTestRule.startSolr(homeDir, nodeProperties, JettyConfig.builder().build());
+ solrTestRule.startSolr(homeDir, nodeProperties, JettyConfig.builder().build());
}
@Test
@@ -88,7 +87,7 @@ public class TestCustomCoreProperties extends SolrTestCaseJ4 {
params(
"q", "*:*",
"echoParams", "all");
- QueryResponse res = solrClientTestRule.getSolrClient("collection1").query(params);
+ QueryResponse res = solrTestRule.getSolrClient("collection1").query(params);
assertEquals(0, res.getResults().getNumFound());
NamedList<?> echoedParams = (NamedList<?>) res.getHeader().get("params");
diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
index 6ec872d9ac0..5c5b5b63470 100644
--- a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
+++ b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java
@@ -21,7 +21,6 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
@@ -34,10 +33,14 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.JavaBinResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
-public class TestTolerantSearch extends SolrJettyTestBase {
+public class TestTolerantSearch extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static SolrClient collection1;
private static SolrClient collection2;
@@ -45,14 +48,22 @@ public class TestTolerantSearch extends SolrJettyTestBase {
private static String shard2;
private static Path createSolrHome() throws Exception {
- Path workDir = createTempDir();
- setupJettyTestHome(workDir, "collection1");
+ Path workDir = createTempDir().toRealPath();
+
+ // Copy solr.xml
Files.copy(
- Path.of(SolrTestCaseJ4.TEST_HOME() + "/collection1/conf/solrconfig-tolerant-search.xml"),
- workDir.resolve("collection1").resolve("conf").resolve("solrconfig.xml"),
+ SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"),
+ workDir.resolve("solr.xml"),
StandardCopyOption.REPLACE_EXISTING);
- FileUtils.copyDirectory(
- workDir.resolve("collection1").toFile(), workDir.resolve("collection2").toFile());
+
+ // Set up collection1 with minimal config + tolerant search solrconfig
+ Path collection1Dir = workDir.resolve("collection1");
+ copyMinConf(collection1Dir, "name=collection1\n", "solrconfig-tolerant-search.xml");
+
+ // Set up configset for CoreAdminRequest.Create (reuse the same config)
+ Path configSetDir = workDir.resolve("configsets").resolve("collection1");
+ copyMinConf(configSetDir, null, "solrconfig-tolerant-search.xml");
+
return workDir;
}
@@ -60,23 +71,24 @@ public class TestTolerantSearch extends SolrJettyTestBase {
public static void createThings() throws Exception {
systemSetPropertyEnableUrlAllowList(false);
Path solrHome = createSolrHome();
- createAndStartJetty(solrHome);
- String url = getBaseUrl();
- collection1 = getHttpSolrClient(url, "collection1");
- collection2 = getHttpSolrClient(url, "collection2");
+ solrTestRule.startSolr(solrHome);
- String urlCollection1 = getBaseUrl() + "/" + "collection1";
- String urlCollection2 = getBaseUrl() + "/" + "collection2";
+ collection1 = solrTestRule.getSolrClient("collection1");
+
+ String urlCollection1 = solrTestRule.getBaseUrl() + "/" + "collection1";
+ String urlCollection2 = solrTestRule.getBaseUrl() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
// create second core
- try (SolrClient nodeClient = getHttpSolrClient(url)) {
- CoreAdminRequest.Create req = new CoreAdminRequest.Create();
- req.setCoreName("collection2");
- req.setConfigSet("collection1");
- nodeClient.request(req);
- }
+ SolrClient nodeClient = solrTestRule.getSolrClient();
+ CoreAdminRequest.Create req = new CoreAdminRequest.Create();
+ req.setCoreName("collection2");
+ req.setConfigSet("collection1");
+ nodeClient.request(req);
+
+ // Now get the client for collection2 after it's been created
+ collection2 = solrTestRule.getSolrClient("collection2");
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
@@ -100,14 +112,8 @@ public class TestTolerantSearch extends SolrJettyTestBase {
@AfterClass
public static void destroyThings() throws Exception {
- if (null != collection1) {
- collection1.close();
- collection1 = null;
- }
- if (null != collection2) {
- collection2.close();
- collection2 = null;
- }
+ collection1 = null;
+ collection2 = null;
resetExceptionIgnores();
systemClearPropertySolrEnableUrlAllowList();
}
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java b/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java
index 5da12a8048b..b5b68bd7f1b 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigSetImmutable.java
@@ -61,7 +61,7 @@ public class TestConfigSetImmutable extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (restTestHarness != null) {
restTestHarness.close();
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
index c7b8219bb33..c0efb0c3274 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
@@ -140,7 +140,7 @@ public class TestSolrConfigHandler extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (restTestHarness != null) {
restTestHarness.close();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestHttpRequestId.java b/solr/core/src/test/org/apache/solr/handler/TestHttpRequestId.java
index 7865c74d954..fc560425209 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestHttpRequestId.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestHttpRequestId.java
@@ -26,7 +26,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.logging.log4j.core.LogEvent;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.common.util.ExecutorUtil;
@@ -35,16 +35,20 @@ import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.util.LogLevel;
import org.apache.solr.util.LogListener;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.MDC;
@LogLevel("org.apache.solr.client.solrj.jetty.HttpJettySolrClient=DEBUG")
-public class TestHttpRequestId extends SolrJettyTestBase {
+public class TestHttpRequestId extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(createTempDir());
}
@Test
@@ -95,7 +99,7 @@ public class TestHttpRequestId extends SolrJettyTestBase {
false);
CompletableFuture<NamedList<Object>> cf;
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl())
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(collection)
.withExecutor(commExecutor)
.build()) {
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
index f59aa9cdffd..c91d1eadb33 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
@@ -38,7 +38,6 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
-import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
@@ -53,7 +52,7 @@ import org.slf4j.LoggerFactory;
// Backups do checksum validation against a footer value not present in 'SimpleText'
@LuceneTestCase.SuppressCodecs({"SimpleText"})
@SolrTestCaseJ4.SuppressSSL // Currently, unknown why SSL does not work with this test
-public class TestReplicationHandlerBackup extends SolrJettyTestBase {
+public class TestReplicationHandlerBackup extends SolrTestCaseJ4 {
JettySolrRunner leaderJetty;
ReplicationTestHelper.SolrInstance leader = null;
@@ -78,9 +77,8 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
return jetty;
}
- private static SolrClient createNewSolrClient(int port) {
- final String baseUrl = buildUrl(port);
- return new HttpSolrClient.Builder(baseUrl)
+ private static SolrClient createNewSolrClient(JettySolrRunner jetty) {
+ return new HttpSolrClient.Builder(jetty.getBaseUrl().toString())
.withConnectionTimeout(15000, TimeUnit.MILLISECONDS)
.withSocketTimeout(60000, TimeUnit.MILLISECONDS)
.build();
@@ -102,7 +100,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
leader.copyConfigFile(CONF_DIR.resolve(configFile).toString(), "solrconfig.xml");
leaderJetty = createAndStartJetty(leader);
- leaderClient = createNewSolrClient(leaderJetty.getLocalPort());
+ leaderClient = createNewSolrClient(leaderJetty);
docsSeed = random().nextLong();
}
@@ -247,7 +245,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
public static void runBackupCommand(JettySolrRunner leaderJetty, String cmd, String params)
throws IOException {
String leaderUrl =
- buildUrl(leaderJetty.getLocalPort())
+ leaderJetty.getBaseUrl().toString()
+ "/"
+ DEFAULT_TEST_CORENAME
+ ReplicationHandler.PATH
diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
index 6d00d5a69b5..fbcac1a5bc7 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
-import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
@@ -41,7 +40,7 @@ import org.junit.Test;
@SolrTestCaseJ4.SuppressSSL // Currently, unknown why SSL does not work with this test
// Backups do checksum validation against a footer value not present in 'SimpleText'
@LuceneTestCase.SuppressCodecs("SimpleText")
-public class TestRestoreCore extends SolrJettyTestBase {
+public class TestRestoreCore extends SolrTestCaseJ4 {
JettySolrRunner leaderJetty;
ReplicationTestHelper.SolrInstance leader = null;
diff --git a/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java b/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java
index 010b1e14a4e..1083c5b5e06 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java
@@ -52,8 +52,7 @@ public class TestStressIncrementalBackup extends SolrCloudTestCase {
backupPath = createTempDir(getTestClass().getSimpleName() + "_backups");
System.setProperty("solr.security.allow.paths", backupPath.toString());
- // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient and I can't
- // bring myself to deal with the nonsense that is SolrJettyTestBase.
+ // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient.
// We do however explicitly want a fresh "cluster" every time a test is run
configureCluster(1).addConfig("conf1", configset("cloud-minimal")).configure();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java
index 9422dbbc267..059c9c3cfaa 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java
@@ -89,8 +89,7 @@ public class TestStressThreadBackup extends SolrCloudTestCase {
public void beforeTest() throws Exception {
backupDir = createTempDir(getTestClass().getSimpleName() + "_backups");
- // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient and I can't
- // bring myself to deal with the nonsense that is SolrJettyTestBase.
+ // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient
// We do however explicitly want a fresh "cluster" every time a test is run
configureCluster(1)
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java
index e1d02085a42..d0a7292d3a4 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java
@@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
@@ -38,18 +38,18 @@ import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
-/**
- * Extend SolrJettyTestBase because the SOLR-2535 bug only manifested itself when the {@link
- * org.apache.solr.servlet.SolrDispatchFilter} is used, which isn't for embedded Solr use.
- */
-public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
+public class ShowFileRequestHandlerTest extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void beforeTest() throws Exception {
initCore("solrconfig.xml", "schema.xml");
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
private GenericSolrRequest createShowFileRequest(SolrParams params) {
@@ -59,7 +59,7 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void test404ViaHttp() {
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(params("file", "does-not-exist-404.txt"));
SolrException e = expectThrows(SolrException.class, () -> request.process(client));
assertEquals(404, e.code());
@@ -82,18 +82,14 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void testDirList() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
- // assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends
- // SolrTestCaseJ4
+ SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(new ModifiableSolrParams());
var resp = request.process(client);
assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0); // some files
}
public void testGetRawFile() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
- // assertQ(req("qt", "/admin/file"));
- // TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
+ SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(params("file", "managed-schema.xml"));
final AtomicBoolean readFile = new AtomicBoolean();
request.setResponseParser(
@@ -146,7 +142,7 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void testIllegalContentType() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
var request =
createShowFileRequest(params("file", "managed-schema", "contentType", "not/known"));
request.setResponseParser(new InputStreamResponseParser("xml"));
@@ -155,7 +151,7 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void testAbsoluteFilename() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params("file", "/etc/passwd", "contentType", "text/plain; charset=utf-8"));
@@ -165,7 +161,7 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void testEscapeConfDir() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params("file", "../../solr.xml", "contentType", "application/xml; charset=utf-8"));
@@ -175,7 +171,7 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
}
public void testPathTraversalFilename() throws SolrServerException, IOException {
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params(
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
index e32da54aacc..75b4de3ffd4 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -17,7 +17,6 @@
package org.apache.solr.handler.component;
import java.io.IOException;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -26,11 +25,9 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import org.apache.commons.io.file.PathUtils;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrException;
@@ -38,46 +35,44 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.util.ExternalPaths;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class DistributedDebugComponentTest extends SolrJettyTestBase {
+public class DistributedDebugComponentTest extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static SolrClient collection1;
private static SolrClient collection2;
private static String shard1;
private static String shard2;
- private static Path createSolrHome() throws Exception {
- Path workDir = createTempDir();
- setupJettyTestHome(workDir, "collection1");
- PathUtils.copyDirectory(workDir.resolve("collection1"), workDir.resolve("collection2"));
- return workDir;
- }
-
@BeforeClass
public static void createThings() throws Exception {
systemSetPropertyEnableUrlAllowList(false);
- Path solrHome = createSolrHome();
- createAndStartJetty(solrHome);
- String url = getBaseUrl();
-
- collection1 = getHttpSolrClient(url, "collection1");
- collection2 = getHttpSolrClient(url, "collection2");
-
- String urlCollection1 = getBaseUrl() + "/" + "collection1";
- String urlCollection2 = getBaseUrl() + "/" + "collection2";
+ solrTestRule.startSolr(createTempDir());
+
+ solrTestRule
+ .newCollection("collection1")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
+ solrTestRule
+ .newCollection("collection2")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
+ var cc = solrTestRule.getCoreContainer();
+ cc.waitForLoadingCoresToFinish(30000);
+
+ String urlCollection1 = solrTestRule.getBaseUrl() + "/" + "collection1";
+ String urlCollection2 = solrTestRule.getBaseUrl() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
-
- // create second core
- try (SolrClient nodeClient = getHttpSolrClient(url)) {
- CoreAdminRequest.Create req = new CoreAdminRequest.Create();
- req.setCoreName("collection2");
- req.setConfigSet("collection1");
- nodeClient.request(req);
- }
+ collection1 = solrTestRule.getSolrClient("collection1");
+ collection2 = solrTestRule.getSolrClient("collection2");
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
@@ -92,15 +87,9 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
@AfterClass
- public static void destroyThings() throws Exception {
- if (null != collection1) {
- collection1.close();
- collection1 = null;
- }
- if (null != collection2) {
- collection2.close();
- collection2 = null;
- }
+ public static void destroyThings() {
+ collection1 = null;
+ collection2 = null;
resetExceptionIgnores();
systemClearPropertySolrEnableUrlAllowList();
}
@@ -170,7 +159,6 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
@Test
- @SuppressWarnings("resource") // Cannot close client in this loop!
public void testRandom() throws Exception {
final int NUM_ITERS = atLeast(50);
diff --git a/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java b/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
index 0347fd4938b..b3b9f42cd5d 100644
--- a/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
+++ b/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
@@ -24,13 +24,15 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrXmlConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class JvmMetricsTest extends SolrJettyTestBase {
+public class JvmMetricsTest extends SolrTestCaseJ4 {
static final String[] STRING_OS_METRICS = {"arch", "name", "version"};
static final String[] NUMERIC_OS_METRICS = {"availableProcessors", "systemLoadAverage"};
@@ -43,10 +45,12 @@ public class JvmMetricsTest extends SolrJettyTestBase {
"mapped.TotalCapacity"
};
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
@BeforeClass
public static void beforeTest() throws Exception {
System.setProperty("solr.metrics.jvm.enabled", "true");
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(createTempDir());
}
@Test
@@ -68,7 +72,11 @@ public class JvmMetricsTest extends SolrJettyTestBase {
@Test
public void testSetupJvmMetrics() throws InterruptedException {
PrometheusMetricReader reader =
- getJetty().getCoreContainer().getMetricManager().getPrometheusMetricReader("solr.jvm");
+ solrTestRule
+ .getJetty()
+ .getCoreContainer()
+ .getMetricManager()
+ .getPrometheusMetricReader("solr.jvm");
MetricSnapshots snapshots = reader.collect();
assertTrue("Should have metric snapshots", snapshots.size() > 0);
diff --git a/solr/core/src/test/org/apache/solr/response/TestErrorResponseStackTrace.java b/solr/core/src/test/org/apache/solr/response/TestErrorResponseStackTrace.java
index ce10d4e2d48..869e3941543 100644
--- a/solr/core/src/test/org/apache/solr/response/TestErrorResponseStackTrace.java
+++ b/solr/core/src/test/org/apache/solr/response/TestErrorResponseStackTrace.java
@@ -41,7 +41,7 @@ import org.junit.Test;
@SuppressSSL
public class TestErrorResponseStackTrace extends SolrTestCaseJ4 {
- @ClassRule public static final SolrJettyTestRule solrRule = new SolrJettyTestRule();
+ @ClassRule public static final SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void setupSolrHome() throws Exception {
@@ -62,13 +62,14 @@ public class TestErrorResponseStackTrace extends SolrTestCaseJ4 {
+ " </requestHandler>\n"
+ "</config>"));
- solrRule.startSolr(LuceneTestCase.createTempDir());
- solrRule.newCollection().withConfigSet(configSet.toString()).create();
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.newCollection().withConfigSet(configSet).create();
}
@Test
public void testFullStackTrace() throws Exception {
- final String url = solrRule.getBaseUrl().toString() + "/collection1/withError?q=*:*&wt=json";
+ final String url =
+ solrTestRule.getBaseUrl().toString() + "/collection1/withError?q=*:*&wt=json";
final HttpGet get = new HttpGet(url);
var client = HttpClientUtil.createClient(null);
try (CloseableHttpResponse responseRaw = client.execute(get)) {
@@ -97,7 +98,7 @@ public class TestErrorResponseStackTrace extends SolrTestCaseJ4 {
@Test
@SuppressWarnings({"unchecked"})
public void testRemoteSolrException() {
- var client = solrRule.getSolrClient("collection1");
+ var client = solrTestRule.getSolrClient("collection1");
QueryRequest queryRequest =
new QueryRequest(new ModifiableSolrParams().set("q", "*:*").set("wt", "json"));
queryRequest.setPath("/withError");
diff --git a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java
index fc2754da254..76738839a1a 100644
--- a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java
+++ b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java
@@ -42,30 +42,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
- @ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final List<String> VALID_PROMETHEUS_VALUES = Arrays.asList("NaN", "+Inf", "-Inf");
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
- solrClientTestRule
- .newCollection("core1")
- .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET.toString())
- .create();
- solrClientTestRule
- .newCollection("core2")
- .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET.toString())
- .create();
- var cc = solrClientTestRule.getCoreContainer();
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.newCollection("core1").withConfigSet(ExternalPaths.DEFAULT_CONFIGSET).create();
+ solrTestRule.newCollection("core2").withConfigSet(ExternalPaths.DEFAULT_CONFIGSET).create();
+ var cc = solrTestRule.getCoreContainer();
cc.waitForLoadingCoresToFinish(30000);
// Populate request metrics on both cores
ModifiableSolrParams queryParams = new ModifiableSolrParams();
queryParams.set("q", "*:*");
- solrClientTestRule.getSolrClient("core1").query(queryParams);
- solrClientTestRule.getSolrClient("core2").query(queryParams);
+ solrTestRule.getSolrClient("core1").query(queryParams);
+ solrTestRule.getSolrClient("core2").query(queryParams);
}
@Test
@@ -75,7 +69,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
var req = new MetricsRequest(params);
req.setResponseParser(new InputStreamResponseParser("prometheus"));
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
String output = InputStreamResponseParser.consumeResponseToString(res);
@@ -126,7 +120,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
req.addHeader("Accept", "application/openmetrics-text;version=1.0.0");
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
try (InputStream in = (InputStream) res.get(STREAM_KEY)) {
@@ -144,7 +138,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
req.setResponseParser(new InputStreamResponseParser("openmetrics"));
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
try (InputStream in = (InputStream) res.get(STREAM_KEY)) {
@@ -162,7 +156,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
req.setResponseParser(new InputStreamResponseParser("prometheus"));
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
try (InputStream in = (InputStream) res.get(STREAM_KEY)) {
@@ -180,7 +174,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
req.setResponseParser(new InputStreamResponseParser(null));
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
try (InputStream in = (InputStream) res.get(STREAM_KEY)) {
@@ -198,7 +192,7 @@ public class TestPrometheusResponseWriter extends SolrTestCaseJ4 {
req.setResponseParser(new InputStreamResponseParser("unknownFormat"));
- try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) {
+ try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) {
NamedList<Object> res = adminClient.request(req);
assertEquals(400, res.get("responseStatus"));
}
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
index 0cc4ba3a989..c31877007d5 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
@@ -70,7 +70,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (restTestHarness != null) {
restTestHarness.close();
}
@@ -1437,7 +1437,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
@SuppressWarnings({"unchecked", "varargs"})
private static <T extends Similarity> void assertFieldSimilarity(
String fieldname, Class<T> expected, Consumer<T>... validators) {
- CoreContainer cc = solrClientTestRule.getCoreContainer();
+ CoreContainer cc = solrTestRule.getCoreContainer();
try (SolrCore core = cc.getCore("collection1")) {
SimilarityFactory simfac = core.getLatestSchema().getSimilarityFactory();
assertNotNull(simfac);
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
index f98a49f3f28..c990b09e8b0 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedStopFilterFactory.java
@@ -61,7 +61,7 @@ public class TestManagedStopFilterFactory extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
System.clearProperty("managed.schema.mutable");
System.clearProperty("solr.index.updatelog.enabled");
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
index 1c5cd9eac34..92d67591aa8 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/analysis/TestManagedSynonymGraphFilterFactory.java
@@ -62,7 +62,7 @@ public class TestManagedSynonymGraphFilterFactory extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (null != tmpSolrHome) {
PathUtils.deleteDirectory(tmpSolrHome);
}
diff --git a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
index daeac88eb92..f70f49991ff 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
@@ -16,15 +16,11 @@
*/
package org.apache.solr.schema;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.util.List;
-import java.util.Properties;
-import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
@@ -34,46 +30,34 @@ import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
-public class TestBinaryField extends SolrJettyTestBase {
+public class TestBinaryField extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void beforeTest() throws Exception {
Path homeDir = createTempDir();
-
Path collDir = homeDir.resolve("collection1");
- Path dataDir = collDir.resolve("data");
- Path confDir = collDir.resolve("conf");
- Files.createDirectories(homeDir);
- Files.createDirectories(collDir);
- Files.createDirectories(dataDir);
- Files.createDirectories(confDir);
+ copyMinConf(collDir, "name=collection1\n", "solrconfig-basic.xml");
- Files.copy(SolrTestCaseJ4.TEST_HOME().resolve("solr.xml"), homeDir.resolve("solr.xml"));
-
- String src_dir = TEST_HOME() + "/collection1/conf";
- Files.copy(Path.of(src_dir, "schema-binaryfield.xml"), confDir.resolve("schema.xml"));
- Files.copy(Path.of(src_dir, "solrconfig-basic.xml"), confDir.resolve("solrconfig.xml"));
+ // Copy the custom schema for binary field tests
+ String sourceConfDir = TEST_HOME() + "/collection1/conf";
Files.copy(
- Path.of(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
- confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
-
- try (Writer w =
- new OutputStreamWriter(
- Files.newOutputStream(collDir.resolve("core.properties")), StandardCharsets.UTF_8)) {
- Properties coreProps = new Properties();
- coreProps.put("name", "collection1");
- coreProps.store(w, "");
- }
+ Path.of(sourceConfDir, "schema-binaryfield.xml"),
+ collDir.resolve("conf/schema.xml"),
+ StandardCopyOption.REPLACE_EXISTING);
- createAndStartJetty(homeDir);
+ solrTestRule.startSolr(homeDir);
}
public void testSimple() throws Exception {
- try (SolrClient client = getSolrClient()) {
+ try (SolrClient client = solrTestRule.getSolrClient()) {
byte[] buf = new byte[10];
for (int i = 0; i < 10; i++) {
buf[i] = (byte) i;
diff --git a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored2.java b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored2.java
index ab6e9178287..f8e6d9874e0 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored2.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored2.java
@@ -45,7 +45,7 @@ public class TestUseDocValuesAsStored2 extends RestTestBase {
@After
public void after() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (restTestHarness != null) {
restTestHarness.close();
diff --git a/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java b/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java
index 2a1921a663a..7130e310e40 100644
--- a/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java
+++ b/solr/core/src/test/org/apache/solr/search/TestDocValuesIteratorCache.java
@@ -42,7 +42,7 @@ public class TestDocValuesIteratorCache extends SolrTestCaseJ4 {
private static final int DOC_COUNT = 1000;
@ClassRule
- public static final SolrClientTestRule solrClientTestRule =
+ public static final SolrClientTestRule solrTestRule =
new EmbeddedSolrServerTestRule() {
@Override
protected void before() throws Throwable {
@@ -82,9 +82,9 @@ public class TestDocValuesIteratorCache extends SolrTestCaseJ4 {
.replace(
"</schema>", fieldConfig(SINGLE, false) + fieldConfig(MULTI, true) + "</schema>"));
- solrClientTestRule.newCollection().withConfigSet(configSet.toString()).create();
+ solrTestRule.newCollection().withConfigSet(configSet).create();
- SolrClient client = solrClientTestRule.getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
Random r = random();
String[][] expectVals = indexDocs(client, r);
diff --git a/solr/core/src/test/org/apache/solr/search/TestThinCache.java b/solr/core/src/test/org/apache/solr/search/TestThinCache.java
index 55717b7d015..02e3a529edb 100644
--- a/solr/core/src/test/org/apache/solr/search/TestThinCache.java
+++ b/solr/core/src/test/org/apache/solr/search/TestThinCache.java
@@ -41,7 +41,9 @@ import org.junit.Test;
/** Test for {@link ThinCache}. */
public class TestThinCache extends SolrTestCaseJ4 {
- @ClassRule public static EmbeddedSolrServerTestRule solrRule = new EmbeddedSolrServerTestRule();
+ @ClassRule
+ public static EmbeddedSolrServerTestRule solrTestRule = new EmbeddedSolrServerTestRule();
+
public static final String SOLR_NODE_LEVEL_CACHE_XML =
"<solr>\n"
+ " <caches>\n"
@@ -62,7 +64,7 @@ public class TestThinCache extends SolrTestCaseJ4 {
Path home = createTempDir("home");
Files.writeString(home.resolve("solr.xml"), SOLR_NODE_LEVEL_CACHE_XML);
- solrRule.startSolr(home);
+ solrTestRule.startSolr(home);
Path configSet = createTempDir("configSet");
copyMinConf(configSet);
@@ -81,16 +83,15 @@ public class TestThinCache extends SolrTestCaseJ4 {
+ " initialSize=\"5\"/>\n"
+ "</query></config>"));
- solrRule.newCollection().withConfigSet(configSet.toString()).create();
+ solrTestRule.newCollection().withConfigSet(configSet).create();
// legacy; get rid of this someday!
- h = new TestHarness(solrRule.getCoreContainer());
+ h = new TestHarness(solrTestRule.getCoreContainer());
lrf = h.getRequestFactory("/select", 0, 20);
}
SolrMetricManager metricManager = new SolrMetricManager(null);
String registry = TestUtil.randomSimpleString(random(), 2, 10);
- String scope = TestUtil.randomSimpleString(random(), 2, 10);
@Test
public void testSimple() {
@@ -162,7 +163,7 @@ public class TestThinCache extends SolrTestCaseJ4 {
}
@Test
- public void testInitCore() throws Exception {
+ public void testInitCore() {
String thinCacheName = "myNodeLevelCacheThin";
String nodeCacheName = "myNodeLevelCache";
for (int i = 0; i < 20; i++) {
diff --git a/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java
index 7c5a87bc5b1..1339d1d64b2 100644
--- a/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java
+++ b/solr/core/src/test/org/apache/solr/search/json/TestJsonRequestWithEdismaxDefType.java
@@ -29,18 +29,17 @@ import org.junit.ClassRule;
public class TestJsonRequestWithEdismaxDefType extends SolrTestCaseJ4 {
- @ClassRule
- public static final SolrClientTestRule solrClientTestRule = new EmbeddedSolrServerTestRule();
+ @ClassRule public static final SolrClientTestRule solrTestRule = new EmbeddedSolrServerTestRule();
public void test() throws Exception {
- solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
Path configSet = LuceneTestCase.createTempDir();
SolrTestCaseJ4.copyMinConf(configSet);
- solrClientTestRule.newCollection().withConfigSet(configSet.toString()).create();
+ solrTestRule.newCollection().withConfigSet(configSet).create();
- SolrClient client = solrClientTestRule.getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
client.request(
new ConfigRequest(
diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
index ea57cec5bf2..9e905c04bab 100644
--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
@@ -16,15 +16,13 @@
*/
package org.apache.solr.servlet;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Arrays;
import java.util.Date;
+import java.util.Properties;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.client.utils.DateUtils;
import org.apache.solr.common.util.SuppressForbidden;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -34,12 +32,27 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- System.setProperty(
- "solr.requests.streaming.remote.enabled", "true"); // needed for testCacheVetoHandler
+ // System properties are required by collection1 solrconfig.xml propTest configuration
+ // These cannot be removed as they are used for property substitution in the config
+ System.setProperty("solr.test.sys.prop1", "propone");
+ System.setProperty("solr.test.sys.prop2", "proptwo");
Path solrHomeDirectory = createTempDir();
- setupJettyTestHome(solrHomeDirectory, "collection1");
- createAndStartJetty(solrHomeDirectory);
+ copySolrHomeToTemp(solrHomeDirectory, "collection1");
+
+ Path coresDir = createTempDir().resolve("cores");
+ Properties props = new Properties();
+ props.setProperty("name", DEFAULT_TEST_CORENAME);
+ props.setProperty("configSet", "collection1");
+
+ writeCoreProperties(coresDir.resolve("core"), props, "CacheHeaderTest");
+
+ Properties nodeProps = new Properties();
+ nodeProps.setProperty("coreRootDirectory", coresDir.toString());
+ nodeProps.setProperty("configSetBaseDir", solrHomeDirectory.toString());
+
+ solrTestRule.startSolr(
+ solrHomeDirectory, nodeProps, org.apache.solr.embedded.JettyConfig.builder().build());
}
@Test
@@ -48,11 +61,11 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
// We force an exception from Solr. This should emit "no-cache" HTTP headers
HttpResponse response = getHttpClient().execute(m);
assertNotEquals(200, response.getStatusLine().getStatusCode());
- checkVetoHeaders(response, false);
+ checkVetoHeaders(response);
}
@SuppressForbidden(reason = "Needs currentTimeMillis to check against expiry headers from Solr")
- protected void checkVetoHeaders(HttpResponse response, boolean checkExpires) throws Exception {
+ protected void checkVetoHeaders(HttpResponse response) {
Header head = response.getFirstHeader("Cache-Control");
assertNotNull("We got no Cache-Control header", head);
assertTrue(
@@ -65,15 +78,6 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
head = response.getFirstHeader("Pragma");
assertNotNull("We got no Pragma header", head);
assertEquals("no-cache", head.getValue());
-
- if (checkExpires) {
- head = response.getFirstHeader("Expires");
- assertNotNull("We got no Expires header:" + Arrays.asList(response.getAllHeaders()), head);
- Date d = DateUtils.parseDate(head.getValue());
- assertTrue(
- "We got no Expires header far in the past",
- System.currentTimeMillis() - d.getTime() > 100000);
- }
}
@Override
@@ -245,14 +249,4 @@ public class CacheHeaderTest extends CacheHeaderTestBase {
assertNotNull("We got no Expires header in response", head);
}
}
-
- protected Path makeFile(String contents, String charset) {
- try {
- Path f = createTempFile("cachetest", "csv");
- Files.writeString(f, contents, Charset.forName(charset));
- return f;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
}
diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
index 5f25e8140d8..be2cf963146 100644
--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTestBase.java
@@ -20,6 +20,7 @@ import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
@@ -27,10 +28,15 @@ import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.apache.HttpSolrClient;
+import org.apache.solr.util.SolrJettyTestRule;
+import org.junit.ClassRule;
import org.junit.Test;
-public abstract class CacheHeaderTestBase extends SolrJettyTestBase {
+public abstract class CacheHeaderTestBase extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
protected HttpRequestBase getSelectMethod(String method, String... params) {
HttpRequestBase m = null;
@@ -46,7 +52,7 @@ public abstract class CacheHeaderTestBase extends SolrJettyTestBase {
URI uri =
URI.create(
- getBaseUrl()
+ solrTestRule.getBaseUrl()
+ "/"
+ DEFAULT_TEST_COLLECTION_NAME
+ "/select?"
@@ -63,31 +69,9 @@ public abstract class CacheHeaderTestBase extends SolrJettyTestBase {
return m;
}
- HttpRequestBase getUpdateMethod(String method, String... params) {
- HttpRequestBase m = null;
-
- ArrayList<BasicNameValuePair> qparams = new ArrayList<>();
- for (int i = 0; i < params.length / 2; i++) {
- qparams.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1]));
- }
-
- URI uri =
- URI.create(
- getBaseUrl()
- + "/"
- + DEFAULT_TEST_COLLECTION_NAME
- + "/update?"
- + URLEncodedUtils.format(qparams, StandardCharsets.UTF_8));
-
- if ("GET".equals(method)) {
- m = new HttpGet(uri);
- } else if ("POST".equals(method)) {
- m = new HttpPost(uri);
- } else if ("HEAD".equals(method)) {
- m = new HttpHead(uri);
- }
-
- return m;
+ protected HttpClient getHttpClient() {
+ HttpSolrClient client = (HttpSolrClient) solrTestRule.getSolrClient();
+ return client.getHttpClient();
}
protected void checkResponseBody(String method, HttpResponse resp) throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/servlet/HideStackTraceTest.java b/solr/core/src/test/org/apache/solr/servlet/HideStackTraceTest.java
index db58af874c2..1b589cf5687 100644
--- a/solr/core/src/test/org/apache/solr/servlet/HideStackTraceTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/HideStackTraceTest.java
@@ -38,7 +38,7 @@ import org.junit.Test;
@SuppressSSL
public class HideStackTraceTest extends SolrTestCaseJ4 {
- @ClassRule public static final SolrJettyTestRule solrRule = new SolrJettyTestRule();
+ @ClassRule public static final SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void setupSolrHome() throws Exception {
@@ -62,8 +62,8 @@ public class HideStackTraceTest extends SolrTestCaseJ4 {
+ " </requestHandler>\n"
+ "</config>"));
- solrRule.startSolr(LuceneTestCase.createTempDir());
- solrRule.newCollection().withConfigSet(configSet.toString()).create();
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.newCollection().withConfigSet(configSet).create();
}
@AfterClass
@@ -143,7 +143,8 @@ public class HideStackTraceTest extends SolrTestCaseJ4 {
// }
// }
- final String url = solrRule.getBaseUrl().toString() + "/collection1/withError?q=*:*&wt=json";
+ final String url =
+ solrTestRule.getBaseUrl().toString() + "/collection1/withError?q=*:*&wt=json";
final HttpGet get = new HttpGet(url);
var client = HttpClientUtil.createClient(null);
try (CloseableHttpResponse response = client.execute(get)) {
diff --git a/solr/core/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java
index 02e5f2422be..409367cbf1c 100644
--- a/solr/core/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/NoCacheHeaderTest.java
@@ -16,22 +16,31 @@
*/
package org.apache.solr.servlet;
+import java.nio.file.Path;
import java.util.Date;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.client.utils.DateUtils;
import org.apache.solr.common.util.SuppressForbidden;
import org.junit.BeforeClass;
import org.junit.Test;
/** A test case for the several HTTP cache headers emitted by Solr */
public class NoCacheHeaderTest extends CacheHeaderTestBase {
- // TODO: fix this test not to directly use the test-files copied to build/
- // as its home. it could interfere with other tests!
+
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(TEST_HOME(), "solr/collection1/conf/solrconfig-nocache.xml", null);
+ Path solrHome = createTempDir();
+ Path collectionDirectory = solrHome.resolve(DEFAULT_TEST_COLLECTION_NAME);
+
+ // Create minimal config with custom nocache solrconfig
+ copyMinConf(
+ collectionDirectory,
+ "name=" + DEFAULT_TEST_COLLECTION_NAME + "\n",
+ "solrconfig-nocache.xml");
+
+ solrTestRule.startSolr(solrHome);
}
// The tests
diff --git a/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java
index 8db6e6c7e66..37b8df1870a 100644
--- a/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/ResponseHeaderTest.java
@@ -24,52 +24,59 @@ import java.nio.file.StandardCopyOption;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.apache.HttpClientUtil;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
-import org.junit.AfterClass;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class ResponseHeaderTest extends SolrJettyTestBase {
+public class ResponseHeaderTest extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static Path solrHomeDirectory;
@BeforeClass
public static void beforeTest() throws Exception {
solrHomeDirectory = createTempDir();
- setupJettyTestHome(solrHomeDirectory, "collection1");
- String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
+ Path collectionDirectory = solrHomeDirectory.resolve("collection1");
+
Files.copy(
- Path.of(top, "solrconfig-headers.xml"),
- Path.of(solrHomeDirectory + "/collection1/conf", "solrconfig.xml"),
+ SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"),
+ solrHomeDirectory.resolve("solr.xml"),
StandardCopyOption.REPLACE_EXISTING);
- createAndStartJetty(solrHomeDirectory);
- }
- @AfterClass
- public static void afterTest() throws Exception {
- if (null != solrHomeDirectory) {
- cleanUpJettyHome(solrHomeDirectory);
- }
+ // Create minimal config with custom solrconfig for headers testing
+ SolrTestCaseJ4.copyMinConf(collectionDirectory, "name=collection1\n", "solrconfig-headers.xml");
+
+ solrTestRule.startSolr(solrHomeDirectory);
}
@Test
public void testHttpResponse() throws IOException {
- URI uri = URI.create(getBaseUrl() + "/collection1/withHeaders?q=*:*");
+ URI uri = URI.create(solrTestRule.getBaseUrl() + "/collection1/withHeaders?q=*:*");
HttpGet httpGet = new HttpGet(uri);
- HttpResponse response = getHttpClient().execute(httpGet);
- Header[] headers = response.getAllHeaders();
- boolean containsWarningHeader = false;
- for (Header header : headers) {
- if ("Warning".equals(header.getName())) {
- containsWarningHeader = true;
- assertEquals("This is a test warning", header.getValue());
- break;
+ CloseableHttpClient httpClient = HttpClientUtil.createClient(null);
+ try {
+ HttpResponse response = httpClient.execute(httpGet);
+ Header[] headers = response.getAllHeaders();
+ boolean containsWarningHeader = false;
+ for (Header header : headers) {
+ if ("Warning".equals(header.getName())) {
+ containsWarningHeader = true;
+ assertEquals("This is a test warning", header.getValue());
+ break;
+ }
}
+ assertTrue("Expected header not found", containsWarningHeader);
+
+ } finally {
+ HttpClientUtil.close(httpClient);
}
- assertTrue("Expected header not found", containsWarningHeader);
}
public static class ComponentThatAddsHeader extends SearchComponent {
diff --git a/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java b/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java
index de20b5a728f..03bc0503924 100644
--- a/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java
+++ b/solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java
@@ -34,12 +34,12 @@ import org.junit.ClassRule;
public class CustomTLogDirTest extends SolrTestCaseJ4 {
@ClassRule
- public static final SolrClientTestRule solrClientTestRule =
+ public static final SolrClientTestRule solrTestRule =
new EmbeddedSolrServerTestRule() {
@Override
protected void before() {
System.setProperty("solr.directoryFactory", "solr.NRTCachingDirectoryFactory");
- solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
}
};
@@ -47,7 +47,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
public void testExternal() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
- SolrClient client = solrClientTestRule.getSolrClient(collectionName);
+ SolrClient client = solrTestRule.getSolrClient(collectionName);
Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
@@ -63,7 +63,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
public void testRelative() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
- SolrClient client = solrClientTestRule.getSolrClient(collectionName);
+ SolrClient client = solrTestRule.getSolrClient(collectionName);
Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
@@ -89,16 +89,12 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
// check that this config is unsuccessful
expectThrows(
Exception.class,
- () ->
- solrClientTestRule
- .newCollection("illegal")
- .withConfigSet(configSet.toString())
- .create());
+ () -> solrTestRule.newCollection("illegal").withConfigSet(configSet).create());
}
public void testAbsoluteSubdir() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
- SolrClient client = solrClientTestRule.getSolrClient(collectionName);
+ SolrClient client = solrTestRule.getSolrClient(collectionName);
Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
@@ -114,7 +110,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
public void testDefault() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
- SolrClient client = solrClientTestRule.getSolrClient(collectionName);
+ SolrClient client = solrTestRule.getSolrClient(collectionName);
Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
@@ -128,7 +124,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
public void testExplicitDefault() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
- SolrClient client = solrClientTestRule.getSolrClient(collectionName);
+ SolrClient client = solrTestRule.getSolrClient(collectionName);
Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
@@ -153,7 +149,7 @@ public class CustomTLogDirTest extends SolrTestCaseJ4 {
String collectionName = instanceDir.getFileName().toString();
- solrClientTestRule.newCollection(collectionName).withConfigSet(configSet.toString()).create();
+ solrTestRule.newCollection(collectionName).withConfigSet(configSet).create();
// resolvedTlogDir = instanceDir.resolve("data/tlog"); // legacy impl _always_ resulted in this
diff --git a/solr/core/src/test/org/apache/solr/update/RootFieldTest.java b/solr/core/src/test/org/apache/solr/update/RootFieldTest.java
index 1c436829d24..fce3c5e5ff8 100644
--- a/solr/core/src/test/org/apache/solr/update/RootFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/update/RootFieldTest.java
@@ -50,18 +50,14 @@ public class RootFieldTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- solrClientTestRule.startSolr(SolrTestCaseJ4.TEST_HOME());
+ solrTestRule.startSolr(SolrTestCaseJ4.TEST_HOME());
useRootSchema = random().nextBoolean();
// schema15.xml declares _root_ field, while schema-rest.xml does not.
String schema = useRootSchema ? "schema15.xml" : "schema-rest.xml";
SolrTestCaseJ4.newRandomConfig();
- solrClientTestRule
- .newCollection()
- .withConfigSet("../collection1")
- .withSchemaFile(schema)
- .create();
+ solrTestRule.newCollection().withConfigSet("../collection1").withSchemaFile(schema).create();
}
@Test
diff --git a/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java b/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java
index a4bdac64b11..f885311cf10 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java
@@ -45,12 +45,12 @@ public abstract class AbstractAtomicUpdatesMultivalueTestBase extends EmbeddedSo
protected static void initWithRequestWriter(RequestWriterSupplier requestWriterSupplier)
throws Exception {
- solrClientTestRule.startSolr(SolrTestCaseJ4.TEST_HOME());
+ solrTestRule.startSolr(SolrTestCaseJ4.TEST_HOME());
System.setProperty("solr.index.updatelog.enabled", "true");
SolrTestCaseJ4.newRandomConfig();
- solrClientTestRule.newCollection().withConfigSet("../collection1").create();
+ solrTestRule.newCollection().withConfigSet("../collection1").create();
}
@Before
diff --git a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/TestLanguageModelBase.java b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/TestLanguageModelBase.java
index 5c8d10ac926..ea02c0f0e8c 100644
--- a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/TestLanguageModelBase.java
+++ b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/TestLanguageModelBase.java
@@ -82,7 +82,7 @@ public class TestLanguageModelBase extends RestTestBase {
restTestHarness.close();
restTestHarness = null;
}
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (null != tmpSolrHome) {
PathUtils.deleteDirectory(tmpSolrHome);
tmpSolrHome = null;
diff --git a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java
index c8b063bd129..5ccb9d95e60 100644
--- a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java
+++ b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorFactoryTest.java
@@ -47,7 +47,7 @@ public class TextToVectorUpdateProcessorFactoryTest extends TestLanguageModelBas
@Before
public void setup() {
- collection1 = solrClientTestRule.getCoreContainer().getCore("collection1");
+ collection1 = solrTestRule.getCoreContainer().getCore("collection1");
}
@After
diff --git a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorTest.java b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorTest.java
index 4354c1a69e3..2dd9cda1a58 100644
--- a/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorTest.java
+++ b/solr/modules/language-models/src/test/org/apache/solr/languagemodels/textvectorisation/update/processor/TextToVectorUpdateProcessorTest.java
@@ -236,6 +236,6 @@ public class TextToVectorUpdateProcessorTest extends TestLanguageModelBase {
UpdateRequest req = new UpdateRequest();
req.add(document);
req.setParam("update.chain", updateChain);
- solrClientTestRule.getSolrClient("collection1").request(req);
+ solrTestRule.getSolrClient("collection1").request(req);
}
}
diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestFeatureVectorCache.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestFeatureVectorCache.java
index 832944ba9a5..7ead428e1cd 100644
--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestFeatureVectorCache.java
+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestFeatureVectorCache.java
@@ -45,7 +45,7 @@ public class TestFeatureVectorCache extends TestRerankBase {
loadFeatures("featurevectorcache_features.json");
loadModels("featurevectorcache_linear_model.json");
- core = solrClientTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME);
+ core = solrTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME);
}
@After
diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java
index 2ee0c1ebdd0..30037e3bc2d 100644
--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java
+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java
@@ -127,13 +127,13 @@ public class TestRerankBase extends RestTestBase {
}
public static ManagedFeatureStore getManagedFeatureStore() {
- try (SolrCore core = solrClientTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
+ try (SolrCore core = solrTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
return ManagedFeatureStore.getManagedFeatureStore(core);
}
}
public static ManagedModelStore getManagedModelStore() {
- try (SolrCore core = solrClientTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
+ try (SolrCore core = solrTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
return ManagedModelStore.getManagedModelStore(core);
}
}
@@ -198,7 +198,7 @@ public class TestRerankBase extends RestTestBase {
restTestHarness.close();
restTestHarness = null;
}
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (null != tmpSolrHome) {
PathUtils.deleteDirectory(tmpSolrHome);
tmpSolrHome = null;
diff --git a/solr/modules/sql/src/test/org/apache/solr/handler/sql/TestSQLHandlerNonCloud.java b/solr/modules/sql/src/test/org/apache/solr/handler/sql/TestSQLHandlerNonCloud.java
index ff8a19085a1..8bb82fd41b0 100644
--- a/solr/modules/sql/src/test/org/apache/solr/handler/sql/TestSQLHandlerNonCloud.java
+++ b/solr/modules/sql/src/test/org/apache/solr/handler/sql/TestSQLHandlerNonCloud.java
@@ -20,35 +20,42 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.stream.SolrStream;
import org.apache.solr.client.solrj.io.stream.TupleStream;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.IOUtils;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class TestSQLHandlerNonCloud extends SolrJettyTestBase {
+public class TestSQLHandlerNonCloud extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static Path createSolrHome() throws Exception {
- Path workDir = createTempDir();
- setupJettyTestHome(workDir, DEFAULT_TEST_COLLECTION_NAME);
+ Path workDir = createTempDir().toRealPath();
+ Path collectionDirectory = workDir.resolve(DEFAULT_TEST_COLLECTION_NAME);
+
+ copyMinConf(collectionDirectory, "name=" + DEFAULT_TEST_COLLECTION_NAME + "\n");
+
return workDir;
}
@BeforeClass
public static void beforeClass() throws Exception {
Path solrHome = createSolrHome();
- createAndStartJetty(solrHome);
+ solrTestRule.startSolr(solrHome);
}
@Test
public void testSQLHandler() throws Exception {
String sql = "select id, field_i, str_s from " + DEFAULT_TEST_COLLECTION_NAME + " limit 10";
SolrParams sParams = params(CommonParams.QT, "/sql", "stmt", sql);
- String url = getBaseUrl() + "/" + DEFAULT_TEST_COLLECTION_NAME;
+ String url = solrTestRule.getBaseUrl() + "/" + DEFAULT_TEST_COLLECTION_NAME;
SolrStream solrStream = new SolrStream(url, sParams);
IOException ex = expectThrows(IOException.class, () -> getTuples(solrStream));
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java
index 15c7944dd9a..dd2b02d25eb 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java
@@ -34,12 +34,9 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
}
@Before
@@ -148,7 +145,7 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@Test
public void testGetIdsWithParams() throws Exception {
SolrDocumentList rsp =
- solrClientTestRule
+ solrTestRule
.getSolrClient()
.getById(Arrays.asList("0", "1", "2"), params(CommonParams.FL, "id"));
assertEquals(2, rsp.getNumFound());
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
index b01faa27437..8dc258df5bc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryHttp2Test.java
@@ -33,7 +33,7 @@ public class SolrExampleBinaryHttp2Test extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
index affddd7776c..ce47301c227 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java
@@ -30,7 +30,7 @@ import org.junit.BeforeClass;
public class SolrExampleBinaryTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleCborTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleCborTest.java
index 7b043c48e3f..b281a4557ce 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleCborTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleCborTest.java
@@ -47,7 +47,7 @@ import org.junit.Ignore;
public class SolrExampleCborTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
index 759dd72a153..bb3c7df6804 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -87,7 +87,7 @@ import org.slf4j.LoggerFactory;
/**
* This should include tests against the example solr config
*
- * <p>This lets us try various SolrServer implementations with the same tests.
+ * <p>This lets us try various SolrClient implementations with the same tests.
*
* @since solr 1.3
*/
@@ -95,10 +95,6 @@ import org.slf4j.LoggerFactory;
public abstract class SolrExampleTests extends SolrExampleTestsBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- static {
- ignoreException("uniqueKey");
- }
-
@Before
public void emptyCollection() throws Exception {
SolrClient client = getSolrClient();
@@ -436,7 +432,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
assertEquals("price:[* TO 2]", values.get(0));
assertEquals("price:[2 TO 4]", values.get(1));
- if (getJetty() != null) {
+ if (solrTestRule.getJetty() != null) {
// check system wide system handler + "/admin/info/system"
String url = getBaseUrl();
try (SolrClient adminClient = getHttpSolrClient(url)) {
@@ -649,7 +645,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
}
private String randomTestString(int maxLength) {
- // we can't just use _TestUtil.randomUnicodeString() or we might get 0xfffe etc
+ // we can't just use _TestUtil.randomUnicodeString() or we might get 0xfffe etc.
// (considered invalid by XML)
int size = random().nextInt(maxLength);
@@ -1012,11 +1008,11 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
List<Pair<NamedList<String>, Object>> docs = new ArrayList<>();
NamedList<String> params = new NamedList<>();
- docs.add(new Pair<>(params, getFileContent(params, "solrj/docs1.xml")));
+ docs.add(new Pair<>(params, getFileContent("solrj/docs1.xml")));
params = new NamedList<>();
params.add(ASSUME_CONTENT_TYPE, "application/csv");
- docs.add(new Pair<>(params, getFileContent(params, "solrj/books.csv")));
+ docs.add(new Pair<>(params, getFileContent("solrj/books.csv")));
MultiContentWriterRequest up =
new MultiContentWriterRequest(SolrRequest.METHOD.POST, "/update", docs.iterator());
@@ -1027,7 +1023,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
assertEquals(12, rsp.getResults().getNumFound());
}
- private ByteBuffer getFileContent(NamedList<?> nl, String name) throws IOException {
+ private ByteBuffer getFileContent(String name) throws IOException {
try (InputStream is = new FileInputStream(getFile(name).toFile())) {
return MultiContentWriterRequest.readByteBuffer(is);
}
@@ -2375,12 +2371,12 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
client.commit(); // Since the transaction log is disabled in the example, we need to commit
SolrQuery q = new SolrQuery();
- q.setRequestHandler("/get");
q.set("id", "DOCID");
q.set("fl", "id,name,aaa:[value v=aaa]");
// First Try with the BinaryResponseParser
QueryRequest req = new QueryRequest(q);
+ req.setPath("/get");
req.setResponseParser(new JavaBinResponseParser());
QueryResponse rsp = req.process(client);
SolrDocument out = (SolrDocument) rsp.getResponse().get("doc");
@@ -2669,7 +2665,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
// between
{
q = new SolrQuery("q", "level_i:0", "indent", "true");
- // NOTE: should be impossible to have more then 7 direct kids, or more then 49 grandkids
+ // NOTE: should be impossible to have more than 7 direct kids, or more than 49 grandkids
q.setFields(
"id", "[child parentFilter=\"level_i:0\" limit=100 childFilter=\"level_i:1\"]",
"name", "[child parentFilter=\"level_i:0\" limit=100 childFilter=\"level_i:2\"]");
@@ -3015,12 +3011,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
@Test
public void testAddChildToChildFreeDoc()
- throws IOException,
- SolrServerException,
- IllegalArgumentException,
- IllegalAccessException,
- SecurityException,
- NoSuchFieldException {
+ throws IOException, SolrServerException, IllegalArgumentException, SecurityException {
SolrClient client = getSolrClient();
client.deleteByQuery("*:*");
@@ -3062,12 +3053,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
@Test
public void testDeleteParentDoc()
- throws IOException,
- SolrServerException,
- IllegalArgumentException,
- IllegalAccessException,
- SecurityException,
- NoSuchFieldException {
+ throws IOException, SolrServerException, IllegalArgumentException, SecurityException {
SolrClient client = getSolrClient();
client.deleteByQuery("*:*");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestsBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestsBase.java
index b8e5b2752bf..efb1119763e 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestsBase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTestsBase.java
@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -32,15 +32,19 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.TimeSource;
+import org.apache.solr.util.SolrJettyTestRule;
import org.apache.solr.util.TimeOut;
-import org.junit.After;
+import org.junit.ClassRule;
import org.junit.Test;
-public abstract class SolrExampleTestsBase extends SolrJettyTestBase {
+public abstract class SolrExampleTestsBase extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
private SolrClient client;
- @After
- public void after() {
+ @Override
+ public void tearDown() throws Exception {
if (client != null) {
try {
client.close();
@@ -49,10 +53,10 @@ public abstract class SolrExampleTestsBase extends SolrJettyTestBase {
}
}
client = null;
+ super.tearDown();
}
- @Override
- public SolrClient getSolrClient() {
+ protected SolrClient getSolrClient() {
if (client == null) {
client = createNewSolrClient();
}
@@ -60,15 +64,24 @@ public abstract class SolrExampleTestsBase extends SolrJettyTestBase {
}
/**
- * Create a new solr client. If createJetty was called, a http implementation will be created,
+ * Create a new solr client. If createJetty was called, an http implementation will be created,
* otherwise an embedded implementation will be created. Subclasses should override for other
* options.
*/
- @Override
public SolrClient createNewSolrClient() {
- return getHttpSolrClient(getBaseUrl(), DEFAULT_TEST_CORENAME);
+ return SolrTestCaseJ4.getHttpSolrClient(solrTestRule.getBaseUrl(), DEFAULT_TEST_CORENAME);
}
+ protected static String getCoreUrl() {
+ return solrTestRule.getBaseUrl() + "/" + DEFAULT_TEST_CORENAME;
+ }
+
+ protected static String getBaseUrl() {
+ return solrTestRule.getBaseUrl();
+ }
+
+ // Backward compatibility methods for existing subclasses
+
/** query the example */
@Test
public void testCommitWithinOnAdd() throws Exception {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
index 5d88eb1f331..902fc5f4681 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java
@@ -30,7 +30,7 @@ import org.junit.BeforeClass;
public class SolrExampleXMLTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
index 9dbdf2b4991..6b6aefc9939 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java
@@ -42,6 +42,11 @@ import org.junit.Test;
public class SolrSchemalessExampleTest extends SolrExampleTestsBase {
+ protected HttpClient getHttpClient() {
+ HttpSolrClient client = (HttpSolrClient) getSolrClient();
+ return client.getHttpClient();
+ }
+
@BeforeClass
public static void beforeClass() throws Exception {
Path tempSolrHome = createTempDir();
@@ -56,22 +61,13 @@ public class SolrSchemalessExampleTest extends SolrExampleTestsBase {
PathUtils.copyDirectory(ExternalPaths.DEFAULT_CONFIGSET, collection1Dir);
Properties props = new Properties();
props.setProperty("name", "collection1");
- OutputStreamWriter writer = null;
- try {
- writer =
- new OutputStreamWriter(
- PathUtils.newOutputStream(collection1Dir.resolve("core.properties"), false),
- StandardCharsets.UTF_8);
+ try (OutputStreamWriter writer =
+ new OutputStreamWriter(
+ PathUtils.newOutputStream(collection1Dir.resolve("core.properties"), false),
+ StandardCharsets.UTF_8)) {
props.store(writer, null);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (Exception ignore) {
- }
- }
}
- createAndStartJetty(tempSolrHome);
+ solrTestRule.startSolr(tempSolrHome);
}
@Test
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java
index a6bb47eda3e..32165843828 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestBatchUpdate.java
@@ -18,7 +18,7 @@ package org.apache.solr.client.solrj;
import java.io.IOException;
import java.util.Iterator;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
import org.apache.solr.client.solrj.beans.Field;
@@ -27,7 +27,10 @@ import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.XMLRequestWriter;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.util.ExternalPaths;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
/**
@@ -36,11 +39,17 @@ import org.junit.Test;
* @since solr 1.4
*/
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
-public class TestBatchUpdate extends SolrJettyTestBase {
+public class TestBatchUpdate extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(createTempDir());
+ solrTestRule
+ .newCollection("collection1")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
}
static final int numdocs = 1000;
@@ -48,7 +57,7 @@ public class TestBatchUpdate extends SolrJettyTestBase {
@Test
public void testWithXml() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withRequestWriter(new XMLRequestWriter())
.build()) {
@@ -60,7 +69,7 @@ public class TestBatchUpdate extends SolrJettyTestBase {
@Test
public void testWithBinary() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withRequestWriter(new JavaBinRequestWriter())
.build()) {
@@ -72,7 +81,7 @@ public class TestBatchUpdate extends SolrJettyTestBase {
@Test
public void testWithBinaryBean() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withRequestWriter(new JavaBinRequestWriter())
.build()) {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
index ea3602b5f7d..7795057a109 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestSolrJErrorHandling.java
@@ -35,27 +35,36 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
import org.apache.solr.client.solrj.request.JavaBinRequestWriter;
import org.apache.solr.client.solrj.request.XMLRequestWriter;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.util.ExternalPaths;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
-public class TestSolrJErrorHandling extends SolrJettyTestBase {
+public class TestSolrJErrorHandling extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
List<Throwable> unexpected = new CopyOnWriteArrayList<>();
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(createTempDir());
+ solrTestRule
+ .newCollection("collection1")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
}
@Override
@@ -102,7 +111,7 @@ public class TestSolrJErrorHandling extends SolrJettyTestBase {
@Test
public void testWithXml() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withRequestWriter(new XMLRequestWriter())
.build()) {
@@ -114,7 +123,7 @@ public class TestSolrJErrorHandling extends SolrJettyTestBase {
@Test
public void testWithBinary() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withRequestWriter(new JavaBinRequestWriter())
.build()) {
@@ -277,7 +286,7 @@ public class TestSolrJErrorHandling extends SolrJettyTestBase {
// sometimes succeeds with this size, but larger can cause OOM from command line
String bodyString = getJsonDocs(200000);
- String urlString = getCoreUrl() + "/update";
+ String urlString = solrTestRule.getBaseUrl() + "/update";
HttpURLConnection conn = null;
URL url = URI.create(urlString).toURL();
@@ -330,7 +339,7 @@ public class TestSolrJErrorHandling extends SolrJettyTestBase {
public void testRawSocket() throws Exception {
String hostName = "127.0.0.1";
- int port = getJetty().getLocalPort();
+ int port = solrTestRule.getJetty().getLocalPort();
try (Socket socket = new Socket(hostName, port);
OutputStream out = new BufferedOutputStream(socket.getOutputStream());
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
index 5d65ff8725d..6a1fac16cbd 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
@@ -40,7 +40,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends SolrTestCaseJ4
protected CoreContainer cores = null;
- @Rule public EmbeddedSolrServerTestRule solrClientTestRule = new EmbeddedSolrServerTestRule();
+ @Rule public EmbeddedSolrServerTestRule solrTestRule = new EmbeddedSolrServerTestRule();
@Rule public TestRule testRule = new SystemPropertiesRestoreRule();
@@ -70,9 +70,9 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends SolrTestCaseJ4
System.setProperty("tempDir", tempDir.toString());
SolrTestCaseJ4.newRandomConfig();
- solrClientTestRule.startSolr(SOLR_HOME);
+ solrTestRule.startSolr(SOLR_HOME);
- cores = solrClientTestRule.getCoreContainer();
+ cores = solrTestRule.getCoreContainer();
}
@Override
@@ -111,6 +111,6 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends SolrTestCaseJ4
}
protected SolrClient getSolrAdmin() {
- return solrClientTestRule.getAdminClient();
+ return solrTestRule.getAdminClient();
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeBinaryJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeBinaryJettyTest.java
index 41f99eb7810..59d765ddfe7 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeBinaryJettyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeBinaryJettyTest.java
@@ -28,11 +28,8 @@ import org.junit.BeforeClass;
public class LargeVolumeBinaryJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java
index e9c473f9572..a558e1c345a 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java
@@ -23,11 +23,8 @@ import org.junit.BeforeClass;
public class LargeVolumeEmbeddedTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java
index de56408cb95..b171f622b69 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java
@@ -24,11 +24,8 @@ public class LargeVolumeJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
// TODO
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
index 87ad1469743..79b24092a0e 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
@@ -28,6 +28,6 @@ public class SolrExampleEmbeddedTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
index 145f4b6c027..071b9ee7ffb 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
@@ -19,8 +19,6 @@ package org.apache.solr.client.solrj.embedded;
import static org.apache.solr.common.util.Utils.fromJSONString;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.stream.Collectors;
@@ -32,7 +30,6 @@ import org.apache.http.entity.InputStreamEntity;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrExampleTests;
-import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.apache.HttpClientUtil;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
import org.apache.solr.client.solrj.request.SolrQuery;
@@ -41,8 +38,6 @@ import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* TODO? perhaps use: http://docs.codehaus.org/display/JETTY/ServletTester rather then open a real
@@ -50,11 +45,10 @@ import org.slf4j.LoggerFactory;
*/
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
public class SolrExampleJettyTest extends SolrExampleTests {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Test
@@ -125,13 +119,4 @@ public class SolrExampleJettyTest extends SolrExampleTests {
assertEquals(1, rsp.getResults().getNumFound());
}
}
-
- private void runQueries(SolrClient client, int count, boolean warmup)
- throws SolrServerException, IOException {
- long start = System.nanoTime();
- for (int i = 0; i < count; i++) {
- client.query(new SolrQuery("*:*"));
- }
- if (warmup) return;
- }
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
index 7e7abe54be2..bac599266ad 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
@@ -40,7 +40,7 @@ public class SolrExampleStreamingHttp2Test extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
index 34f4460cb0f..a662c444c46 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
@@ -38,7 +38,7 @@ public class SolrExampleStreamingTest extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
index ae0f2c64bc6..3afeb5b3f84 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleXMLHttp2Test.java
@@ -32,7 +32,7 @@ import org.junit.BeforeClass;
public class SolrExampleXMLHttp2Test extends SolrExampleTests {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java
index 4e2bf500e65..1c99a2caa4d 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java
@@ -106,7 +106,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testDelete() throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (HttpJdkSolrClient client = builder(url).build()) {
try {
client.deleteById("id");
@@ -120,7 +120,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testDeleteXml() throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (HttpJdkSolrClient client =
builder(url).withResponseParser(new XMLResponseParser()).build()) {
try {
@@ -143,7 +143,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
DebugServlet.addResponseHeader("Content-Type", "application/octet-stream");
DebugServlet.responseBodyByQueryFragment.put("", javabinResponse());
}
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
SolrQuery q = new SolrQuery("foo");
q.setParam("a", MUST_ENCODE);
q.setParam("case_sensitive_param", "lowercase");
@@ -164,8 +164,8 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
DebugServlet.clear();
DebugServlet.addResponseHeader("Content-Type", "application/octet-stream");
DebugServlet.responseBodyByQueryFragment.put("", javabinResponse());
- String someOtherUrl = getBaseUrl() + "/some/other/base/url";
- String intendedUrl = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String someOtherUrl = solrTestRule.getBaseUrl() + "/some/other/base/url";
+ String intendedUrl = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
SolrQuery q = new SolrQuery("foo");
q.setParam("a", MUST_ENCODE);
@@ -181,14 +181,15 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testGetById() throws Exception {
DebugServlet.clear();
- try (HttpJdkSolrClient client = builder(getBaseUrl() + DEBUG_SERVLET_PATH).build()) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH).build()) {
super.testGetById(client);
}
}
@Test
public void testAsyncGet() throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
ResponseParser rp = new XMLResponseParser();
HttpSolrClientBuilderBase<?, ?> b =
builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);
@@ -209,7 +210,8 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
public void testTimeout() throws Exception {
SolrQuery q = new SolrQuery("*:*");
try (HttpJdkSolrClient client =
- (HttpJdkSolrClient) builder(getBaseUrl() + SLOW_SERVLET_PATH, 500, 500).build()) {
+ (HttpJdkSolrClient)
+ builder(solrTestRule.getBaseUrl() + SLOW_SERVLET_PATH, 500, 500).build()) {
client.query(q, SolrRequest.METHOD.GET);
fail("No exception thrown.");
} catch (SolrServerException e) {
@@ -222,7 +224,8 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
SolrQuery q = new SolrQuery("*:*");
try (HttpJdkSolrClient client =
(HttpJdkSolrClient)
- builder(getBaseUrl() + DEBUG_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0).build()) {
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
+ .build()) {
try {
client.query(q, SolrRequest.METHOD.GET);
} catch (RemoteSolrException ignored) {
@@ -235,7 +238,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
SolrQuery q = new SolrQuery("*:*");
try (HttpJdkSolrClient client =
(HttpJdkSolrClient)
- builder(getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
+ builder(solrTestRule.getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
.withRequestTimeout(500, TimeUnit.MILLISECONDS)
.build()) {
client.query(q, SolrRequest.METHOD.GET);
@@ -247,7 +250,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testFollowRedirect() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
try (HttpJdkSolrClient client = builder(clientUrl).withFollowRedirects(true).build()) {
SolrQuery q = new SolrQuery("*:*");
client.query(q);
@@ -256,7 +259,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testDoNotFollowRedirect() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
try (HttpJdkSolrClient client = builder(clientUrl).withFollowRedirects(false).build()) {
SolrQuery q = new SolrQuery("*:*");
@@ -267,7 +270,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testRedirectSwapping() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
SolrQuery q = new SolrQuery("*:*");
// default for follow redirects is false
@@ -291,7 +294,8 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
}
public void testSolrExceptionCodeNotFromSolr() throws IOException, SolrServerException {
- try (HttpJdkSolrClient client = builder(getBaseUrl() + DEBUG_SERVLET_PATH).build()) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH).build()) {
super.testSolrExceptionCodeNotFromSolr(client);
} finally {
DebugServlet.clear();
@@ -300,7 +304,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUpdateDefault() throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (HttpJdkSolrClient client = builder(url).build()) {
testUpdate(client, WT.JAVABIN, "application/javabin", MUST_ENCODE);
}
@@ -317,14 +321,10 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
}
private void testUpdateXml(boolean http11) throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
// 64k+ post body, just to be sure we are using the [in|out]put streams correctly.
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 65536; i++) {
- sb.append("A");
- }
- String value = sb.toString();
+ String value = "A".repeat(65536);
try (HttpJdkSolrClient client =
builder(url)
@@ -347,7 +347,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUpdateJavabin() throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (HttpJdkSolrClient client =
builder(url)
.withRequestWriter(new JavaBinRequestWriter())
@@ -360,9 +360,12 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testCollectionParameters() throws IOException, SolrServerException {
- HttpJdkSolrClient baseUrlClient = builder(getBaseUrl()).withDefaultCollection(null).build();
+ HttpJdkSolrClient baseUrlClient =
+ builder(solrTestRule.getBaseUrl()).withDefaultCollection(null).build();
HttpJdkSolrClient collection1UrlClient =
- builder(getCoreUrl()).withDefaultCollection(null).build();
+ builder(solrTestRule.getBaseUrl() + "/" + DEFAULT_COLLECTION)
+ .withDefaultCollection(null)
+ .build();
testCollectionParameters(baseUrlClient, collection1UrlClient);
}
@@ -377,7 +380,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
try (HttpJdkSolrClient client =
(HttpJdkSolrClient)
builder(
- getBaseUrl() + DEBUG_SERVLET_PATH,
+ solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH,
DEFAULT_CONNECTION_TIMEOUT,
DEFAULT_CONNECTION_TIMEOUT)
.build()) {
@@ -388,9 +391,9 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testSetCredentialsExplicitly() throws Exception {
try (HttpJdkSolrClient client =
- builder(getBaseUrl() + DEBUG_SERVLET_PATH)
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
.withBasicAuthCredentials("foo", "explicit")
- .build(); ) {
+ .build()) {
super.testSetCredentialsExplicitly(client);
}
}
@@ -398,16 +401,17 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testPerRequestCredentials() throws Exception {
try (HttpJdkSolrClient client =
- builder(getBaseUrl() + DEBUG_SERVLET_PATH)
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
.withBasicAuthCredentials("foo2", "explicit")
- .build(); ) {
+ .build()) {
super.testPerRequestCredentials(client);
}
}
@Test
public void testNoCredentials() throws Exception {
- try (HttpJdkSolrClient client = builder(getBaseUrl() + DEBUG_SERVLET_PATH).build(); ) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH).build()) {
super.testNoCredentials(client);
}
}
@@ -416,9 +420,9 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
public void testUseOptionalCredentials() throws Exception {
// username foo, password with embedded colon separator is "expli:cit".
try (HttpJdkSolrClient client =
- builder(getBaseUrl() + DEBUG_SERVLET_PATH)
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
.withOptionalBasicAuthCredentials("foo:expli:cit")
- .build(); ) {
+ .build()) {
super.testUseOptionalCredentials(client);
}
}
@@ -426,9 +430,9 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUseOptionalCredentialsWithNull() throws Exception {
try (HttpJdkSolrClient client =
- builder(getBaseUrl() + DEBUG_SERVLET_PATH)
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
.withOptionalBasicAuthCredentials(null)
- .build(); ) {
+ .build()) {
super.testUseOptionalCredentialsWithNull(client);
}
}
@@ -437,14 +441,16 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
public void testProcessorMimeTypes() throws Exception {
ResponseParser rp = new XMLResponseParser();
- try (HttpJdkSolrClient client = builder(getBaseUrl()).withResponseParser(rp).build()) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl()).withResponseParser(rp).build()) {
assertTrue(client.processorAcceptsMimeType(rp.getContentTypes(), "application/xml"));
assertFalse(client.processorAcceptsMimeType(rp.getContentTypes(), "application/json"));
queryToHelpJdkReleaseThreads(client);
}
rp = new JavaBinResponseParser();
- try (HttpJdkSolrClient client = builder(getBaseUrl()).withResponseParser(rp).build()) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl()).withResponseParser(rp).build()) {
assertTrue(
client.processorAcceptsMimeType(
rp.getContentTypes(), "application/vnd.apache.solr.javabin"));
@@ -456,7 +462,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testContentTypeToEncoding() throws Exception {
- try (HttpJdkSolrClient client = builder(getBaseUrl()).build()) {
+ try (HttpJdkSolrClient client = builder(solrTestRule.getBaseUrl()).build()) {
assertEquals("UTF-8", client.contentTypeToEncoding("application/xml; charset=UTF-8"));
assertNull(client.contentTypeToEncoding("application/vnd.apache.solr.javabin"));
assertNull(client.contentTypeToEncoding("application/octet-stream"));
@@ -470,7 +476,8 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
ExecutorService myExecutor = null;
try {
myExecutor = ExecutorUtil.newMDCAwareSingleThreadExecutor(new NamedThreadFactory("tpiens"));
- try (HttpJdkSolrClient client = builder(getBaseUrl()).withExecutor(myExecutor).build()) {
+ try (HttpJdkSolrClient client =
+ builder(solrTestRule.getBaseUrl()).withExecutor(myExecutor).build()) {
assertEquals(myExecutor, client.executor);
queryToHelpJdkReleaseThreads(client);
}
@@ -488,7 +495,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
public void testCookieHandlerSettingHonored() throws Exception {
CookieHandler myCookieHandler = new CookieManager();
try (HttpJdkSolrClient client =
- builder(getBaseUrl()).withCookieHandler(myCookieHandler).build()) {
+ builder(solrTestRule.getBaseUrl()).withCookieHandler(myCookieHandler).build()) {
assertEquals(myCookieHandler, client.httpClient.cookieHandler().get());
queryToHelpJdkReleaseThreads(client);
}
@@ -496,7 +503,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testPing() throws Exception {
- try (HttpJdkSolrClient client = builder(getBaseUrl()).build()) {
+ try (HttpJdkSolrClient client = builder(solrTestRule.getBaseUrl()).build()) {
SolrPingResponse spr = client.ping("collection1");
assertEquals(0, spr.getStatus());
assertNull(spr.getException());
@@ -506,7 +513,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
@Test
public void testMaybeTryHeadRequestHasContentType() throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (HttpJdkSolrClient client = builder(url).build()) {
assertTrue(client.maybeTryHeadRequest(url));
@@ -539,7 +546,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
private URI baseUri() {
try {
- return new URI(getBaseUrl());
+ return new URI(solrTestRule.getBaseUrl());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
@@ -558,7 +565,7 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
new HttpJdkSolrClient.Builder(url)
.withConnectionTimeout(connectionTimeout, TimeUnit.MILLISECONDS)
.withIdleTimeout(socketTimeout, TimeUnit.MILLISECONDS)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withSSLContext(MockTrustManager.ALL_TRUSTING_SSL_CONTEXT);
return (B) b;
}
@@ -571,7 +578,6 @@ public class HttpJdkSolrClientTest extends HttpSolrClientTestBase {
String[] str = JAVABIN_STR.split(" ");
byte[] bytes = new byte[str.length];
for (int i = 0; i < str.length; i++) {
- int asInt = 0;
bytes[i] = (byte) Integer.decode("#" + str[i]).intValue();
}
return bytes;
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBadInputTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBadInputTest.java
index 006264c6603..37c1dc0211f 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBadInputTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBadInputTest.java
@@ -19,15 +19,19 @@ package org.apache.solr.client.solrj.impl;
import java.util.ArrayList;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
-import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.ExternalPaths;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
/** Tests {@link HttpSolrClient}'s response to a variety of bad inputs. */
-public class HttpSolrClientBadInputTest extends SolrJettyTestBase {
+public class HttpSolrClientBadInputTest extends SolrTestCaseJ4 {
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
private static final List<String> NULL_STR_LIST = null;
private static final List<String> EMPTY_STR_LIST = new ArrayList<>();
private static final String ANY_COLLECTION = "ANY_COLLECTION";
@@ -35,12 +39,16 @@ public class HttpSolrClientBadInputTest extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome(), JettyConfig.builder().build());
+ solrTestRule.startSolr(createTempDir());
+ solrTestRule
+ .newCollection("collection1")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
}
@Test
public void testDeleteByIdReportsInvalidIdLists() throws Exception {
- try (SolrClient client = getHttpSolrClient(getBaseUrl(), ANY_COLLECTION)) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl(), ANY_COLLECTION)) {
assertExceptionThrownWithMessageContaining(
IllegalArgumentException.class,
List.of("ids", "null"),
@@ -67,7 +75,7 @@ public class HttpSolrClientBadInputTest extends SolrJettyTestBase {
});
}
- try (SolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
assertExceptionThrownWithMessageContaining(
IllegalArgumentException.class,
List.of("ids", "null"),
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java
index c77df8c803f..c1deeeee1ca 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientTestBase.java
@@ -30,12 +30,13 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import org.apache.solr.SolrJettyTestBase;
+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;
@@ -58,12 +59,16 @@ import org.apache.solr.util.ServletFixtures.DebugServlet;
import org.apache.solr.util.ServletFixtures.RedirectServlet;
import org.apache.solr.util.ServletFixtures.SlowServlet;
import org.apache.solr.util.ServletFixtures.SlowStreamServlet;
+import org.apache.solr.util.SolrJettyTestRule;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
-public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
+public abstract class HttpSolrClientTestBase extends SolrTestCaseJ4 {
- protected static final String DEFAULT_CORE = "foo";
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
+ protected static final String DEFAULT_COLLECTION = DEFAULT_TEST_CORENAME;
protected static final String SLOW_SERVLET_PATH = "/slow";
protected static final String SLOW_SERVLET_REGEX = SLOW_SERVLET_PATH + "/*";
protected static final String DEBUG_SERVLET_PATH = "/debug";
@@ -86,7 +91,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
.withServlet(new ServletHolder(SlowStreamServlet.class), SLOW_STREAM_SERVLET_REGEX)
.withSSLConfig(sslConfig.buildServerSSLConfig())
.build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
}
@Override
@@ -276,7 +281,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
protected enum WT {
JAVABIN,
XML
- };
+ }
protected void testUpdate(HttpSolrClientBase client, WT wt, String contentType, String docIdValue)
throws Exception {
@@ -323,13 +328,13 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
try {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "collection");
- baseUrlClient.add(COLLECTION_1, doc);
- baseUrlClient.commit(COLLECTION_1);
+ baseUrlClient.add(DEFAULT_COLLECTION, doc);
+ baseUrlClient.commit(DEFAULT_COLLECTION);
assertEquals(
1,
baseUrlClient
- .query(COLLECTION_1, new SolrQuery("id:collection"))
+ .query(DEFAULT_COLLECTION, new SolrQuery("id:collection"))
.getResults()
.getNumFound());
@@ -350,8 +355,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
}
}
- protected void verifyServletState(HttpSolrClientBase client, SolrRequest<?> request)
- throws Exception {
+ protected void verifyServletState(HttpSolrClientBase client, SolrRequest<?> request) {
// check query String
Iterator<String> paramNames = request.getParams().getParameterNamesIterator();
while (paramNames.hasNext()) {
@@ -365,7 +369,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
assertEquals(
shouldBeInQueryString,
DebugServlet.queryString.contains(
- name + "=" + URLEncoder.encode(value, StandardCharsets.UTF_8.name())));
+ name + "=" + URLEncoder.encode(value, StandardCharsets.UTF_8)));
// in either case, it should be in the parameters
assertNotNull(DebugServlet.parameters.get(name));
assertEquals(1, DebugServlet.parameters.get(name).length);
@@ -376,12 +380,12 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
}
protected void testQueryString() throws Exception {
- final String clientUrl = getBaseUrl() + DEBUG_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
UpdateRequest req = new UpdateRequest();
try (HttpSolrClientBase client =
builder(clientUrl, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withTheseParamNamesInTheUrl(Set.of("serverOnly"))
.build()) {
// test without request query params
@@ -556,7 +560,7 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
protected void testUpdateAsync() throws Exception {
ResponseParser rp = new XMLResponseParser();
- String url = getBaseUrl();
+ String url = solrTestRule.getBaseUrl();
HttpSolrClientBuilderBase<?, ?> b =
builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);
int limit = 10;
@@ -565,11 +569,11 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
try (HttpSolrClientBase client = b.build()) {
// ensure the collection is empty to start
- client.deleteByQuery(COLLECTION_1, "*:*");
- client.commit(COLLECTION_1);
+ client.deleteByQuery(DEFAULT_COLLECTION, "*:*");
+ client.commit(DEFAULT_COLLECTION);
QueryResponse qr =
client.query(
- COLLECTION_1,
+ DEFAULT_COLLECTION,
new MapSolrParams(Collections.singletonMap("q", "*:*")),
SolrRequest.METHOD.POST);
assertEquals(0, qr.getResults().getNumFound());
@@ -579,22 +583,22 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
ur.add("id", "KEY-" + i);
ur.setMethod(SolrRequest.METHOD.POST);
- client.requestAsync(ur, COLLECTION_1).whenComplete((nl, e) -> latch.countDown());
+ client.requestAsync(ur, DEFAULT_COLLECTION).whenComplete((nl, e) -> latch.countDown());
}
latch.await(1, TimeUnit.MINUTES);
- client.commit(COLLECTION_1);
+ client.commit(DEFAULT_COLLECTION);
// check that the correct number of documents were added
qr =
client.query(
- COLLECTION_1,
+ DEFAULT_COLLECTION,
new MapSolrParams(Collections.singletonMap("q", "*:*")),
SolrRequest.METHOD.POST);
assertEquals(limit, qr.getResults().getNumFound());
// clean up
- client.deleteByQuery(COLLECTION_1, "*:*");
- client.commit(COLLECTION_1);
+ client.deleteByQuery(DEFAULT_COLLECTION, "*:*");
+ client.commit(DEFAULT_COLLECTION);
}
}
@@ -636,13 +640,13 @@ public abstract class HttpSolrClientTestBase extends SolrJettyTestBase {
ResponseParser rp = new XMLResponseParser();
DebugServlet.clear();
DebugServlet.addResponseHeader("Content-Type", "Wrong Content Type!");
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
HttpSolrClientBuilderBase<?, ?> b =
builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);
try (HttpSolrClientBase client = b.build()) {
QueryRequest query = new QueryRequest(new MapSolrParams(Collections.singletonMap("id", "1")));
- CompletableFuture<NamedList<Object>> future = client.requestAsync(query, COLLECTION_1);
+ CompletableFuture<NamedList<Object>> future = client.requestAsync(query, DEFAULT_COLLECTION);
ExecutionException ee = null;
try {
future.get(1, TimeUnit.MINUTES);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBadInputTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBadInputTest.java
index 50b040b780f..df69c1938d8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBadInputTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBadInputTest.java
@@ -19,14 +19,18 @@ package org.apache.solr.client.solrj.impl;
import java.util.ArrayList;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.LBHttpSolrClient;
-import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.ExternalPaths;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class LBHttpSolrClientBadInputTest extends SolrJettyTestBase {
+public class LBHttpSolrClientBadInputTest extends SolrTestCaseJ4 {
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
private static final List<String> NULL_STR_LIST = null;
private static final List<String> EMPTY_STR_LIST = new ArrayList<>();
private static final String ANY_COLLECTION = "ANY_COLLECTION";
@@ -34,14 +38,18 @@ public class LBHttpSolrClientBadInputTest extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome(), JettyConfig.builder().build());
+ solrTestRule.startSolr(createTempDir());
+ solrTestRule
+ .newCollection("collection1")
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
}
@Test
public void testDeleteByIdReportsInvalidIdLists() throws Exception {
try (SolrClient client =
new LBHttpSolrClient.Builder()
- .withBaseEndpoint(getBaseUrl())
+ .withBaseEndpoint(solrTestRule.getBaseUrl())
.withDefaultCollection(ANY_COLLECTION)
.build()) {
assertExceptionThrownWithMessageContaining(
@@ -71,7 +79,7 @@ public class LBHttpSolrClientBadInputTest extends SolrJettyTestBase {
}
try (SolrClient client =
- new LBHttpSolrClient.Builder().withBaseEndpoint(getBaseUrl()).build()) {
+ new LBHttpSolrClient.Builder().withBaseEndpoint(solrTestRule.getBaseUrl()).build()) {
assertExceptionThrownWithMessageContaining(
IllegalArgumentException.class,
List.of("ids", "null"),
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientBadInputTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientBadInputTest.java
index e2e2d18b832..9e1137119b4 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientBadInputTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientBadInputTest.java
@@ -19,12 +19,15 @@ package org.apache.solr.client.solrj.jetty;
import java.util.ArrayList;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import java.util.Properties;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrJettyTestBase {
+public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrTestCaseJ4 {
private static final List<String> NULL_STR_LIST = null;
private static final List<String> EMPTY_STR_LIST = new ArrayList<>();
private static final String ANY_COLLECTION = "ANY_COLLECTION";
@@ -32,9 +35,12 @@ public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrJettyTestBa
private static final int ANY_QUEUE_SIZE = 1;
private static final int ANY_MAX_NUM_THREADS = 1;
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome(), JettyConfig.builder().build());
+ solrTestRule.startSolr(
+ legacyExampleCollection1SolrHome(), new Properties(), JettyConfig.builder().build());
}
@Test
@@ -42,7 +48,7 @@ public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrJettyTestBa
try (var http2Client = new HttpJettySolrClient.Builder().build();
var client =
- new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client)
+ new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client)
.withDefaultCollection(ANY_COLLECTION)
.withQueueSize(ANY_QUEUE_SIZE)
.withThreadCount(ANY_MAX_NUM_THREADS)
@@ -75,7 +81,7 @@ public class ConcurrentUpdateJettySolrClientBadInputTest extends SolrJettyTestBa
try (var http2Client = new HttpJettySolrClient.Builder().build();
var client =
- new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client)
+ new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client)
.withDefaultCollection(ANY_COLLECTION)
.withQueueSize(ANY_QUEUE_SIZE)
.withThreadCount(ANY_MAX_NUM_THREADS)
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientTest.java
index e0c078f1eec..bb2d3c5cef8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/ConcurrentUpdateJettySolrClientTest.java
@@ -31,11 +31,12 @@ import java.net.SocketTimeoutException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec;
@@ -45,14 +46,16 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
+public class ConcurrentUpdateJettySolrClientTest extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
/** Mock endpoint where the CUSS being tested in this class sends requests. */
@@ -167,18 +170,20 @@ public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
}
}
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
@BeforeClass
public static void beforeTest() throws Exception {
JettyConfig jettyConfig =
JettyConfig.builder().withServlet(new ServletHolder(TestServlet.class), "/cuss/*").build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
}
@Test
public void testConcurrentUpdate() throws Exception {
TestServlet.clear();
- String serverUrl = getBaseUrl() + "/cuss/foo";
+ String serverUrl = solrTestRule.getBaseUrl() + "/cuss/foo";
int cussThreadCount = 2;
int cussQueueSize = 100;
@@ -248,7 +253,7 @@ public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
try (var http2Client = new HttpJettySolrClient.Builder().build();
var concurrentClient =
- (new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client))
+ (new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client))
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
.build()) {
@@ -268,7 +273,7 @@ public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
try (var http2Client = new HttpJettySolrClient.Builder().build();
var concurrentClient =
- new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client)
+ new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client)
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
@@ -290,7 +295,7 @@ public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
try (var http2Client = new HttpJettySolrClient.Builder().build();
var concurrentClient =
- new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client)
+ new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client)
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
.setPollQueueTime(0, TimeUnit.MILLISECONDS)
@@ -327,7 +332,7 @@ public class ConcurrentUpdateJettySolrClientTest extends SolrJettyTestBase {
try (var http2Client = new HttpJettySolrClient.Builder().build();
var concurrentClient =
- new ConcurrentUpdateJettySolrClient.Builder(getBaseUrl(), http2Client)
+ new ConcurrentUpdateJettySolrClient.Builder(solrTestRule.getBaseUrl(), http2Client)
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientCompatibilityTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientCompatibilityTest.java
index c213b3d3130..918ef1247f8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientCompatibilityTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientCompatibilityTest.java
@@ -17,7 +17,7 @@
package org.apache.solr.client.solrj.jetty;
-import org.apache.solr.SolrJettyTestBase;
+import java.util.Properties;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.RemoteSolrException;
import org.apache.solr.client.solrj.SolrRequest;
@@ -26,13 +26,17 @@ import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.util.LogLevel;
import org.apache.solr.util.ServletFixtures.DebugServlet;
+import org.apache.solr.util.SolrJettyTestRule;
import org.eclipse.jetty.client.transport.HttpClientTransportOverHTTP;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.http2.client.transport.HttpClientTransportOverHTTP2;
+import org.junit.ClassRule;
@LogLevel("org.eclipse.jetty.client=DEBUG;org.eclipse.jetty.util=DEBUG")
@SolrTestCaseJ4.SuppressSSL
-public class HttpJettySolrClientCompatibilityTest extends SolrJettyTestBase {
+public class HttpJettySolrClientCompatibilityTest extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
public void testSystemPropertyFlag() {
System.setProperty("solr.http1", "true");
@@ -52,17 +56,19 @@ public class HttpJettySolrClientCompatibilityTest extends SolrJettyTestBase {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(true)
.build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + "/debug/foo").useHttp1_1(true).build()) {
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
+ .useHttp1_1(true)
+ .build()) {
assertTrue(client.getHttpClient().getTransport() instanceof HttpClientTransportOverHTTP);
try {
client.query(new SolrQuery("*:*"), SolrRequest.METHOD.GET);
} catch (RemoteSolrException ignored) {
}
} finally {
- solrClientTestRule.reset();
+ solrTestRule.reset();
}
}
@@ -73,17 +79,19 @@ public class HttpJettySolrClientCompatibilityTest extends SolrJettyTestBase {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(false)
.build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + "/debug/foo").useHttp1_1(true).build()) {
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo")
+ .useHttp1_1(true)
+ .build()) {
assertTrue(client.getHttpClient().getTransport() instanceof HttpClientTransportOverHTTP);
try {
client.query(new SolrQuery("*:*"), SolrRequest.METHOD.GET);
} catch (RemoteSolrException ignored) {
}
} finally {
- solrClientTestRule.reset();
+ solrTestRule.reset();
}
}
@@ -97,10 +105,11 @@ public class HttpJettySolrClientCompatibilityTest extends SolrJettyTestBase {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.useOnlyHttp1(true)
.build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
System.clearProperty("solr.http1");
- try (var client = new HttpJettySolrClient.Builder(getBaseUrl() + "/debug/foo").build()) {
+ try (var client =
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/debug/foo").build()) {
assertTrue(client.getHttpClient().getTransport() instanceof HttpClientTransportOverHTTP2);
try {
client.query(new SolrQuery("*:*"), SolrRequest.METHOD.GET);
@@ -111,7 +120,7 @@ public class HttpJettySolrClientCompatibilityTest extends SolrJettyTestBase {
// expected
}
} finally {
- solrClientTestRule.reset();
+ solrTestRule.reset();
}
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientProxyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientProxyTest.java
index ec887fe4f26..8d5488ff6b1 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientProxyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientProxyTest.java
@@ -19,7 +19,6 @@ package org.apache.solr.client.solrj.jetty;
import com.carrotsearch.randomizedtesting.RandomizedTest;
import java.util.Arrays;
import java.util.Objects;
-import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.SolrTestCaseJ4;
@@ -27,7 +26,6 @@ import org.apache.solr.client.solrj.impl.HttpJdkSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClientBase;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.SocketProxy;
import org.apache.solr.util.SolrJettyTestRule;
@@ -38,7 +36,7 @@ import org.junit.Test;
public class HttpJettySolrClientProxyTest extends SolrTestCaseJ4 {
- @ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
// TODO add SSL test
@@ -46,13 +44,12 @@ public class HttpJettySolrClientProxyTest extends SolrTestCaseJ4 {
public static void beforeTest() throws Exception {
RandomizedTest.assumeFalse(sslConfig.isSSLMode());
- solrClientTestRule.enableProxy();
- solrClientTestRule.startSolr(createTempDir(), new Properties(), JettyConfig.builder().build());
+ solrTestRule.enableProxy();
+ solrTestRule.startSolr(createTempDir());
// Actually only need extremely minimal configSet but just use the default
- solrClientTestRule
+ solrTestRule
.newCollection()
- .withConfigSet(
- ExternalPaths.DEFAULT_CONFIGSET.toString()) // TODO should be default for empty home
+ .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET) // TODO should be default for empty home
.create();
}
@@ -64,7 +61,7 @@ public class HttpJettySolrClientProxyTest extends SolrTestCaseJ4 {
@Before
public void before() {
- this.proxy = solrClientTestRule.getJetty().getProxy();
+ this.proxy = solrTestRule.getJetty().getProxy();
this.host = proxy.getUrl().getHost();
this.url = "http://" + host + ":" + (proxy.getUrl().getPort() + 10) + "/solr";
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientTest.java
index 4e927ac7e91..11171989a5c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/jetty/HttpJettySolrClientTest.java
@@ -24,7 +24,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
-import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -47,7 +46,6 @@ import org.apache.solr.client.solrj.response.ResponseParser;
import org.apache.solr.client.solrj.response.XMLResponseParser;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -81,8 +79,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
SolrQuery q = new SolrQuery("*:*");
try (HttpJettySolrClient client =
(HttpJettySolrClient)
- builder(getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 2000)
- .withDefaultCollection(DEFAULT_CORE)
+ builder(solrTestRule.getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 2000)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
client.query(q, SolrRequest.METHOD.GET);
fail("No exception thrown.");
@@ -96,8 +94,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
SolrQuery q = new SolrQuery("*:*");
try (HttpJettySolrClient client =
(HttpJettySolrClient)
- builder(getBaseUrl() + DEBUG_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
- .withDefaultCollection(DEFAULT_CORE)
+ builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
try {
client.query(q, SolrRequest.METHOD.GET);
@@ -111,8 +109,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
SolrQuery q = new SolrQuery("*:*");
try (HttpJettySolrClient client =
(HttpJettySolrClient)
- builder(getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
- .withDefaultCollection(DEFAULT_CORE)
+ builder(solrTestRule.getBaseUrl() + SLOW_SERVLET_PATH, DEFAULT_CONNECTION_TIMEOUT, 0)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withRequestTimeout(500, TimeUnit.MILLISECONDS)
.build()) {
client.query(q, SolrRequest.METHOD.GET);
@@ -129,8 +127,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testSolrExceptionCodeNotFromSolr() throws IOException, SolrServerException {
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
super.testSolrExceptionCodeNotFromSolr(client);
} finally {
@@ -147,12 +145,13 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
try (var client = new HttpJettySolrClient.Builder(null).build()) {
try {
// if client base url is null, request url will be used in exception message
- client.requestWithBaseUrl(getBaseUrl() + DEBUG_SERVLET_PATH, new SolrPing(), DEFAULT_CORE);
+ client.requestWithBaseUrl(
+ solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH, new SolrPing(), DEFAULT_COLLECTION);
fail("Didn't get excepted exception from oversided request");
} catch (SolrException e) {
assertEquals("Unexpected exception status code", status, e.code());
- assertTrue(e.getMessage().contains(getBaseUrl()));
+ assertTrue(e.getMessage().contains(solrTestRule.getBaseUrl()));
}
} finally {
DebugServlet.clear();
@@ -162,12 +161,12 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Override
protected void testQuerySetup(SolrRequest.METHOD method, ResponseParser rp) throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
SolrQuery q = new SolrQuery("foo");
q.setParam("a", MUST_ENCODE);
q.setParam("case_sensitive_param", "lowercase");
q.setParam("CASE_SENSITIVE_PARAM", "uppercase");
- var b = new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_CORE);
+ var b = new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_COLLECTION);
if (rp != null) {
b.withResponseParser(rp);
}
@@ -220,13 +219,15 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
DebugServlet.clear();
final var defaultUrl =
"http://not-a-real-url:8983/solr"; // Would result in an exception if used
- final var urlToUse = getBaseUrl() + DEBUG_SERVLET_PATH;
+ final var urlToUse = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
final var queryParams = new ModifiableSolrParams();
queryParams.add("q", "*:*");
// Ensure the correct URL is used by the lambda-based requestWithBaseUrl method
try (var client =
- new HttpJettySolrClient.Builder(defaultUrl).withDefaultCollection(DEFAULT_CORE).build()) {
+ new HttpJettySolrClient.Builder(defaultUrl)
+ .withDefaultCollection(DEFAULT_COLLECTION)
+ .build()) {
try {
client.requestWithBaseUrl(urlToUse, (c) -> c.query(queryParams));
} catch (RemoteSolrException rse) {
@@ -237,7 +238,9 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
// Ensure the correct URL is used by the SolrRequest-based requestWithBaseUrl method
try (var client =
- new HttpJettySolrClient.Builder(defaultUrl).withDefaultCollection(DEFAULT_CORE).build()) {
+ new HttpJettySolrClient.Builder(defaultUrl)
+ .withDefaultCollection(DEFAULT_COLLECTION)
+ .build()) {
try {
client.requestWithBaseUrl(urlToUse, new QueryRequest(queryParams), null);
} catch (RemoteSolrException rse) {
@@ -250,9 +253,9 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testDelete() throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (var client =
- new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_CORE).build()) {
+ new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_COLLECTION).build()) {
try {
client.deleteById("id");
} catch (RemoteSolrException ignored) {
@@ -265,10 +268,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testDeleteXml() throws Exception {
DebugServlet.clear();
- String url = getBaseUrl() + "/debug/foo";
+ String url = solrTestRule.getBaseUrl() + "/debug/foo";
try (var client =
new HttpJettySolrClient.Builder(url)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withResponseParser(new XMLResponseParser())
.build()) {
try {
@@ -284,8 +287,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
public void testGetById() throws Exception {
DebugServlet.clear();
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
super.testGetById(client);
}
@@ -293,19 +296,19 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUpdateDefault() throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
try (var client =
- new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_CORE).build()) {
+ new HttpJettySolrClient.Builder(url).withDefaultCollection(DEFAULT_COLLECTION).build()) {
testUpdate(client, WT.JAVABIN, "application/javabin", MUST_ENCODE);
}
}
@Test
public void testUpdateXml() throws Exception {
- String url = getBaseUrl() + "/debug/foo";
+ String url = solrTestRule.getBaseUrl() + "/debug/foo";
try (var client =
new HttpJettySolrClient.Builder(url)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withRequestWriter(new XMLRequestWriter())
.withResponseParser(new XMLResponseParser())
.build()) {
@@ -315,10 +318,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUpdateJavabin() throws Exception {
- String url = getBaseUrl() + "/debug/foo";
+ String url = solrTestRule.getBaseUrl() + "/debug/foo";
try (var client =
new HttpJettySolrClient.Builder(url)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withRequestWriter(new JavaBinRequestWriter())
.withResponseParser(new JavaBinResponseParser())
.build()) {
@@ -328,7 +331,7 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testAsyncGet() throws Exception {
- String url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
ResponseParser rp = new XMLResponseParser();
HttpSolrClientBuilderBase<?, ?> b =
builder(url, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT).withResponseParser(rp);
@@ -348,12 +351,11 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testAsyncQueryWithSharedClient() throws Exception {
DebugServlet.clear();
- final var url = getBaseUrl() + DEBUG_SERVLET_PATH;
+ final var url = solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH;
ResponseParser rp = new XMLResponseParser();
- final var queryParams = new MapSolrParams(Collections.singletonMap("q", "*:*"));
final var builder =
new HttpJettySolrClient.Builder(url)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withResponseParser(rp);
try (HttpJettySolrClient originalClient = builder.build()) {
final var derivedBuilder = builder.withHttpClient(originalClient);
@@ -363,10 +365,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testFollowRedirect() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
try (var client =
new HttpJettySolrClient.Builder(clientUrl)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withFollowRedirects(true)
.build()) {
SolrQuery q = new SolrQuery("*:*");
@@ -375,11 +377,11 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
}
@Test
- public void testDoNotFollowRedirect() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ public void testDoNotFollowRedirect() {
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
try (var client =
new HttpJettySolrClient.Builder(clientUrl)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withFollowRedirects(false)
.build()) {
SolrQuery q = new SolrQuery("*:*");
@@ -391,12 +393,14 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testRedirectSwapping() throws Exception {
- final String clientUrl = getBaseUrl() + REDIRECT_SERVLET_PATH;
+ final String clientUrl = solrTestRule.getBaseUrl() + REDIRECT_SERVLET_PATH;
SolrQuery q = new SolrQuery("*:*");
// default for follow redirects is false
try (var client =
- new HttpJettySolrClient.Builder(clientUrl).withDefaultCollection(DEFAULT_CORE).build()) {
+ new HttpJettySolrClient.Builder(clientUrl)
+ .withDefaultCollection(DEFAULT_COLLECTION)
+ .build()) {
SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));
assertTrue(e.getMessage().contains("redirect"));
@@ -404,7 +408,7 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
try (var client =
new HttpJettySolrClient.Builder(clientUrl)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withFollowRedirects(true)
.build()) {
// shouldn't throw an exception
@@ -414,7 +418,7 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
// set explicit false for following redirects
try (var client =
new HttpJettySolrClient.Builder(clientUrl)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withFollowRedirects(false)
.build()) {
@@ -425,8 +429,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testCollectionParameters() throws IOException, SolrServerException {
- var baseUrlClient = new HttpJettySolrClient.Builder(getBaseUrl()).build();
- var collection1UrlClient = new HttpJettySolrClient.Builder(getCoreUrl()).build();
+ var baseUrlClient = new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build();
+ var collection1UrlClient =
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + "/" + DEFAULT_COLLECTION)
+ .build();
testCollectionParameters(baseUrlClient, collection1UrlClient);
}
@@ -487,16 +493,16 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testSetCredentialsExplicitly() {
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withBasicAuthCredentials("foo", "explicit")
- .build(); ) {
+ .build()) {
super.testSetCredentialsExplicitly(client);
}
}
@Test
- public void testSetCredentialsWithSysProps() throws IOException, SolrServerException {
+ public void testSetCredentialsWithSysProps() {
System.setProperty(
PreemptiveBasicAuthClientCustomizer.SYS_PROP_BASIC_AUTH_CREDENTIALS, "foo:bar");
System.setProperty(
@@ -506,8 +512,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
PreemptiveBasicAuthClientCustomizer.setDefaultSolrParams(
new PreemptiveBasicAuthClientCustomizer.CredentialsResolver().defaultParams);
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
QueryRequest r = new QueryRequest(new SolrQuery("quick brown fox"));
DebugServlet.addResponseHeader(
@@ -536,10 +542,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testPerRequestCredentials() {
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withBasicAuthCredentials("foo2", "explicit")
- .build(); ) {
+ .build()) {
super.testPerRequestCredentials(client);
}
}
@@ -547,9 +553,9 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testNoCredentials() {
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
- .build(); ) {
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
+ .build()) {
super.testNoCredentials(client);
}
}
@@ -558,10 +564,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
public void testUseOptionalCredentials() {
// username foo, password with embedded colon separator is "expli:cit".
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withOptionalBasicAuthCredentials("foo:expli:cit")
- .build(); ) {
+ .build()) {
super.testUseOptionalCredentials(client);
}
}
@@ -569,10 +575,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testUseOptionalCredentialsWithNull() {
try (var client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.withOptionalBasicAuthCredentials(null)
- .build(); ) {
+ .build()) {
super.testUseOptionalCredentialsWithNull(client);
}
}
@@ -610,8 +616,8 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
System.setProperty(HttpJettySolrClient.CLIENT_CUSTOMIZER_SYSPROP, "FakeClassName");
try {
SolrClient client =
- new HttpJettySolrClient.Builder(getBaseUrl() + DEBUG_SERVLET_PATH)
- .withDefaultCollection(DEFAULT_CORE)
+ new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build();
fail("Expecting exception");
} catch (RuntimeException e) {
@@ -624,10 +630,10 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
try (HttpJettySolrClient client =
(HttpJettySolrClient)
builder(
- getBaseUrl() + DEBUG_SERVLET_PATH,
+ solrTestRule.getBaseUrl() + DEBUG_SERVLET_PATH,
DEFAULT_CONNECTION_TIMEOUT,
DEFAULT_CONNECTION_TIMEOUT)
- .withDefaultCollection(DEFAULT_CORE)
+ .withDefaultCollection(DEFAULT_COLLECTION)
.build()) {
super.testGetRawStream(client);
}
@@ -673,7 +679,7 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testIdleTimeoutWithHttpClient() throws Exception {
- String url = getBaseUrl() + SLOW_STREAM_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + SLOW_STREAM_SERVLET_PATH;
try (var oldClient =
new HttpJettySolrClient.Builder(url)
.withRequestTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS)
@@ -715,7 +721,7 @@ public class HttpJettySolrClientTest extends HttpSolrClientTestBase {
@Test
public void testRequestTimeoutWithHttpClient() throws Exception {
- String url = getBaseUrl() + SLOW_STREAM_SERVLET_PATH;
+ String url = solrTestRule.getBaseUrl() + SLOW_STREAM_SERVLET_PATH;
try (var oldClient =
new HttpJettySolrClient.Builder(url)
.withIdleTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS)
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
index 22ea7401ef5..98d853c787d 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
@@ -113,7 +113,7 @@ public class SchemaTest extends RestTestBase {
@After
public void cleanup() throws Exception {
- solrClientTestRule.reset();
+ solrTestRule.reset();
if (restTestHarness != null) {
restTestHarness.close();
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
index 6679a825137..b37c0b9d502 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
@@ -30,17 +30,17 @@ public class SolrPingTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr"));
+ solrTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr"));
SolrTestCaseJ4.newRandomConfig();
- solrClientTestRule.newCollection().withConfigSet("../collection1").create();
+ solrTestRule.newCollection().withConfigSet("../collection1").create();
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- solrClientTestRule.clearIndex();
+ solrTestRule.clearIndex();
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", 1);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java
index 203f115b7a9..404ba2320c0 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java
@@ -51,14 +51,14 @@ public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServ
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
+ solrTestRule.startSolr(LuceneTestCase.createTempDir());
- solrClientTestRule
+ solrTestRule
.newCollection(COLLECTION_NAME)
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
.create();
- SolrClient client = solrClientTestRule.getSolrClient(COLLECTION_NAME);
+ SolrClient client = solrTestRule.getSolrClient(COLLECTION_NAME);
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
up.setParam("collection", COLLECTION_NAME);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/InputStreamResponseParserTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/InputStreamResponseParserTest.java
index a75f22a7d6c..6734b53d6a5 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/InputStreamResponseParserTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/InputStreamResponseParserTest.java
@@ -21,7 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
@@ -30,26 +30,30 @@ import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
/** A test for parsing Solr response from query by InputStreamResponseParser. */
-public class InputStreamResponseParserTest extends SolrJettyTestBase {
+public class InputStreamResponseParserTest extends SolrTestCaseJ4 {
private static InputStream getResponse() {
return new ByteArrayInputStream("NO-OP test response".getBytes(StandardCharsets.UTF_8));
}
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
@Before
public void doBefore() throws IOException, SolrServerException {
// add document and commit, and ensure it's there
- SolrClient client = getSolrClient();
+ SolrClient client = solrTestRule.getSolrClient();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1234");
client.add(doc);
@@ -61,7 +65,7 @@ public class InputStreamResponseParserTest extends SolrJettyTestBase {
public void testQueryParse() throws Exception {
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withResponseParser(new InputStreamResponseParser("xml"))
.build()) {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java
index dc73163bf54..575fa87c2ad 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java
@@ -32,19 +32,16 @@ public class TermsResponseTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- solrClientTestRule.clearIndex();
+ solrTestRule.clearIndex();
}
@Test
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestClusteringResponse.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestClusteringResponse.java
index 56081f20d8a..d740ace5a4f 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestClusteringResponse.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestClusteringResponse.java
@@ -23,13 +23,13 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.Test;
/** Test for ClusteringComponent's response in Solrj */
-public class TestClusteringResponse extends SolrJettyTestBase {
+public class TestClusteringResponse extends SolrTestCaseJ4 {
@Test
public void testClusteringResponse() throws Exception {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java
index eace417d4b9..be51f216dab 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java
@@ -41,12 +41,9 @@ public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr();
+ solrTestRule.startSolr();
- solrClientTestRule
- .newCollection()
- .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET.toString())
- .create();
+ solrTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();
client = getSolrClient();
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java
index cf729e329a9..98c1bae3bd8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java
@@ -19,7 +19,7 @@ package org.apache.solr.client.solrj.response;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
@@ -27,21 +27,19 @@ import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams;
-import org.junit.Before;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
/** Test for SuggesterComponent's response in Solrj */
-public class TestSuggesterResponse extends SolrJettyTestBase {
+public class TestSuggesterResponse extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@BeforeClass
public static void beforeClass() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
- }
-
- @Before
- public void setUpClient() {
- getSolrClient();
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}
static String field = "cat";
@@ -116,8 +114,8 @@ public class TestSuggesterResponse extends SolrJettyTestBase {
}
private void addSampleDocs() throws SolrServerException, IOException {
- getSolrClient().deleteByQuery("*:*");
- getSolrClient().commit(true, true);
+ solrTestRule.getSolrClient().deleteByQuery("*:*");
+ solrTestRule.getSolrClient().commit(true, true);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111");
doc.setField(field, "Computer");
@@ -127,10 +125,10 @@ public class TestSuggesterResponse extends SolrJettyTestBase {
SolrInputDocument doc3 = new SolrInputDocument();
doc3.setField("id", "333");
doc3.setField(field, "Laptop");
- getSolrClient().add(doc);
- getSolrClient().add(doc2);
- getSolrClient().add(doc3);
- getSolrClient().commit(true, true);
+ solrTestRule.getSolrClient().add(doc);
+ solrTestRule.getSolrClient().add(doc2);
+ solrTestRule.getSolrClient().add(doc3);
+ solrTestRule.getSolrClient().commit(true, true);
}
/*
@@ -140,7 +138,7 @@ public class TestSuggesterResponse extends SolrJettyTestBase {
final ResponseParser randomParser =
random().nextBoolean() ? new JavaBinResponseParser() : new XMLResponseParser();
return new HttpSolrClient.Builder()
- .withBaseSolrUrl(getBaseUrl())
+ .withBaseSolrUrl(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withResponseParser(randomParser)
.build();
diff --git a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
index 3eb73eb8878..12973d24bf6 100644
--- a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
@@ -24,9 +24,9 @@ import org.junit.ClassRule;
public abstract class EmbeddedSolrServerTestBase extends SolrTestCase {
@ClassRule
- public static EmbeddedSolrServerTestRule solrClientTestRule = new EmbeddedSolrServerTestRule();
+ public static EmbeddedSolrServerTestRule solrTestRule = new EmbeddedSolrServerTestRule();
public static SolrClient getSolrClient() {
- return solrClientTestRule.getSolrClient();
+ return solrTestRule.getSolrClient();
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
deleted file mode 100644
index a6524e74800..00000000000
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.solr;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Properties;
-import java.util.SortedMap;
-import org.apache.commons.io.file.PathUtils;
-import org.apache.http.client.HttpClient;
-import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.apache.HttpSolrClient;
-import org.apache.solr.embedded.JettyConfig;
-import org.apache.solr.embedded.JettySolrRunner;
-import org.apache.solr.util.SolrJettyTestRule;
-import org.eclipse.jetty.ee10.servlet.ServletHolder;
-import org.junit.ClassRule;
-
-@Deprecated // just use SolrJettyTestRule
-public abstract class SolrJettyTestBase extends SolrTestCaseJ4 {
- @ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
-
- protected static JettySolrRunner createAndStartJetty(
- Path solrHome,
- String configFile,
- String schemaFile,
- String context,
- boolean stopAtShutdown,
- SortedMap<ServletHolder, String> extraServlets)
- throws Exception {
- // creates the data dir
-
- assert context == null || context.equals("/solr"); // deprecated
-
- JettyConfig jettyConfig =
- JettyConfig.builder().stopAtShutdown(stopAtShutdown).withServlets(extraServlets).build();
-
- Properties nodeProps = new Properties();
- if (configFile != null) nodeProps.setProperty("solrconfig", configFile);
- if (schemaFile != null) nodeProps.setProperty("schema", schemaFile);
- if (System.getProperty("solr.data.dir") == null) {
- nodeProps.setProperty("solr.data.dir", createTempDir().toRealPath().toString());
- }
-
- return createAndStartJetty(solrHome, nodeProps, jettyConfig);
- }
-
- protected static JettySolrRunner createAndStartJetty(
- Path solrHome, String configFile, String context) throws Exception {
- return createAndStartJetty(solrHome, configFile, null, context, true, null);
- }
-
- protected static JettySolrRunner createAndStartJetty(Path solrHome, JettyConfig jettyConfig)
- throws Exception {
-
- return createAndStartJetty(solrHome, new Properties(), jettyConfig);
- }
-
- protected static JettySolrRunner createAndStartJetty(Path solrHome) throws Exception {
- return createAndStartJetty(solrHome, new Properties(), JettyConfig.builder().build());
- }
-
- protected static JettySolrRunner createAndStartJetty(
- Path solrHome, Properties nodeProperties, JettyConfig jettyConfig) throws Exception {
-
- Path coresDir = createTempDir().resolve("cores");
-
- Properties props = new Properties();
- props.setProperty("name", DEFAULT_TEST_CORENAME);
- props.setProperty("configSet", "collection1");
- props.setProperty("config", "${solrconfig:solrconfig.xml}");
- props.setProperty("schema", "${schema:schema.xml}");
-
- writeCoreProperties(coresDir.resolve("core"), props, "RestTestBase");
-
- Properties nodeProps = new Properties(nodeProperties);
- nodeProps.setProperty("coreRootDirectory", coresDir.toString());
- nodeProps.setProperty("configSetBaseDir", solrHome.toString());
-
- solrClientTestRule.startSolr(solrHome, nodeProps, jettyConfig);
- return getJetty();
- }
-
- protected static JettySolrRunner getJetty() {
- return solrClientTestRule.getJetty();
- }
-
- /** URL to Solr */
- protected static String getBaseUrl() {
- return solrClientTestRule.getBaseUrl();
- }
-
- /** URL to the core */
- protected static String getCoreUrl() {
- return getBaseUrl() + "/" + DEFAULT_TEST_CORENAME;
- }
-
- protected SolrClient getSolrClient() {
- return solrClientTestRule.getSolrClient();
- }
-
- /**
- * Create a new solr client. If createJetty was called, an http implementation will be created,
- * otherwise an embedded implementation will be created. Subclasses should override for other
- * options.
- */
- public SolrClient createNewSolrClient() {
- return new HttpSolrClient.Builder(getBaseUrl())
- .withDefaultCollection(DEFAULT_TEST_CORENAME)
- .build();
- }
-
- protected HttpClient getHttpClient() {
- HttpSolrClient client = (HttpSolrClient) getSolrClient();
- return client.getHttpClient();
- }
-
- // Sets up the necessary config files for Jetty. At least some tests require that the solrconfig
- // from the test file directory are used, but some also require that the solr.xml file be
- // explicitly there as of SOLR-4817
- @Deprecated // Instead use a basic config + whatever is needed or default config
- protected static void setupJettyTestHome(Path solrHome, String collection) throws Exception {
- copySolrHomeToTemp(solrHome, collection);
- }
-
- protected static void cleanUpJettyHome(Path solrHome) throws Exception {
- if (Files.exists(solrHome)) {
- PathUtils.deleteDirectory(solrHome);
- }
- }
-}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index e00ff7f5a8f..76c251e0769 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -2231,10 +2231,13 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
copyMinConf(dstRoot, null);
}
- // Creates a minimal conf dir, adding in a core.properties file from the string passed in
- // the string to write to the core.properties file may be null in which case nothing is done with
- // it.
- // propertiesContent may be an empty string, which will actually work.
+ /**
+ * Creates a minimal Solr configuration directory with default solrconfig. Adds in a
+ * core.properties if propertiesContent is provided.
+ *
+ * @param dstRoot the destination directory where conf/ will be created
+ * @param propertiesContent content for core.properties file, or null to skip creating it
+ */
public static void copyMinConf(Path dstRoot, String propertiesContent) throws IOException {
copyMinConf(dstRoot, propertiesContent, "solrconfig-minimal.xml");
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
index 8856625d331..644f1a638ab 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
@@ -20,21 +20,31 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.util.Map;
+import java.util.Properties;
import java.util.SortedMap;
import javax.xml.xpath.XPathExpressionException;
+import org.apache.http.client.HttpClient;
import org.apache.solr.JSONTestUtil;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.apache.HttpSolrClient;
import org.apache.solr.common.params.MultiMapSolrParams;
import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.servlet.SolrRequestParsers;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.junit.AfterClass;
+import org.junit.ClassRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
-public abstract class RestTestBase extends SolrJettyTestBase {
+public abstract class RestTestBase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
protected static RestTestHarness restTestHarness;
@AfterClass
@@ -57,7 +67,76 @@ public abstract class RestTestBase extends SolrJettyTestBase {
createAndStartJetty(solrHome, configFile, schemaFile, context, stopAtShutdown, extraServlets);
- restTestHarness = new RestTestHarness(() -> getCoreUrl());
+ restTestHarness = new RestTestHarness(RestTestBase::getCoreUrl);
+ }
+
+ protected static JettySolrRunner createAndStartJetty(
+ Path solrHome,
+ String configFile,
+ String schemaFile,
+ String context,
+ boolean stopAtShutdown,
+ SortedMap<ServletHolder, String> extraServlets)
+ throws Exception {
+ // creates the data dir
+
+ assert context == null || context.equals("/solr"); // deprecated
+
+ JettyConfig jettyConfig =
+ JettyConfig.builder().stopAtShutdown(stopAtShutdown).withServlets(extraServlets).build();
+
+ Properties nodeProps = new Properties();
+ if (configFile != null) nodeProps.setProperty("solrconfig", configFile);
+ if (schemaFile != null) nodeProps.setProperty("schema", schemaFile);
+ if (System.getProperty("solr.data.dir") == null) {
+ nodeProps.setProperty("solr.data.dir", createTempDir().toRealPath().toString());
+ }
+
+ return createAndStartJetty(solrHome, nodeProps, jettyConfig);
+ }
+
+ protected static JettySolrRunner createAndStartJetty(
+ Path solrHome, Properties nodeProperties, JettyConfig jettyConfig) throws Exception {
+
+ Path coresDir = createTempDir().resolve("cores");
+
+ Properties props = new Properties();
+ props.setProperty("name", DEFAULT_TEST_CORENAME);
+ props.setProperty("configSet", "collection1");
+ props.setProperty("config", "${solrconfig:solrconfig.xml}");
+ props.setProperty("schema", "${schema:schema.xml}");
+
+ writeCoreProperties(coresDir.resolve("core"), props, "RestTestBase");
+
+ Properties nodeProps = new Properties(nodeProperties);
+ nodeProps.setProperty("coreRootDirectory", coresDir.toString());
+ nodeProps.setProperty("configSetBaseDir", solrHome.toString());
+
+ solrTestRule.startSolr(solrHome, nodeProps, jettyConfig);
+ return getJetty();
+ }
+
+ protected static JettySolrRunner getJetty() {
+ return solrTestRule.getJetty();
+ }
+
+ /** URL to Solr */
+ protected static String getBaseUrl() {
+ return solrTestRule.getBaseUrl();
+ }
+
+ /** URL to the core */
+ protected static String getCoreUrl() {
+ return getBaseUrl() + "/" + DEFAULT_TEST_CORENAME;
+ }
+
+ protected static SolrClient getSolrClient() {
+ return solrTestRule.getSolrClient();
+ }
+
+ protected static HttpClient getHttpClient() {
+ HttpSolrClient client = (HttpSolrClient) getSolrClient();
+ return client.getHttpClient();
}
/** Validates an update XML String is successful */
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java b/solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java
index 653c165b16c..ad37a04741d 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java
@@ -79,9 +79,14 @@ public abstract class SolrClientTestRule extends ExternalResource {
if (configSet.endsWith(confSuffix)) {
configSet = configSet.substring(0, configSet.length() - confSuffix.length());
}
+ this.configSet = configSet;
}
- this.configSet = configSet;
+ return this;
+ }
+
+ public NewCollectionBuilder withConfigSet(Path configSet) {
+ withConfigSet(configSet.toString());
return this;
}
diff --git a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/BasicHttpSolrClientTest.java b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/BasicHttpSolrClientTest.java
index c56d452d272..c2b87f70419 100644
--- a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/BasicHttpSolrClientTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/BasicHttpSolrClientTest.java
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.http.Header;
@@ -44,7 +45,6 @@ import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.HttpContext;
-import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.api.util.SolrVersion;
import org.apache.solr.client.solrj.RemoteSolrException;
@@ -71,13 +71,17 @@ import org.apache.solr.util.ServletFixtures.DebugServlet;
import org.apache.solr.util.ServletFixtures.RedirectServlet;
import org.apache.solr.util.ServletFixtures.SlowServlet;
import org.apache.solr.util.ServletFixtures.SlowStreamServlet;
+import org.apache.solr.util.SolrJettyTestRule;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class BasicHttpSolrClientTest extends SolrJettyTestBase {
+public class BasicHttpSolrClientTest extends SolrTestCaseJ4 {
+
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String UA_VERSION = SolrVersion.LATEST_STRING;
@@ -91,7 +95,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
.withServlet(new ServletHolder(DebugServlet.class), "/debug/*")
.withServlet(new ServletHolder(SlowStreamServlet.class), "/slowStream/*")
.build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
}
@Test
@@ -100,7 +104,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
final var queryRequest = new QueryRequest(q);
queryRequest.setPath("/slow/foo" + queryRequest.getPath());
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(2000, TimeUnit.MILLISECONDS)
.build()) {
@@ -122,7 +126,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
ErrorCode.UNKNOWN,
ErrorCode.getErrorCode(status));
- try (SolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
DebugServlet.setErrorCode(status);
SolrQuery q = new SolrQuery("foo");
final var queryRequest = new QueryRequest(q);
@@ -142,7 +146,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
q.setParam("a", "\u1234");
final var queryRequest = new QueryRequest(q);
queryRequest.setPath(debugPath);
- try (HttpSolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (HttpSolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
expectThrows(RemoteSolrException.class, () -> queryRequest.process(client));
@@ -212,7 +216,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
// XML
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withResponseParser(new XMLResponseParser())
.build()) {
// XML/GET
@@ -281,7 +285,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
DebugServlet.clear();
final String debugPath = "/debug/foo";
- try (HttpSolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (HttpSolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
final UpdateRequest deleteById = new UpdateRequest();
deleteById.deleteById("id");
deleteById.setPath(debugPath + deleteById.getPath());
@@ -306,7 +310,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
// XML
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withResponseParser(new XMLResponseParser())
.build()) {
final var deleteByQueryRequest = new UpdateRequest();
@@ -331,7 +335,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
@Test
public void testGetById() throws Exception {
DebugServlet.clear();
- try (SolrClient client = getHttpSolrClient(getBaseUrl() + "/debug/foo")) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl() + "/debug/foo")) {
Collection<String> ids = Collections.singletonList("a");
expectThrows(RemoteSolrException.class, () -> client.getById("a"));
expectThrows(RemoteSolrException.class, () -> client.getById(ids, null));
@@ -345,7 +349,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
DebugServlet.clear();
final String debugPath = "/debug/foo";
- try (HttpSolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (HttpSolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
UpdateRequest req = new UpdateRequest();
req.add(new SolrInputDocument());
req.setPath(debugPath + req.getPath());
@@ -370,7 +374,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
DebugServlet.clear();
// XML response and writer
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withRequestWriter(new XMLRequestWriter())
.withResponseParser(new XMLResponseParser())
.build()) {
@@ -394,7 +398,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
DebugServlet.clear();
// javabin request
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withRequestWriter(new JavaBinRequestWriter())
.withResponseParser(new JavaBinResponseParser())
.build()) {
@@ -425,21 +429,21 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
queryRequest.setPath(redirectPath + queryRequest.getPath());
// default for redirect is false.
- try (HttpSolrClient client = new HttpSolrClient.Builder(getBaseUrl()).build()) {
+ try (HttpSolrClient client = new HttpSolrClient.Builder(solrTestRule.getBaseUrl()).build()) {
SolrServerException e =
expectThrows(SolrServerException.class, () -> queryRequest.process(client));
assertTrue(e.getMessage().contains("redirect"));
}
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl()).withFollowRedirects(true).build()) {
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl()).withFollowRedirects(true).build()) {
// No exception expected
queryRequest.process(client);
}
// And with explicit false:
try (HttpSolrClient client =
- new HttpSolrClient.Builder(getBaseUrl()).withFollowRedirects(false).build()) {
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl()).withFollowRedirects(false).build()) {
SolrServerException e =
expectThrows(SolrServerException.class, () -> queryRequest.process(client));
assertTrue(e.getMessage().contains("redirect"));
@@ -453,7 +457,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
final var queryRequest = new QueryRequest(q);
queryRequest.setPath(debugPath + queryRequest.getPath());
- try (SolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
// verify request header gets set
DebugServlet.clear();
expectThrows(RemoteSolrException.class, () -> queryRequest.process(client));
@@ -461,7 +465,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
}
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl()).allowCompression(true).build()) {
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl()).allowCompression(true).build()) {
try {
queryRequest.process(client);
} catch (RemoteSolrException ignored) {
@@ -470,7 +474,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
}
try (SolrClient client =
- new HttpSolrClient.Builder(getBaseUrl()).allowCompression(false).build()) {
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl()).allowCompression(false).build()) {
try {
queryRequest.process(client);
} catch (RemoteSolrException ignored) {
@@ -479,7 +483,9 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
assertNull(DebugServlet.headers.get("accept-encoding"));
// verify server compresses output
- HttpGet get = new HttpGet(getCoreUrl() + "/select?q=foo&wt=xml");
+ HttpGet get =
+ new HttpGet(
+ solrTestRule.getBaseUrl() + "/" + DEFAULT_TEST_CORENAME + "/select?q=foo&wt=xml");
get.setHeader("Accept-Encoding", "gzip");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true);
@@ -504,7 +510,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
}
// verify compressed response can be handled
- try (SolrClient client = getHttpSolrClient(getBaseUrl(), DEFAULT_TEST_COLLECTION_NAME)) {
+ try (SolrClient client =
+ getHttpSolrClient(solrTestRule.getBaseUrl(), DEFAULT_TEST_COLLECTION_NAME)) {
QueryResponse response = client.query(new SolrQuery("foo"));
assertEquals(0, response.getStatus());
}
@@ -513,7 +520,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
@Test
public void testCollectionParameters() throws IOException, SolrServerException {
- try (SolrClient client = getHttpSolrClient(getBaseUrl())) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "collection");
client.add("collection1", doc);
@@ -524,7 +531,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
client.query("collection1", new SolrQuery("id:collection")).getResults().getNumFound());
}
- try (SolrClient client = getHttpSolrClient(getBaseUrl(), DEFAULT_TEST_CORENAME)) {
+ try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl(), DEFAULT_TEST_CORENAME)) {
assertEquals(1, client.query(new SolrQuery("id:collection")).getResults().getNumFound());
}
}
@@ -533,7 +540,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
public void testGetRawStream() throws SolrServerException, IOException {
CloseableHttpClient httpClient = HttpClientUtil.createClient(null);
try (SolrClient solrClient =
- new HttpSolrClient.Builder(getBaseUrl())
+ new HttpSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withHttpClient(httpClient)
.withResponseParser(null)
@@ -581,7 +588,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue);
cookie.setVersion(0);
cookie.setPath("/");
- cookie.setDomain(getJetty().getBaseUrl().getHost());
+ cookie.setDomain(solrTestRule.getJetty().getBaseUrl().getHost());
CookieStore cookieStore = new BasicCookieStore();
CookieSpec cookieSpec = new SolrPortAwareCookieSpecFactory().create(context);
@@ -606,7 +613,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
HttpClientUtil.addRequestInterceptor(cookieSettingRequestInterceptor);
final String debugPath = "/debug/foo";
- try (SolrClient server = getHttpSolrClient(getBaseUrl())) {
+ try (SolrClient server = getHttpSolrClient(solrTestRule.getBaseUrl())) {
SolrQuery q = new SolrQuery("foo");
q.setParam("a", "\u1234");
@@ -675,7 +682,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
@Test
public void testQueryString() throws Exception {
final String debugPath = "/debug/foo";
- HttpSolrClient.Builder builder = new HttpSolrClient.Builder(getBaseUrl());
+ HttpSolrClient.Builder builder = new HttpSolrClient.Builder(solrTestRule.getBaseUrl());
try (HttpSolrClient client =
builder.withTheseParamNamesInTheUrl(Set.of("serverOnly")).build()) {
// test without request query params
@@ -730,7 +737,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
public void testInvariantParams() throws IOException {
try (HttpSolrClient createdClient =
new HttpSolrClient.Builder()
- .withBaseSolrUrl(getBaseUrl())
+ .withBaseSolrUrl(solrTestRule.getBaseUrl())
.withInvariantParams(SolrTestCaseJ4.params("param", "value"))
.build()) {
assertEquals("value", createdClient.getInvariantParams().get("param"));
@@ -738,7 +745,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {
try (HttpSolrClient createdClient =
new HttpSolrClient.Builder()
- .withBaseSolrUrl(getBaseUrl())
+ .withBaseSolrUrl(solrTestRule.getBaseUrl())
.withInvariantParams(SolrTestCaseJ4.params("fq", "fq1", "fq", "fq2"))
.build()) {
assertEquals(2, createdClient.getInvariantParams().getParams("fq").length);
diff --git a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientBadInputTest.java b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientBadInputTest.java
index 55bc43e598d..51202442729 100644
--- a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientBadInputTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientBadInputTest.java
@@ -19,13 +19,18 @@ package org.apache.solr.client.solrj.apache;
import java.util.ArrayList;
import java.util.List;
-import org.apache.solr.SolrJettyTestBase;
+import java.util.Properties;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
-public class ConcurrentUpdateSolrClientBadInputTest extends SolrJettyTestBase {
+public class ConcurrentUpdateSolrClientBadInputTest extends SolrTestCaseJ4 {
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
private static final List<String> NULL_STR_LIST = null;
private static final List<String> EMPTY_STR_LIST = new ArrayList<>();
private static final String ANY_COLLECTION = "ANY_COLLECTION";
@@ -35,13 +40,14 @@ public class ConcurrentUpdateSolrClientBadInputTest extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome(), JettyConfig.builder().build());
+ solrTestRule.startSolr(
+ legacyExampleCollection1SolrHome(), new Properties(), JettyConfig.builder().build());
}
@Test
public void testDeleteByIdReportsInvalidIdLists() throws Exception {
try (SolrClient client =
- new ConcurrentUpdateSolrClient.Builder(getBaseUrl())
+ new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(ANY_COLLECTION)
.withQueueSize(ANY_QUEUE_SIZE)
.withThreadCount(ANY_MAX_NUM_THREADS)
@@ -73,7 +79,7 @@ public class ConcurrentUpdateSolrClientBadInputTest extends SolrJettyTestBase {
}
try (SolrClient client =
- new ConcurrentUpdateSolrClient.Builder(getBaseUrl())
+ new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl())
.withQueueSize(ANY_QUEUE_SIZE)
.withThreadCount(ANY_MAX_NUM_THREADS)
.build()) {
diff --git a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientTest.java b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientTest.java
index 8eb35f15039..dc0755ef5af 100644
--- a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/ConcurrentUpdateSolrClientTest.java
@@ -27,11 +27,12 @@ import java.lang.invoke.MethodHandles;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.HttpResponse;
-import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec;
@@ -41,13 +42,17 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.embedded.JettyConfig;
+import org.apache.solr.util.SolrJettyTestRule;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
+public class ConcurrentUpdateSolrClientTest extends SolrTestCaseJ4 {
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
+
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
/** Mock endpoint where the CUSS being tested in this class sends requests. */
@@ -130,14 +135,14 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
public static void beforeTest() throws Exception {
JettyConfig jettyConfig =
JettyConfig.builder().withServlet(new ServletHolder(TestServlet.class), "/cuss/*").build();
- createAndStartJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome(), new Properties(), jettyConfig);
}
@Test
public void testConcurrentUpdate() throws Exception {
TestServlet.clear();
- String serverUrl = getBaseUrl() + "/cuss/foo";
+ String serverUrl = solrTestRule.getBaseUrl() + "/cuss/foo";
int cussThreadCount = 2;
int cussQueueSize = 100;
@@ -205,7 +210,7 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
int cussQueueSize = 10;
try (ConcurrentUpdateSolrClient concurrentClient =
- (new ConcurrentUpdateSolrClient.Builder(getBaseUrl()))
+ (new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl()))
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
.build()) {
@@ -224,7 +229,7 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
}
try (ConcurrentUpdateSolrClient concurrentClient =
- (new ConcurrentUpdateSolrClient.Builder(getBaseUrl()))
+ (new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl()))
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
@@ -245,7 +250,7 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
int expected = numDocs * numRunnables;
try (ConcurrentUpdateSolrClient concurrentClient =
- (new ConcurrentUpdateSolrClient.Builder(getBaseUrl()))
+ (new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl()))
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
.withPollQueueTime(0)
@@ -281,7 +286,7 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
}
try (ConcurrentUpdateSolrClient concurrentClient =
- (new ConcurrentUpdateSolrClient.Builder(getBaseUrl()))
+ (new ConcurrentUpdateSolrClient.Builder(solrTestRule.getBaseUrl()))
.withDefaultCollection(DEFAULT_TEST_CORENAME)
.withQueueSize(cussQueueSize)
.withThreadCount(cussThreadCount)
diff --git a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientConPoolTest.java b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientConPoolTest.java
index 3104e264c91..c1ac4215f98 100644
--- a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientConPoolTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientConPoolTest.java
@@ -25,8 +25,7 @@ import java.util.concurrent.ExecutorService;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.pool.PoolStats;
-import org.apache.solr.SolrJettyTestBase;
-import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.LBSolrClient;
import org.apache.solr.client.solrj.request.SolrQuery;
@@ -39,16 +38,17 @@ import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
import org.junit.ClassRule;
-public class HttpSolrClientConPoolTest extends SolrJettyTestBase {
+public class HttpSolrClientConPoolTest extends SolrTestCaseJ4 {
+ @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
@ClassRule public static SolrJettyTestRule secondJetty = new SolrJettyTestRule();
private static String fooUrl; // first Jetty URL
private static String barUrl; // second Jetty URL
@BeforeClass
- public static void beforeTest() throws Exception {
- createAndStartJetty(legacyExampleCollection1SolrHome());
- fooUrl = getBaseUrl();
+ public static void beforeTest() {
+ solrTestRule.startSolr(legacyExampleCollection1SolrHome());
+ fooUrl = solrTestRule.getBaseUrl();
secondJetty.startSolr(legacyExampleCollection1SolrHome());
barUrl = secondJetty.getBaseUrl();
@@ -113,7 +113,6 @@ public class HttpSolrClientConPoolTest extends SolrJettyTestBase {
public void testLBClient() throws IOException, SolrServerException {
PoolingHttpClientConnectionManager pool = HttpClientUtil.createPoolingConnectionManager();
- final SolrClient client1;
int threadCount = atLeast(2);
final ExecutorService threads =
ExecutorUtil.newMDCAwareFixedThreadPool(
diff --git a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientSSLAuthConPoolTest.java b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientSSLAuthConPoolTest.java
index 6fd123ca72e..4238a7ed2cf 100644
--- a/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientSSLAuthConPoolTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/client/solrj/apache/HttpSolrClientSSLAuthConPoolTest.java
@@ -25,8 +25,9 @@ import org.junit.BeforeClass;
public class HttpSolrClientSSLAuthConPoolTest extends HttpSolrClientConPoolTest {
@BeforeClass
- public static void checkUrls() throws Exception {
- URL[] urls = new URL[] {getJetty().getBaseUrl(), secondJetty.getJetty().getBaseUrl()};
+ public static void checkUrls() {
+ URL[] urls =
+ new URL[] {solrTestRule.getJetty().getBaseUrl(), secondJetty.getJetty().getBaseUrl()};
for (URL u : urls) {
assertEquals("expect https urls ", "https", u.getProtocol());
}