You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2024/02/06 12:32:22 UTC
(solr) branch branch_9x updated: Reinstate "SOLR-17066: Switch HttpSolrClient away from coreURLs, pt 2 (#2231)""
This is an automated email from the ASF dual-hosted git repository.
gerlowskija pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 901a3099c93 Reinstate "SOLR-17066: Switch HttpSolrClient away from coreURLs, pt 2 (#2231)""
901a3099c93 is described below
commit 901a3099c93953e7be333b2d5fd15b92d5ed2966
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Mon Feb 5 09:54:32 2024 -0500
Reinstate "SOLR-17066: Switch HttpSolrClient away from coreURLs, pt 2 (#2231)""
This commit fixes a bug in a previously committed (and then reverted)
change e8ac06.
The root of the problem lies in how Solr handles context-roots. Solr 9
allows configurable and arbitrary context roots, while Solr 10 disallows
this practice.
This difference wasn't accounted for when backporting the core URL
removal to branch_9x, causing a large number of test failures due to
some assumptions around what a path should look like. These assumptions
were valid for Solr 10 (i.e. `main`) but invalid for Solr 9.
In order to reinstate this commit on branch_9x, the commit no longer
inspects and splits user-provided URLs when creating clients. Instead,
it relies on thorough javadocs to clarify that use of core URLs is
(1) deprecated, and (2) mutually exclusive with the
`withDefaultCollection` builder option.
---
.../client/solrj/impl/ConnectionReuseTest.java | 3 +-
.../apache/solr/cloud/LeaderTragicEventTest.java | 11 ++--
.../test/org/apache/solr/cloud/RouteFieldTest.java | 20 ++++---
.../cloud/TestLeaderElectionWithEmptyReplica.java | 3 +-
.../org/apache/solr/cloud/TestPullReplica.java | 15 ++++-
.../solr/cloud/TestRandomRequestDistribution.java | 10 ++--
.../org/apache/solr/cloud/TestTlogReplica.java | 15 ++++-
.../solr/cloud/api/collections/ShardSplitTest.java | 3 +-
.../apache/solr/handler/ReplicationTestHelper.java | 12 ++++
.../handler/TestHealthCheckHandlerLegacyMode.java | 4 +-
.../solr/handler/TestReplicationHandler.java | 56 ++++++++----------
.../TestReplicationHandlerDiskOverFlow.java | 8 +--
.../solr/handler/admin/CoreAdminHandlerTest.java | 15 +++--
.../DistributedQueryElevationComponentTest.java | 3 +-
.../solr/handler/component/SearchHandlerTest.java | 13 +++-
.../src/test/org/apache/solr/pkg/TestPackages.java | 10 ++++
.../solr/update/DeleteByIdWithRouterFieldTest.java | 5 +-
.../hadoop/TestImpersonationWithHadoopAuth.java | 3 +-
.../TestSolrCloudWithSecureImpersonation.java | 3 +-
.../org/apache/solr/hdfs/cloud/StressHdfsTest.java | 3 +-
.../solr/client/solrj/io/SolrClientCache.java | 18 ++++--
.../impl/ConcurrentUpdateHttp2SolrClient.java | 69 +++++++++++++++++++++-
.../solrj/impl/ConcurrentUpdateSolrClient.java | 18 ++++--
.../solr/client/solrj/impl/Http2SolrClient.java | 49 ++++++++++++++-
.../solr/client/solrj/impl/HttpSolrClient.java | 17 ++++--
.../solr/client/solrj/impl/LBHttp2SolrClient.java | 38 +++++++++++-
.../solr/client/solrj/impl/LBHttpSolrClient.java | 27 ++++++---
.../solr/client/solrj/impl/SolrClientBuilder.java | 7 ++-
.../java/org/apache/solr/common/util/URLUtil.java | 10 ++++
.../solr/client/solrj/SolrExampleTestsBase.java | 2 +-
30 files changed, 367 insertions(+), 103 deletions(-)
diff --git a/solr/core/src/test/org/apache/solr/client/solrj/impl/ConnectionReuseTest.java b/solr/core/src/test/org/apache/solr/client/solrj/impl/ConnectionReuseTest.java
index e68ea8722bf..20965ef6cb6 100644
--- a/solr/core/src/test/org/apache/solr/client/solrj/impl/ConnectionReuseTest.java
+++ b/solr/core/src/test/org/apache/solr/client/solrj/impl/ConnectionReuseTest.java
@@ -89,7 +89,8 @@ public class ConnectionReuseTest extends SolrCloudTestCase {
.withThreadCount(1)
.build();
case 1:
- return new HttpSolrClient.Builder(url.toString() + "/" + COLLECTION)
+ return new HttpSolrClient.Builder(url.toString())
+ .withDefaultCollection(COLLECTION)
.withHttpClient(httpClient)
.build();
case 2:
diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
index b2c3e6eab6d..a1453f07cc2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
@@ -113,7 +113,10 @@ public class LeaderTragicEventTest extends SolrCloudTestCase {
// Check that we can continue indexing after this
updateResponse = new UpdateRequest().add("id", "2").commit(cluster.getSolrClient(), collection);
assertEquals(0, updateResponse.getStatus());
- try (SolrClient followerClient = new HttpSolrClient.Builder(oldLeader.getCoreUrl()).build()) {
+ try (SolrClient followerClient =
+ new HttpSolrClient.Builder(oldLeader.getBaseUrl())
+ .withDefaultCollection(oldLeader.getCoreName())
+ .build()) {
QueryResponse queryResponse = new QueryRequest(new SolrQuery("*:*")).process(followerClient);
assertEquals(
queryResponse.getResults().toString(), 2, queryResponse.getResults().getNumFound());
@@ -128,9 +131,9 @@ public class LeaderTragicEventTest extends SolrCloudTestCase {
Replica oldLeader = dc.getLeader("shard1");
log.info("Will crash leader : {}", oldLeader);
- try (SolrClient solrClient =
- new HttpSolrClient.Builder(dc.getLeader("shard1").getCoreUrl()).build()) {
- new UpdateRequest().add("id", "99").commit(solrClient, null);
+ final Replica leaderReplica = dc.getLeader("shard1");
+ try (SolrClient solrClient = new HttpSolrClient.Builder(leaderReplica.getBaseUrl()).build()) {
+ new UpdateRequest().add("id", "99").commit(solrClient, leaderReplica.getCoreName());
fail("Should have injected tragedy");
} catch (RemoteSolrException e) {
// solrClient.add would throw RemoteSolrException with code 500
diff --git a/solr/core/src/test/org/apache/solr/cloud/RouteFieldTest.java b/solr/core/src/test/org/apache/solr/cloud/RouteFieldTest.java
index 3884f14134d..22afebb4fb3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/RouteFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/RouteFieldTest.java
@@ -38,6 +38,7 @@ import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.URLUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
@@ -154,13 +155,8 @@ public class RouteFieldTest extends SolrCloudTestCase {
params.add(CommonParams.SORT, "sorter asc");
params.add(CommonParams.ROWS, "1000");
- SolrClient solrClient = new HttpSolrClient.Builder(urlId).build();
- SolrDocumentList docsId = (SolrDocumentList) solrClient.request(request).get("response");
- solrClient.close();
-
- solrClient = new HttpSolrClient.Builder(urlRoute).build();
- SolrDocumentList docsRoute = (SolrDocumentList) solrClient.request(request).get("response");
- solrClient.close();
+ final var docsId = getDocsMatching(urlId, request);
+ final var docsRoute = getDocsMatching(urlRoute, request);
assertEquals(
"We should have the exact same number of docs on each shard",
@@ -175,4 +171,14 @@ public class RouteFieldTest extends SolrCloudTestCase {
idRoute - 1_500_000);
}
}
+
+ private SolrDocumentList getDocsMatching(String coreUrl, QueryRequest request)
+ throws IOException, SolrServerException {
+ final var baseUrl = URLUtil.extractBaseUrl(coreUrl);
+ final var coreName = URLUtil.extractCoreFromCoreUrl(coreUrl);
+ try (SolrClient solrClient =
+ new HttpSolrClient.Builder(baseUrl).withDefaultCollection(coreName).build()) {
+ return (SolrDocumentList) solrClient.request(request).get("response");
+ }
+ }
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionWithEmptyReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionWithEmptyReplica.java
index 97df978bd10..5bab0e126b9 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionWithEmptyReplica.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionWithEmptyReplica.java
@@ -118,7 +118,8 @@ public class TestLeaderElectionWithEmptyReplica extends SolrCloudTestCase {
int count = 0;
for (Replica replica : shard.getReplicas()) {
SolrClient client =
- new Builder(replica.getCoreUrl())
+ new Builder(replica.getBaseUrl())
+ .withDefaultCollection(replica.getCoreName())
.withHttpClient(((CloudLegacySolrClient) cloudClient).getHttpClient())
.build();
QueryResponse response = client.query(new SolrQuery("q", "*:*", "distrib", "false"));
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java
index a5b0ee21781..fd6d6eb7742 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java
@@ -464,7 +464,10 @@ public class TestPullReplica extends SolrCloudTestCase {
List<String> ids = new ArrayList<>(slice.getReplicas().size());
for (Replica rAdd : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rAdd.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rAdd.getBaseUrl())
+ .withDefaultCollection(rAdd.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
}
SolrDocument docCloudClient =
@@ -472,7 +475,10 @@ public class TestPullReplica extends SolrCloudTestCase {
assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
for (Replica rGet : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rGet.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rGet.getBaseUrl())
+ .withDefaultCollection(rGet.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
SolrDocument doc = client.getById(String.valueOf(id));
assertEquals("bar", doc.getFieldValue("foo_s"));
}
@@ -483,7 +489,10 @@ public class TestPullReplica extends SolrCloudTestCase {
SolrDocumentList previousAllIdsResult = null;
for (Replica rAdd : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rAdd.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rAdd.getBaseUrl())
+ .withDefaultCollection(rAdd.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
SolrDocumentList allIdsResult = client.getById(ids);
if (previousAllIdsResult != null) {
assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java b/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java
index 768f258cc50..9bf2777975e 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java
@@ -110,7 +110,8 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
String baseUrl = replicas.iterator().next().getBaseUrl();
if (!baseUrl.endsWith("/")) baseUrl += "/";
try (SolrClient client =
- new HttpSolrClient.Builder(baseUrl + "a1x2")
+ new HttpSolrClient.Builder(baseUrl)
+ .withDefaultCollection("a1x2")
.withConnectionTimeout(2000, TimeUnit.MILLISECONDS)
.withSocketTimeout(5000, TimeUnit.MILLISECONDS)
.build()) {
@@ -221,11 +222,10 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
// Query against the node which hosts the down replica
String baseUrl = notLeader.getBaseUrl();
- if (!baseUrl.endsWith("/")) baseUrl += "/";
- String path = baseUrl + "football";
- log.info("Firing queries against path={}", path);
+ log.info("Firing queries against path={} and collection=football", baseUrl);
try (SolrClient client =
- new HttpSolrClient.Builder(path)
+ new HttpSolrClient.Builder(baseUrl)
+ .withDefaultCollection("football")
.withConnectionTimeout(2000, TimeUnit.MILLISECONDS)
.withSocketTimeout(5000, TimeUnit.MILLISECONDS)
.build()) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
index 937b8f1fe17..c3baa8e5486 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java
@@ -406,7 +406,10 @@ public class TestTlogReplica extends SolrCloudTestCase {
List<String> ids = new ArrayList<>(slice.getReplicas().size());
for (Replica rAdd : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rAdd.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rAdd.getBaseUrl())
+ .withDefaultCollection(rAdd.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
}
SolrDocument docCloudClient =
@@ -415,7 +418,10 @@ public class TestTlogReplica extends SolrCloudTestCase {
assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
for (Replica rGet : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rGet.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rGet.getBaseUrl())
+ .withDefaultCollection(rGet.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
SolrDocument doc = client.getById(String.valueOf(id));
assertEquals("bar", doc.getFieldValue("foo_s"));
}
@@ -426,7 +432,10 @@ public class TestTlogReplica extends SolrCloudTestCase {
SolrDocumentList previousAllIdsResult = null;
for (Replica rAdd : slice.getReplicas()) {
try (SolrClient client =
- new HttpSolrClient.Builder(rAdd.getCoreUrl()).withHttpClient(httpClient).build()) {
+ new HttpSolrClient.Builder(rAdd.getBaseUrl())
+ .withDefaultCollection(rAdd.getCoreName())
+ .withHttpClient(httpClient)
+ .build()) {
SolrDocumentList allIdsResult = client.getById(ids);
if (previousAllIdsResult != null) {
assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java
index f252c23e901..3794840112a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java
@@ -307,7 +307,8 @@ public class ShardSplitTest extends BasicDistributedZkTest {
int count = 0;
for (Replica replica : shard.getReplicas()) {
var client =
- new HttpSolrClient.Builder(replica.getCoreUrl())
+ new HttpSolrClient.Builder(replica.getBaseUrl())
+ .withDefaultCollection(replica.getCoreName())
.withHttpClient(((CloudLegacySolrClient) cloudClient).getHttpClient())
.build();
QueryResponse response = client.query(new SolrQuery("q", "*:*", "distrib", "false"));
diff --git a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
index 83b60838b06..dd29908b1c1 100644
--- a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
+++ b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
@@ -64,8 +64,20 @@ public final class ReplicationTestHelper {
return jetty;
}
+ /**
+ * @param baseUrl the root URL for a Solr node
+ */
public static SolrClient createNewSolrClient(String baseUrl) {
+ return createNewSolrClient(baseUrl, null);
+ }
+
+ /**
+ * @param baseUrl the root URL for a Solr node
+ * @param collectionOrCore an optional default collection/core for the created client
+ */
+ public static SolrClient createNewSolrClient(String baseUrl, String collectionOrCore) {
return new HttpSolrClient.Builder(baseUrl)
+ .withDefaultCollection(collectionOrCore)
.withConnectionTimeout(15000, TimeUnit.MILLISECONDS)
.withSocketTimeout(90000, TimeUnit.MILLISECONDS)
.build();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java b/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java
index 1d3ecfeed62..3de554c1a4c 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestHealthCheckHandlerLegacyMode.java
@@ -62,7 +62,7 @@ public class TestHealthCheckHandlerLegacyMode extends SolrTestCaseJ4 {
leaderJetty = ReplicationTestHelper.createAndStartJetty(leader);
leaderClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(leaderJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(leaderJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
leaderClientHealthCheck =
ReplicationTestHelper.createNewSolrClient(buildUrl(leaderJetty.getLocalPort(), context));
@@ -73,7 +73,7 @@ public class TestHealthCheckHandlerLegacyMode extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(followerJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(followerJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
followerClientHealthCheck =
ReplicationTestHelper.createNewSolrClient(buildUrl(followerJetty.getLocalPort(), context));
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
index 175bf9bfc8f..1f245f4ed7f 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -125,7 +125,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(leaderJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(leaderJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
follower =
new SolrInstance(
@@ -134,7 +134,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(followerJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(followerJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
System.setProperty("solr.indexfetcher.sotimeout2", "45000");
}
@@ -302,10 +302,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderClient.close();
leaderClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(leaderJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(leaderJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
followerClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(followerJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(followerJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
clearIndexWithReplication();
{
@@ -375,7 +375,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
repeaterJetty = createAndStartJetty(repeater);
repeaterClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(repeaterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(repeaterJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
NamedList<Object> details = getDetails(repeaterClient);
@@ -409,7 +409,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
instanceJetty = createAndStartJetty(solrInstance);
client =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(instanceJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(instanceJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
NamedList<Object> details = getDetails(client);
@@ -568,8 +568,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
follower.setTestPort(leaderJetty.getLocalPort());
follower.copyConfigFile(follower.getSolrConfigFile(), "solrconfig.xml");
@@ -589,7 +588,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// add a doc with new field and commit on leader to trigger index fetch from follower.
index(leaderClient, "id", "2000", "name", "name = " + 2000, "newname", "newname = " + 2000);
leaderClient.commit();
@@ -676,7 +675,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// close and re-create leader client because its connection pool has stale connections
leaderClient.close();
leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
nDocs--;
for (int i = 0; i < nDocs; i++) index(leaderClient, "id", i, "name", "name = " + i);
@@ -812,7 +811,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerClient.close();
followerClient =
ReplicationTestHelper.createNewSolrClient(
- buildUrl(followerJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME);
+ buildUrl(followerJetty.getLocalPort(), context), DEFAULT_TEST_CORENAME);
leaderClient.deleteByQuery("*:*");
followerClient.deleteByQuery("*:*");
@@ -961,14 +960,14 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
leader.copyConfigFile(CONF_DIR + "solrconfig-leader3.xml", "solrconfig.xml");
leaderJetty.stop();
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
leaderClient.deleteByQuery("*:*");
followerClient.deleteByQuery("*:*");
@@ -1114,7 +1113,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
try {
repeater =
@@ -1127,7 +1126,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
repeaterClient.close();
}
repeaterClient =
- createNewSolrClient(buildUrl(repeaterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(repeaterJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
for (int i = 0; i < 3; i++) index(leaderClient, "id", i, "name", "name = " + i);
@@ -1195,8 +1194,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
for (int i = 0; i < nDocs; i++) index(leaderClient, "id", i, "name", "name = " + i);
@@ -1213,7 +1211,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// get docs from follower and check if number is equal to leader
NamedList<Object> followerQueryRsp = rQuery(nDocs, "*:*", followerClient);
@@ -1247,7 +1245,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
for (int i = 0; i < nDocs; i++) index(leaderClient, "id", i, "name", "name = " + i);
@@ -1272,7 +1270,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// get docs from follower and check if number is equal to leader
NamedList<Object> followerQueryRsp = rQuery(nDocs, "*:*", followerClient);
@@ -1303,8 +1301,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
leaderClient.deleteByQuery("*:*");
for (int i = 0; i < docs; i++) index(leaderClient, "id", i, "name", "name = " + i);
@@ -1322,7 +1319,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// get docs from follower and check if number is equal to leader
NamedList<Object> followerQueryRsp = rQuery(docs, "*:*", followerClient);
@@ -1399,8 +1396,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
follower.setTestPort(leaderJetty.getLocalPort());
follower.copyConfigFile(follower.getSolrConfigFile(), "solrconfig.xml");
@@ -1409,7 +1405,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
followerClient.deleteByQuery("*:*");
followerClient.commit();
@@ -1455,8 +1451,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
useFactory(null);
leaderJetty = createAndStartJetty(leader);
leaderClient.close();
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// index docs
final int totalDocs = TestUtil.nextInt(random(), 17, 53);
@@ -1483,8 +1478,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// Start again and replicate the data
useFactory(null);
leaderJetty = createAndStartJetty(leader);
- leaderClient =
- createNewSolrClient(buildUrl(leaderJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ leaderClient = createNewSolrClient(buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
// start follower
follower.setTestPort(leaderJetty.getLocalPort());
@@ -1492,7 +1486,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient.close();
followerClient =
- createNewSolrClient(buildUrl(followerJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME);
+ createNewSolrClient(buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
long startTime = System.nanoTime();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerDiskOverFlow.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerDiskOverFlow.java
index 9b35aa29cf5..c66a1dd7201 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerDiskOverFlow.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerDiskOverFlow.java
@@ -81,9 +81,7 @@ public class TestReplicationHandlerDiskOverFlow extends SolrTestCaseJ4 {
leaderJetty = createAndStartJetty(leader);
leaderClient =
ReplicationTestHelper.createNewSolrClient(
- TestReplicationHandler.buildUrl(leaderJetty.getLocalPort())
- + "/"
- + DEFAULT_TEST_CORENAME);
+ TestReplicationHandler.buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
System.setProperty(TEST_URL_ALLOW_LIST, leaderJetty.getBaseUrl().toString());
follower =
@@ -93,9 +91,7 @@ public class TestReplicationHandlerDiskOverFlow extends SolrTestCaseJ4 {
followerJetty = createAndStartJetty(follower);
followerClient =
ReplicationTestHelper.createNewSolrClient(
- TestReplicationHandler.buildUrl(followerJetty.getLocalPort())
- + "/"
- + DEFAULT_TEST_CORENAME);
+ TestReplicationHandler.buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
System.setProperty("solr.indexfetcher.sotimeout2", "45000");
}
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
index 0ab68fc397e..a175d0e072e 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java
@@ -306,7 +306,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
runner.start();
try (SolrClient client =
- new HttpSolrClient.Builder(runner.getBaseUrl() + "/corex")
+ new HttpSolrClient.Builder(runner.getBaseUrl().toString())
+ .withDefaultCollection("corex")
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.build()) {
@@ -379,7 +380,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
runner.start();
try (SolrClient client =
- new HttpSolrClient.Builder(runner.getBaseUrl() + "/corex")
+ new HttpSolrClient.Builder(runner.getBaseUrl().toString())
+ .withDefaultCollection("corex")
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.build()) {
@@ -390,7 +392,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
}
try (SolrClient client =
- new HttpSolrClient.Builder(runner.getBaseUrl() + "/corex")
+ new HttpSolrClient.Builder(runner.getBaseUrl().toString())
+ .withDefaultCollection("corex")
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.build()) {
@@ -414,7 +417,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
BaseHttpSolrClient.RemoteSolrException.class,
() -> {
try (SolrClient client =
- new HttpSolrClient.Builder(runner.getBaseUrl() + "/corex")
+ new HttpSolrClient.Builder(runner.getBaseUrl().toString())
+ .withDefaultCollection("corex")
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(DEFAULT_CONNECTION_TIMEOUT * 1000, TimeUnit.MILLISECONDS)
.build()) {
@@ -441,7 +445,8 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
runner.start();
try (SolrClient client =
- new HttpSolrClient.Builder(runner.getBaseUrl() + "/corex")
+ new HttpSolrClient.Builder(runner.getBaseUrl().toString())
+ .withDefaultCollection("corex")
.withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.withSocketTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
.build()) {
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java
index a27b6a6d3a7..4136090d6bf 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java
@@ -166,9 +166,10 @@ public class DistributedQueryElevationComponentTest extends BaseDistributedSearc
assertEquals(true, document.getFieldValue("[elevated]"));
// Force javabin format
- final String clientUrl = jettys.get(0).getBaseUrl() + "/" + "collection1";
+ final String clientUrl = jettys.get(0).getBaseUrl().toString();
try (SolrClient client =
new HttpSolrClient.Builder(clientUrl)
+ .withDefaultCollection("collection1")
.withResponseParser(new BinaryResponseParser())
.build(); ) {
SolrQuery solrQuery =
diff --git a/solr/core/src/test/org/apache/solr/handler/component/SearchHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/component/SearchHandlerTest.java
index 0f22a624093..95d89a7259a 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/SearchHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/SearchHandlerTest.java
@@ -157,7 +157,10 @@ public class SearchHandlerTest extends SolrTestCaseJ4 {
Replica replica = getRandomEntry(slice.getReplicas());
JettySolrRunner jetty = miniCluster.getReplicaJetty(replica);
// Use the replica's core URL to avoid ZK communication
- try (SolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).build()) {
+ try (SolrClient client =
+ new HttpSolrClient.Builder(replica.getBaseUrl())
+ .withDefaultCollection(replica.getCoreName())
+ .build()) {
jetty.getCoreContainer().getZkController().getZkClient().close();
rsp = req.process(client);
assertFalse(rsp.getResponseHeader().getBooleanArg("zkConnected"));
@@ -205,7 +208,9 @@ public class SearchHandlerTest extends SolrTestCaseJ4 {
JettySolrRunner disconnectedJetty = miniCluster.getReplicaJetty(disconnectedReplica);
// Use the replica's core URL to avoid ZK communication
try (SolrClient solrClient =
- new HttpSolrClient.Builder(disconnectedReplica.getCoreUrl()).build()) {
+ new HttpSolrClient.Builder(disconnectedReplica.getBaseUrl())
+ .withDefaultCollection(disconnectedReplica.getCoreName())
+ .build()) {
ignoreException("ZooKeeper is not connected");
disconnectedJetty.getCoreContainer().getZkController().getZkClient().close();
req.process(solrClient);
@@ -262,7 +267,9 @@ public class SearchHandlerTest extends SolrTestCaseJ4 {
}
Replica connectedReplica = connectedSlice.getReplicas().iterator().next();
try (SolrClient solrClient =
- new HttpSolrClient.Builder(connectedReplica.getCoreUrl()).build()) {
+ new HttpSolrClient.Builder(connectedReplica.getBaseUrl())
+ .withDefaultCollection(connectedReplica.getCoreName())
+ .build()) {
ignoreException("ZooKeeper is not connected");
ignoreException("no active servers hosting shard:");
JettySolrRunner disconnectedJetty = miniCluster.getReplicaJetty(disconnectedReplica);
diff --git a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
index a3f1917473d..d70aa372737 100644
--- a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
+++ b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java
@@ -440,6 +440,11 @@ public class TestPackages extends SolrCloudTestCase {
return new RequestWriter.StringPayloadContentWriter(
"{set:{PKG_VERSIONS:{mypkg : '1.1'}}}", ClientUtils.TEXT_JSON);
}
+
+ @Override
+ public boolean requiresCollection() {
+ return true;
+ }
}.process(cluster.getSolrClient());
add.version = "2.1";
@@ -464,6 +469,11 @@ public class TestPackages extends SolrCloudTestCase {
return new RequestWriter.StringPayloadContentWriter(
"{set:{PKG_VERSIONS:{mypkg : '2.1'}}}", ClientUtils.TEXT_JSON);
}
+
+ @Override
+ public boolean requiresCollection() {
+ return true;
+ }
}.process(cluster.getSolrClient());
// now, let's force every collection using 'mypkg' to refresh
diff --git a/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java b/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java
index df32ef6783b..e4339f045eb 100644
--- a/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java
@@ -81,7 +81,10 @@ public class DeleteByIdWithRouterFieldTest extends SolrCloudTestCase {
ClusterState clusterState = cluster.getSolrClient().getClusterState();
for (Replica replica : clusterState.getCollection(COLL).getReplicas()) {
- clients.add(new HttpSolrClient.Builder(replica.getCoreUrl()).build());
+ clients.add(
+ new HttpSolrClient.Builder(replica.getBaseUrl())
+ .withDefaultCollection(replica.getCoreName())
+ .build());
}
}
diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
index f9172efb9f3..a1eb218d609 100644
--- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
+++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
@@ -211,7 +211,8 @@ public class TestImpersonationWithHadoopAuth extends SolrCloudTestCase {
// try a command to each node, one of them must be forwarded
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
try (SolrClient client =
- new HttpSolrClient.Builder(jetty.getBaseUrl().toString() + "/" + collectionName)
+ new HttpSolrClient.Builder(jetty.getBaseUrl().toString())
+ .withDefaultCollection(collectionName)
.build()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "*:*");
diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithSecureImpersonation.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithSecureImpersonation.java
index 496ae2b9d7d..25c49f2ebde 100644
--- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithSecureImpersonation.java
+++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithSecureImpersonation.java
@@ -340,7 +340,8 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
// try a command to each node, one of them must be forwarded
for (JettySolrRunner jetty : miniCluster.getJettySolrRunners()) {
try (HttpSolrClient client =
- new HttpSolrClient.Builder(jetty.getBaseUrl().toString() + "/" + collectionName)
+ new HttpSolrClient.Builder(jetty.getBaseUrl().toString())
+ .withDefaultCollection(collectionName)
.build()) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "*:*");
diff --git a/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/StressHdfsTest.java b/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/StressHdfsTest.java
index 65ddfefa556..72acd6f5343 100644
--- a/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/StressHdfsTest.java
+++ b/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/StressHdfsTest.java
@@ -189,7 +189,8 @@ public class StressHdfsTest extends AbstractBasicDistributedZkTestBase {
int i = 0;
for (SolrClient client : clients) {
try (SolrClient c =
- new HttpSolrClient.Builder(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)
+ new HttpSolrClient.Builder(getBaseUrl(client))
+ .withDefaultCollection(DELETE_DATA_DIR_COLLECTION)
.withConnectionTimeout(30000, TimeUnit.MILLISECONDS)
.build()) {
int docCnt = random().nextInt(1000) + 1;
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
index 915d9fbafc7..b9276f087b6 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java
@@ -144,6 +144,14 @@ public class SolrClientCache implements Closeable {
return client;
}
+ /**
+ * Create (and cache) a SolrClient based around the provided URL
+ *
+ * @param baseUrl a Solr URL. May be either a "base" URL (i.e. ending in "/solr"), or point to a
+ * particular collection or core.
+ * @return a SolrClient configured to use the provided URL. The cache retains a reference to the
+ * returned client, and will close it when callers invoke {@link SolrClientCache#close()}
+ */
public synchronized SolrClient getHttpSolrClient(String baseUrl) {
ensureOpen();
Objects.requireNonNull(baseUrl, "Url cannot be null!");
@@ -161,8 +169,8 @@ public class SolrClientCache implements Closeable {
}
@Deprecated
- private static SolrClient newHttpSolrClient(String baseUrl, HttpClient httpClient) {
- HttpSolrClient.Builder builder = new HttpSolrClient.Builder(baseUrl);
+ private static SolrClient newHttpSolrClient(String url, HttpClient httpClient) {
+ final var builder = new HttpSolrClient.Builder(url);
adjustTimeouts(builder, httpClient);
return builder.build();
}
@@ -177,10 +185,10 @@ public class SolrClientCache implements Closeable {
}
private static Http2SolrClient.Builder newHttp2SolrClientBuilder(
- String baseUrl, Http2SolrClient http2SolrClient) {
- var builder = new Http2SolrClient.Builder(baseUrl);
+ String url, Http2SolrClient http2SolrClient) {
+ final var builder = new Http2SolrClient.Builder(url);
if (http2SolrClient != null) {
- builder = builder.withHttpClient(http2SolrClient);
+ builder.withHttpClient(http2SolrClient);
}
long idleTimeout = minSocketTimeout;
if (builder.getIdleTimeoutMillis() != null) {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
index d000933b41f..7394e69770a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
@@ -733,10 +733,72 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
protected boolean closeHttp2Client;
private long pollQueueTimeMillis;
+ /**
+ * Create a Builder object, based on the provided SolrClient and Solr URL.
+ *
+ * <p>Two different paths can be specified as a part of this URL:
+ *
+ * <p>1) A path pointing directly at a particular core
+ *
+ * <pre>
+ * SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder(client, "http://my-solr-server:8983/solr/core1").build();
+ * QueryResponse resp = client.query(new SolrQuery("*:*"));
+ * </pre>
+ *
+ * Note that when a core is provided in the base URL, queries and other requests can be made
+ * without mentioning the core explicitly. However, the client can only send requests to that
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
+ *
+ * <p>2) The path of the root Solr path ("/solr")
+ *
+ * <pre>
+ * SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder("http://my-solr-server:8983/solr").build();
+ * QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
+ * </pre>
+ *
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
+ */
public Builder(String baseSolrUrl, Http2SolrClient client) {
this(baseSolrUrl, client, false);
}
+ /**
+ * Create a Builder object, based on the provided SolrClient and Solr URL.
+ *
+ * <p>Two different paths can be specified as a part of this URL:
+ *
+ * <p>1) A path pointing directly at a particular core
+ *
+ * <pre>
+ * SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder(client, "http://my-solr-server:8983/solr/core1").build();
+ * QueryResponse resp = client.query(new SolrQuery("*:*"));
+ * </pre>
+ *
+ * Note that when a core is provided in the base URL, queries and other requests can be made
+ * without mentioning the core explicitly. However, the client can only send requests to that
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
+ *
+ * <p>2) The path of the root Solr path ("/solr")
+ *
+ * <pre>
+ * SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder("http://my-solr-server:8983/solr").build();
+ * QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
+ * </pre>
+ *
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
+ */
public Builder(String baseSolrUrl, Http2SolrClient client, boolean closeHttp2Client) {
this.baseSolrUrl = baseSolrUrl;
this.client = client;
@@ -816,7 +878,12 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
return this;
}
- /** Sets a default for core or collection based requests. */
+ /**
+ * Sets a default for core or collection based requests.
+ *
+ * <p>This method should not be used if the client is provided a Solr URL which already contains
+ * a core or collection name.
+ */
public Builder withDefaultCollection(String defaultCoreOrCollection) {
this.defaultCollection = defaultCoreOrCollection;
return this;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 2341ea3d4e2..6cfeb8bc0b1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -104,6 +104,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
this.internalHttpClient = (builder.httpClient == null);
this.client =
new HttpSolrClient.Builder(builder.baseSolrUrl)
+ .withDefaultCollection(builder.defaultCollection)
.withHttpClient(builder.httpClient)
.withConnectionTimeout(builder.connectionTimeoutMillis, TimeUnit.MILLISECONDS)
.withSocketTimeout(builder.socketTimeoutMillis, TimeUnit.MILLISECONDS)
@@ -329,7 +330,11 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
requestParams.set(CommonParams.VERSION, client.parser.getVersion());
String basePath = client.getBaseURL();
- if (update.getCollection() != null) basePath += "/" + update.getCollection();
+ if (update.getCollection() != null) {
+ basePath += "/" + update.getCollection();
+ } else if (client.getDefaultCollection() != null) {
+ basePath += "/" + client.getDefaultCollection();
+ }
method = new HttpPost(basePath + "/update" + requestParams.toQueryString());
@@ -883,7 +888,11 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
*
* Note that when a core is provided in the base URL, queries and other requests can be made
* without mentioning the core explicitly. However, the client can only send requests to that
- * core.
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
*
* <p>2) The path of the root Solr path ("/solr")
*
@@ -892,8 +901,9 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
* QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
* </pre>
*
- * In this case the client is more flexible and can be used to send requests to any cores. This
- * flexibility though requires that the core be specified on all requests.
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
*/
public Builder(String baseSolrUrl) {
this.baseSolrUrl = baseSolrUrl;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 374b7a704d9..33533c9b06b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -1124,6 +1124,45 @@ public class Http2SolrClient extends SolrClient {
public Builder() {}
+ /**
+ * Create a Builder object, based on the provided Solr URL.
+ *
+ * <p>Two different paths can be specified as a part of this URL:
+ *
+ * <p>1) A path pointing directly at a particular core
+ *
+ * <pre>
+ * SolrClient client = new Http2SolrClient.Builder("http://my-solr-server:8983/solr/core1").build();
+ * QueryResponse resp = client.query(new SolrQuery("*:*"));
+ * </pre>
+ *
+ * Note that when a core is provided in the base URL, queries and other requests can be made
+ * without mentioning the core explicitly. However, the client can only send requests to that
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
+ *
+ * <p>2) The path of the root Solr path ("/solr")
+ *
+ * <pre>
+ * SolrClient client = new Http2SolrClient.Builder("http://my-solr-server:8983/solr").build();
+ * QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
+ * </pre>
+ *
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
+ *
+ * <p>By default, compression is not enabled on created HttpSolrClient objects. By default,
+ * redirects are not followed in created HttpSolrClient objects. By default, {@link
+ * BinaryRequestWriter} is used for composing requests. By default, {@link BinaryResponseParser}
+ * is used for parsing responses.
+ *
+ * @param baseSolrUrl the base URL of the Solr server that will be targeted by any created
+ * clients.
+ */
public Builder(String baseSolrUrl) {
this.baseSolrUrl = baseSolrUrl;
}
@@ -1223,6 +1262,9 @@ public class Http2SolrClient extends SolrClient {
if (this.urlParamNames == null) {
this.urlParamNames = http2SolrClient.urlParamNames;
}
+ if (this.defaultCollection == null) {
+ this.defaultCollection = http2SolrClient.defaultCollection;
+ }
return this;
}
@@ -1238,7 +1280,12 @@ public class Http2SolrClient extends SolrClient {
return this;
}
- /** Sets a default for core or collection based requests. */
+ /**
+ * Sets a default for core or collection based requests.
+ *
+ * <p>This method should not be used if the client is provided a Solr URL which already contains
+ * a core or collection name.
+ */
public Builder withDefaultCollection(String defaultCoreOrCollection) {
this.defaultCollection = defaultCoreOrCollection;
return this;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
index 48e5b2deead..ca455a62426 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
@@ -956,7 +956,11 @@ public class HttpSolrClient extends BaseHttpSolrClient {
*
* Note that when a core is provided in the base URL, queries and other requests can be made
* without mentioning the core explicitly. However, the client can only send requests to that
- * core.
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
*
* <p>2) The path of the root Solr path ("/solr")
*
@@ -987,7 +991,11 @@ public class HttpSolrClient extends BaseHttpSolrClient {
*
* Note that when a core is provided in the base URL, queries and other requests can be made
* without mentioning the core explicitly. However, the client can only send requests to that
- * core.
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
*
* <p>2) The path of the root Solr path ("/solr")
*
@@ -996,8 +1004,9 @@ public class HttpSolrClient extends BaseHttpSolrClient {
* QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
* </pre>
*
- * In this case the client is more flexible and can be used to send requests to any cores. This
- * flexibility though requires that the core be specified on all requests.
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
*
* <p>By default, compression is not enabled on created HttpSolrClient objects. By default,
* redirects are not followed in created HttpSolrClient objects. By default, {@link
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java
index b756b02f772..6cfada08541 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java
@@ -322,6 +322,37 @@ public class LBHttp2SolrClient extends LBSolrClient {
TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS); // 1 minute between checks
protected String defaultCollection;
+ /**
+ * Create a Builder object, based on the provided solrClient and Solr URLs.
+ *
+ * <p>Two different paths can be specified as a part of the provided URLs:
+ *
+ * <p>1) A path pointing directly at a particular core
+ *
+ * <pre>
+ * SolrClient client = new LBHttp2SolrClient.Builder(client, "http://my-solr-server:8983/solr/core1").build();
+ * QueryResponse resp = client.query(new SolrQuery("*:*"));
+ * </pre>
+ *
+ * Note that when a core is provided in the base URL, queries and other requests can be made
+ * without mentioning the core explicitly. However, the client can only send requests to that
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
+ *
+ * <p>2) The path of the root Solr path ("/solr")
+ *
+ * <pre>
+ * SolrClient client = new LBHttp2SolrClient.Builder(client, "http://my-solr-server:8983/solr").build();
+ * QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
+ * </pre>
+ *
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
+ */
public Builder(Http2SolrClient http2Client, String... baseSolrUrls) {
this.http2SolrClient = http2Client;
this.baseSolrUrls = baseSolrUrls;
@@ -342,7 +373,12 @@ public class LBHttp2SolrClient extends LBSolrClient {
return this;
}
- /** Sets a default for core or collection based requests. */
+ /**
+ * Sets a default for core or collection based requests.
+ *
+ * <p>This method should not be used if the client is provided a Solr URL which already contains
+ * a core or collection name.
+ */
public LBHttp2SolrClient.Builder withDefaultCollection(String defaultCoreOrCollection) {
this.defaultCollection = defaultCoreOrCollection;
return this;
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
index 12aaf0c86ef..b45d2f0c52a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
@@ -134,10 +134,12 @@ public class LBHttpSolrClient extends LBSolrClient {
client = httpSolrClientBuilder.build();
}
} else {
- final HttpSolrClient.Builder clientBuilder =
- new HttpSolrClient.Builder(server).withHttpClient(httpClient).withResponseParser(parser);
- clientBuilder.withConnectionTimeout(connectionTimeoutMillis, TimeUnit.MILLISECONDS);
- clientBuilder.withSocketTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS);
+ final var clientBuilder =
+ new HttpSolrClient.Builder(server)
+ .withHttpClient(httpClient)
+ .withResponseParser(parser)
+ .withConnectionTimeout(connectionTimeoutMillis, TimeUnit.MILLISECONDS)
+ .withSocketTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS);
if (requestWriter != null) {
clientBuilder.withRequestWriter(requestWriter);
}
@@ -232,7 +234,11 @@ public class LBHttpSolrClient extends LBSolrClient {
*
* Note that when a core is provided in the base URL, queries and other requests can be made
* without mentioning the core explicitly. However, the client can only send requests to that
- * core.
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
*
* <p>2) The path of the root Solr path ("/solr")
*
@@ -265,7 +271,11 @@ public class LBHttpSolrClient extends LBSolrClient {
*
* Note that when a core is provided in the base URL, queries and other requests can be made
* without mentioning the core explicitly. However, the client can only send requests to that
- * core.
+ * core. Attempts to make core-agnostic requests, or requests for other cores will fail.
+ *
+ * <p>Use of these core-based URLs is deprecated and will not be supported in Solr 10.0 Users
+ * should instead provide base URLs as described below, and provide a "default collection" as
+ * desired using {@link #withDefaultCollection(String)}
*
* <p>2) The path of the root Solr path ("/solr")
*
@@ -274,8 +284,9 @@ public class LBHttpSolrClient extends LBSolrClient {
* QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
* </pre>
*
- * In this case the client is more flexible and can be used to send requests to any cores. This
- * flexibility though requires that the core is specified on all requests.
+ * In this case the client is more flexible and can be used to send requests to any cores. Users
+ * can still provide a "default" collection if desired through use of {@link
+ * #withDefaultCollection(String)}.
*/
public Builder withBaseSolrUrls(String... solrUrls) {
for (String baseSolrUrl : solrUrls) {
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
index 94657ab7b9d..c5f5ce5c939 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java
@@ -98,7 +98,12 @@ public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {
return getThis();
}
- /** Sets a default for core or collection based requests. */
+ /**
+ * Sets a default for core or collection based requests.
+ *
+ * <p>This method should not be used if the client is provided a Solr URL which already contains a
+ * core or collection name.
+ */
public B withDefaultCollection(String defaultCoreOrCollection) {
this.defaultCollection = defaultCoreOrCollection;
return getThis();
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java
index 026c9a959a6..853e90957a5 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java
@@ -16,10 +16,14 @@
*/
package org.apache.solr.common.util;
+import java.lang.invoke.MethodHandles;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class URLUtil {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final Pattern URL_PREFIX = Pattern.compile("^([a-z]*?://).*");
@@ -55,6 +59,12 @@ public class URLUtil {
coreUrl = removeTrailingSlashIfPresent(coreUrl);
// Remove the core name and return
+ final var indexOfLastSlash = coreUrl.lastIndexOf("/");
+ if (indexOfLastSlash == -1) {
+ log.warn(
+ "Solr core URL [{}] did not contain expected path segments when parsing, ignoring...");
+ return coreUrl;
+ }
return coreUrl.substring(0, coreUrl.lastIndexOf("/"));
}
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 88d454cfe52..01b0940f357 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
@@ -64,7 +64,7 @@ public abstract class SolrExampleTestsBase extends SolrJettyTestBase {
*/
@Override
public SolrClient createNewSolrClient() {
- return getHttpSolrClient(getCoreUrl());
+ return getHttpSolrClient(getBaseUrl(), DEFAULT_TEST_CORENAME);
}
/** query the example */