From 50ffdd070b5e791dc43fd0324ab5a0cd98b2a186 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Fri, 21 Aug 2026 13:11:23 +0300 Subject: [PATCH 01/24] SOLR-18390: remove test-framework HTTP client convenience helpers Removes the four @Deprecated helpers (SolrTestCaseJ4.getHttpSolrClient overloads and JettySolrRunner.newClient()) and inlines every call site to the equivalent HttpJettySolrClient.Builder construction. Test-only change, no behavior change. --- .../solr/bench/lifecycle/SolrStartup.java | 4 +- .../org/apache/solr/TestCpuTimeSearch.java | 3 +- .../solr/cli/TestSolrCLIRunExample.java | 5 ++- .../solr/cloud/AliasIntegrationTest.java | 9 +++- .../solr/cloud/BasicDistributedZk2Test.java | 10 ++++- .../solr/cloud/BasicDistributedZkTest.java | 8 +++- .../CloudExitableDirectoryReaderTest.java | 5 ++- .../solr/cloud/CollectionsAPISolrJTest.java | 4 +- .../ConcurrentCreateRoutedAliasTest.java | 5 ++- .../solr/cloud/DeleteInactiveReplicaTest.java | 4 +- ...stribDocExpirationUpdateProcessorTest.java | 6 ++- .../cloud/DistributedVersionInfoTest.java | 24 ++++++++--- .../cloud/FullSolrCloudDistribCmdsTest.java | 36 ++++++++++++---- .../solr/cloud/HttpPartitionOnCommitTest.java | 6 ++- .../apache/solr/cloud/HttpPartitionTest.java | 5 ++- .../solr/cloud/MigrateReplicasTest.java | 6 ++- .../solr/cloud/MigrateRouteKeyTest.java | 6 ++- .../apache/solr/cloud/MoveReplicaTest.java | 5 ++- .../cloud/NestedShardedAtomicUpdateTest.java | 6 ++- .../solr/cloud/RemoteQueryErrorTest.java | 4 +- .../apache/solr/cloud/ReplaceNodeTest.java | 6 ++- .../solr/cloud/ReplicationFactorTest.java | 6 ++- .../org/apache/solr/cloud/SplitShardTest.java | 6 ++- .../solr/cloud/TestBaseStatsCacheCloud.java | 4 +- .../solr/cloud/TestCloudConsistency.java | 5 ++- .../solr/cloud/TestCloudDeleteByQuery.java | 26 +++++++++--- ...stCloudPhrasesIdentificationComponent.java | 6 ++- .../cloud/TestCloudPseudoReturnFields.java | 6 ++- .../apache/solr/cloud/TestCloudRecovery2.java | 22 ++++++---- .../apache/solr/cloud/TestConfigSetsAPI.java | 11 ++--- .../cloud/TestConfigSetsAPIExclusivity.java | 3 +- .../cloud/TestConfigSetsAPIZkFailure.java | 3 +- .../solr/cloud/TestGracefulJettyShutdown.java | 4 +- .../cloud/TestMiniSolrCloudClusterSSL.java | 2 +- .../apache/solr/cloud/TestPullReplica.java | 42 +++++++++++++++---- .../cloud/TestPullReplicaErrorHandling.java | 42 +++++++++++++++---- .../solr/cloud/TestPullReplicaWithAuth.java | 6 ++- .../cloud/TestQueryingOnDownCollection.java | 4 +- .../TestStressCloudBlindAtomicUpdates.java | 6 ++- .../solr/cloud/TestTlogReplayVsRecovery.java | 10 +++-- .../apache/solr/cloud/TestTlogReplica.java | 27 +++++++++--- .../TestTolerantUpdateProcessorCloud.java | 26 +++++++++--- ...estTolerantUpdateProcessorRandomCloud.java | 6 ++- .../solr/cloud/UnloadDistributedZkTest.java | 4 +- .../solr/cloud/ZkShardTermsRecoveryTest.java | 6 ++- ...ncurrentDeleteAndCreateCollectionTest.java | 5 ++- .../cloud/api/collections/ShardSplitTest.java | 20 ++++++--- .../snapshots/TestSolrCloudSnapshots.java | 5 ++- .../core/snapshots/TestSolrCoreSnapshots.java | 8 +++- .../solr/filestore/TestDistribFileStore.java | 4 +- .../solr/handler/TestReplicationHandler.java | 3 +- .../handler/TestStressIncrementalBackup.java | 11 ++++- .../solr/handler/TestStressThreadBackup.java | 11 ++++- .../apache/solr/handler/V2StandaloneTest.java | 4 +- .../handler/admin/CoreAdminHandlerTest.java | 4 +- .../handler/admin/HealthCheckHandlerTest.java | 19 ++++++--- .../handler/admin/LukeHandlerCloudTest.java | 11 ++++- .../handler/component/UpdateLogCloudTest.java | 4 +- .../metrics/SolrMetricsIntegrationTest.java | 4 +- .../TestPrometheusResponseWriter.java | 19 ++++++--- .../solr/response/TestRawTransformer.java | 5 ++- .../ManagedSchemaRoundRobinCloudTest.java | 5 ++- .../solr/search/TestCoordinatorRole.java | 3 +- .../facet/TestCloudJSONFacetJoinDomain.java | 6 ++- .../search/facet/TestCloudJSONFacetSKG.java | 6 ++- .../facet/TestCloudJSONFacetSKGEquiv.java | 6 ++- .../solr/search/stats/TestDistribIDF.java | 11 +++-- .../security/BasicAuthIntegrationTest.java | 6 ++- .../security/BasicAuthStandaloneTest.java | 3 +- .../solr/security/MultiAuthPluginTest.java | 13 +++--- .../update/DeleteByIdWithRouterFieldTest.java | 11 ++++- .../processor/TestCloudDeduplication.java | 3 +- .../solr/client/solrj/SolrExampleTests.java | 2 +- .../client/solrj/SolrExampleTestsBase.java | 6 ++- .../solrj/impl/CloudHttp2SolrClientTest.java | 12 ++++-- .../impl/HttpSolrClientBadInputTest.java | 8 +++- .../client/solrj/impl/LB2SolrClientTest.java | 4 +- .../solr/BaseDistributedSearchTestCase.java | 5 ++- .../java/org/apache/solr/SolrTestCaseHS.java | 4 +- .../java/org/apache/solr/SolrTestCaseJ4.java | 33 --------------- .../cloud/AbstractFullDistribZkTestBase.java | 2 +- ...ctCollectionsAPIDistributedZkTestBase.java | 5 ++- .../apache/solr/embedded/JettySolrRunner.java | 7 +--- .../solr/embedded/TestJettySolrRunner.java | 4 +- 84 files changed, 540 insertions(+), 212 deletions(-) diff --git a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java index d0bd64d56baf..e308aba70b9d 100644 --- a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java @@ -23,6 +23,7 @@ import org.apache.commons.io.file.PathUtils; import org.apache.lucene.util.IOUtils; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; import org.apache.solr.embedded.JettyConfig; @@ -78,7 +79,8 @@ public void bootstrapJettyServer() throws Exception { solrRunner = new JettySolrRunner(tmpSolrHome.toString(), buildJettyConfig()); solrRunner.start(false); - try (SolrClient client = solrRunner.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { for (int i = 0; i < NUM_CORES; i++) { createCore(client, "core-prefix-" + i); } diff --git a/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java b/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java index 427205d300c2..7bea9335dcb9 100644 --- a/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java +++ b/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java @@ -20,6 +20,7 @@ import java.util.List; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -100,7 +101,7 @@ public void testWithoutDistrib() throws SolrServerException, IOException { coll.getSlices().stream() .flatMap(s -> s.getReplicas().stream()) .toArray(Replica[]::new)); - try (SolrClient client = getHttpSolrClient(randomReplica.getCoreUrl())) { + try (SolrClient client = new HttpJettySolrClient.Builder(randomReplica.getCoreUrl()).build()) { response = client.query(query); } diff --git a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java index 7a7f105c0848..2e2157878ae8 100644 --- a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java +++ b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java @@ -39,6 +39,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.cloud.MiniSolrCloudCluster; @@ -376,7 +377,9 @@ protected void testExample(String exampleName) throws Exception { if ("techproducts".equals(exampleName)) { try (SolrClient solrClient = - getHttpSolrClient("http://localhost:" + bindPort + "/solr", exampleName)) { + new HttpJettySolrClient.Builder("http://localhost:" + bindPort + "/solr") + .withDefaultCollection(exampleName) + .build()) { SolrQuery query = new SolrQuery("*:*"); QueryResponse qr = solrClient.query(query); long numFound = qr.getResults().getNumFound(); diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java index 18e4d92ba4b6..1349f8868be6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -33,6 +33,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.ClusterStateProvider; import org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -959,11 +960,15 @@ private void searchSeveralWays( // HttpSolrClient JettySolrRunner jetty = cluster.getRandomJetty(random()); if (random().nextBoolean()) { - try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), collectionList)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(collectionList) + .build()) { responseConsumer.accept(client.query(null, solrQuery)); } } else { - try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { responseConsumer.accept(client.query(collectionList, solrQuery)); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java index 61edcfa0f1f6..71bf9cffe162 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -26,6 +26,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -221,7 +222,10 @@ private void addAndQueryDocs(final String baseUrl, int docs) throws Exception { SolrQuery query = new SolrQuery("*:*"); - try (SolrClient client = getHttpSolrClient(baseUrl, "onenodecollection")) { + try (SolrClient client = + new HttpJettySolrClient.Builder(baseUrl) + .withDefaultCollection("onenodecollection") + .build()) { // add a doc client.add(sdoc("id", docs)); client.commit(); @@ -442,7 +446,9 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception { // try a backup command try (final SolrClient client = - getHttpSolrClient((String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))) { + new HttpJettySolrClient.Builder( + (String) shardToJetty.get(SHARD2).get(0).info.get("base_url")) + .build()) { final String backupName = "the_backup"; ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command", "backup"); diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 88be1ee8861b..a78b7ad299df 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -47,6 +47,7 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.Create; @@ -913,7 +914,10 @@ private long checkSlicesSameCounts(DocCollection dColl) throws SolrServerExcepti for (Slice slice : dColl.getActiveSlices()) { long sliceDocCount = -1; for (Replica rep : slice.getReplicas()) { - try (SolrClient one = getHttpSolrClient(rep)) { + try (SolrClient one = + new HttpJettySolrClient.Builder(rep.getBaseUrl()) + .withDefaultCollection(rep.getCoreName()) + .build()) { SolrQuery query = new SolrQuery("*:*"); query.setDistrib(false); QueryResponse resp = one.query(query); @@ -1503,7 +1507,7 @@ private void createSolrCore( final String shardId) { Callable call = () -> { - try (SolrClient client = getHttpSolrClient(baseUrl)) { + try (SolrClient client = new HttpJettySolrClient.Builder(baseUrl).build()) { // client.setConnectionTimeout(15000); Create createCmd = new Create(); createCmd.setCoreName(collection + num); diff --git a/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java b/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java index 24d02a389cf4..6dc0c7d61f5c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -81,7 +82,9 @@ public static void setupCluster() throws Exception { clusterBuilder.configure(); // pick an arbitrary node to use for our requests - client = cluster.getRandomJetty(random()).newClient(); + client = + new HttpJettySolrClient.Builder(cluster.getRandomJetty(random()).getBaseUrl().toString()) + .build(); CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1) .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT); diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java index 17cb7e51ebb6..f4c942a5f167 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java @@ -48,6 +48,7 @@ import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CollectionPropertiesApi; import org.apache.solr.client.solrj.request.CollectionsApi; @@ -300,7 +301,8 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException String corename = response._getStr(asList("success", nodeName, "core"), null); try (SolrClient coreClient = - getHttpSolrClient(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))) { + new HttpJettySolrClient.Builder(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName)) + .build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient); assertEquals( collectionName, status._get(asList("status", corename, "cloud", "collection"), null)); diff --git a/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java b/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java index 504bfd94facb..f52ab1df0b2d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java @@ -21,6 +21,7 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.common.util.IOUtils; @@ -96,7 +97,7 @@ public void testConcurrentCreateRoutedAliasMinimal() { for (; num < threads.length + numStart; num++) { final String aliasName = "testAlias" + num; final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); int i = num - numStart; threads[i] = @@ -120,7 +121,7 @@ public void testConcurrentCreateRoutedAliasComplex() { for (; num < threads.length + numStart; num++) { final String aliasName = "testAliasCplx" + num; final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); int i = num - numStart; threads[i] = diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java index e84e9e436dc7..606a7235b9fd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java @@ -20,6 +20,7 @@ import java.nio.file.Files; import java.util.concurrent.TimeUnit; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.common.cloud.DocCollection; @@ -108,7 +109,8 @@ public void deleteInactiveReplicaTest() throws Exception { && !FileUtils.fileExists(replicaCd.getDataDir())); // Check that we can't create a core with no coreNodeName - try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) { + try (SolrClient queryClient = + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { Exception e = expectThrows( Exception.class, diff --git a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java index 45b83e7066df..17175d63df80 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java @@ -28,6 +28,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -288,7 +289,10 @@ private Map getTestDataForAllReplicas() for (Replica replica : collectionState.getReplicas()) { String coreName = replica.getCoreName(); - try (SolrClient client = getHttpSolrClient(replica)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command", "indexversion"); diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java index b6b1f977240a..d2d6aa7aa373 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java @@ -34,6 +34,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -107,7 +108,10 @@ public void testReplicaVersionHandling() throws Exception { maxOnReplica); // send the same doc but with a lower version than the max in the index - try (SolrClient client = getHttpSolrClient(replica)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { String docId = String.valueOf(1); SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", docId); @@ -298,7 +302,10 @@ protected long getVersionFromIndex(Replica replica, String docId) query.addSort(new SolrQuery.SortClause("_version_", SolrQuery.ORDER.desc)); query.setParam("distrib", false); - try (SolrClient client = getHttpSolrClient(replica)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { QueryResponse qr = client.query(query); SolrDocumentList hits = qr.getResults(); if (hits.isEmpty()) fail("No results returned from query: " + query); @@ -320,9 +327,16 @@ protected void assertDocsExistInAllReplicas( int lastDocId, Set deletedDocs) throws Exception { - SolrClient leaderSolr = getHttpSolrClient(leader); + SolrClient leaderSolr = + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) + .build(); List replicas = new ArrayList(notLeaders.size()); - for (Replica r : notLeaders) replicas.add(getHttpSolrClient(r)); + for (Replica r : notLeaders) + replicas.add( + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build()); try { for (int d = firstDocId; d <= lastDocId; d++) { @@ -376,7 +390,7 @@ protected Long assertDocExists(SolrClient solr, String docId, Long expVers) thro protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { String coreName = replica.getCoreName(); boolean reloadedOk = false; - try (SolrClient client = getHttpSolrClient(replica.getBaseUrl())) { + try (SolrClient client = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); diff --git a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java index cb5bee468783..e162c35b15a6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java @@ -31,6 +31,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.jetty.ConcurrentUpdateJettySolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -170,8 +171,14 @@ public void testDeleteByIdImplicitRouter() throws Exception { (n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2)); final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); - try (SolrClient shard1 = getHttpSolrClient(docCol.getSlice("shard1").getLeader()); - SolrClient shard2 = getHttpSolrClient(docCol.getSlice("shard2").getLeader())) { + try (SolrClient shard1 = + new HttpJettySolrClient.Builder(docCol.getSlice("shard1").getLeader().getBaseUrl()) + .withDefaultCollection(docCol.getSlice("shard1").getLeader().getCoreName()) + .build(); + SolrClient shard2 = + new HttpJettySolrClient.Builder(docCol.getSlice("shard2").getLeader().getBaseUrl()) + .withDefaultCollection(docCol.getSlice("shard2").getLeader().getCoreName()) + .build()) { // Add three documents to shard1 shard1.add(sdoc("id", "1", "title", "s1 one")); @@ -325,8 +332,14 @@ public void testDeleteByIdCompositeRouterWithRouterField() throws Exception { (n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2)); final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); - try (SolrClient shard1 = getHttpSolrClient(docCol.getSlice("shard1").getLeader()); - SolrClient shard2 = getHttpSolrClient(docCol.getSlice("shard2").getLeader())) { + try (SolrClient shard1 = + new HttpJettySolrClient.Builder(docCol.getSlice("shard1").getLeader().getBaseUrl()) + .withDefaultCollection(docCol.getSlice("shard1").getLeader().getCoreName()) + .build(); + SolrClient shard2 = + new HttpJettySolrClient.Builder(docCol.getSlice("shard2").getLeader().getBaseUrl()) + .withDefaultCollection(docCol.getSlice("shard2").getLeader().getCoreName()) + .build()) { // Add six documents w/diff routes (all sent to shard1 leader's core) shard1.add(sdoc("id", "1", "routefield_s", "europe")); @@ -488,7 +501,10 @@ public void testThatCantForwardToLeaderFails() throws Exception { } // create client to send our updates to... - try (SolrClient indexClient = getHttpSolrClient(indexingBaseUrl, collectionName)) { + try (SolrClient indexClient = + new HttpJettySolrClient.Builder(indexingBaseUrl) + .withDefaultCollection(collectionName) + .build()) { // Sanity check: we should be able to send a bunch of updates that work right now... for (int i = 0; i < 100; i++) { @@ -862,11 +878,17 @@ private void checkShardConsistency(String collectionName, final SolrParams param final Slice slice = entry.getValue(); log.info("Checking: {} -> {}", shardName, slice); final Replica leader = entry.getValue().getLeader(); - try (SolrClient leaderClient = getHttpSolrClient(leader)) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) + .build()) { final SolrDocumentList leaderResults = leaderClient.query(perReplicaParams).getResults(); log.debug("Shard {}: Leader results: {}", shardName, leaderResults); for (Replica replica : slice) { - try (SolrClient replicaClient = getHttpSolrClient(replica)) { + try (SolrClient replicaClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { final SolrDocumentList replicaResults = replicaClient.query(perReplicaParams).getResults(); if (log.isDebugEnabled()) { diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java index c271c88adb7a..0543f72cf7b6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java @@ -21,6 +21,7 @@ import java.nio.file.Path; import java.util.List; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.ZkStateReader; @@ -190,7 +191,10 @@ protected void sendCommitWithRetry(Replica replica) throws Exception { String replicaCoreUrl = replica.getCoreUrl(); log.info("Sending commit request to: {}", replicaCoreUrl); final RTimer timer = new RTimer(); - try (SolrClient client = getHttpSolrClient(replica)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { try { client.commit(); diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java index ee536f12ae16..56fe4f5f53d7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java @@ -36,6 +36,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.common.SolrException; @@ -516,7 +517,9 @@ protected void assertDocsExistInAllReplicas( } protected SolrClient getHttpSolrClient(Replica replica, String collection) { - return getHttpSolrClient(replica.getBaseUrl(), collection); + return new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(collection) + .build(); } // Send doc directly to a server (without going through proxy) diff --git a/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java b/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java index 1d4d431d6df2..b05e198daa5b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java @@ -29,6 +29,7 @@ import org.apache.solr.client.api.model.MigrateReplicasRequestBody; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; @@ -124,7 +125,8 @@ public void test() throws Exception { ((Map) response.get("responseHeader")).get("status")); ZkStateReader zkStateReader = ZkStateReader.from(cloudClient); try (SolrClient coreClient = - getHttpSolrClient(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned))) { + new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned)) + .build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); assertEquals( "There should not be any cores left on decommissioned node", @@ -151,7 +153,7 @@ public void test() throws Exception { ((Map) response.get("responseHeader")).get("status")); try (SolrClient coreClient = - getHttpSolrClient(zkStateReader.getBaseUrlForNodeName(emptyNode))) { + new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(emptyNode)).build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); assertEquals( "Expecting no cores but found some: " + status.getCoreStatus(), diff --git a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java index c990f43423ab..d54212f5fdd2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java @@ -24,6 +24,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; @@ -134,7 +135,10 @@ public void multipleShardMigrateTest() throws Exception { DocCollection state = getCollectionState(targetCollection); Replica replica = state.getReplicas().get(0); - try (SolrClient collectionClient = getHttpSolrClient(replica)) { + try (SolrClient collectionClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { SolrQuery solrQuery = new SolrQuery("*:*"); assertEquals( diff --git a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java index 76092a2c9369..74592a114d7f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java @@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -365,7 +366,9 @@ private int getNumOfCores( CloudSolrClient cloudClient, String nodeName, String collectionName, String replicaType) throws IOException, SolrServerException { try (SolrClient coreclient = - getHttpSolrClient(ZkStateReader.from(cloudClient).getBaseUrlForNodeName(nodeName))) { + new HttpJettySolrClient.Builder( + ZkStateReader.from(cloudClient).getBaseUrlForNodeName(nodeName)) + .build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient); if (status.getCoreStatus().size() == 0) { return 0; diff --git a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java index 455b202f1d38..6526361b872c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java @@ -26,6 +26,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -72,7 +73,10 @@ public static void beforeClass() throws Exception { clients = new ArrayList<>(); ClusterState clusterState = cloudClient.getClusterState(); for (Replica replica : clusterState.getCollection(DEFAULT_COLLECTION).getReplicas()) { - clients.add(getHttpSolrClient(replica)); + clients.add( + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java b/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java index 9da524dfc9b8..ddaf414e5d0c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java @@ -19,6 +19,7 @@ import static org.hamcrest.core.StringContains.containsString; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; @@ -43,7 +44,8 @@ public void test() throws Exception { .process(cluster.getSolrClient()); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - try (SolrClient client = jetty.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { SolrException e = expectThrows( SolrException.class, diff --git a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java index bc64635d2d87..7b77f91fc988 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; @@ -118,7 +119,8 @@ public void test() throws Exception { .processAndWait("000", cloudClient, 15); ZkStateReader zkStateReader = ZkStateReader.from(cloudClient); try (SolrClient coreClient = - getHttpSolrClient(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned))) { + new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned)) + .build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); assertEquals(0, status.getCoreStatus().size()); } @@ -137,7 +139,7 @@ public void test() throws Exception { replaceNodeRequest.processAndWait("001", cloudClient, 10); try (SolrClient coreClient = - getHttpSolrClient(zkStateReader.getBaseUrlForNodeName(emptyNode))) { + new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(emptyNode)).build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); assertEquals( "Expecting no cores but found some: " + status.getCoreStatus(), diff --git a/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java b/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java index eb63af4a5ac5..a37086b06149 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java @@ -31,6 +31,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -268,7 +269,10 @@ protected void sendNonDirectUpdateRequestReplicaWithRetry( protected void sendNonDirectUpdateRequestReplica( Replica replica, UpdateRequest up, int expectedRf, String collection) throws Exception { - try (SolrClient solrServer = getHttpSolrClient(replica.getBaseUrl(), collection)) { + try (SolrClient solrServer = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(collection) + .build()) { NamedList resp = solrServer.request(up); NamedList hdr = (NamedList) resp.get("responseHeader"); Integer batchRf = (Integer) hdr.get(UpdateRequest.REPFACT); diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java index 0b539bd39d0f..a78eb5c39566 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java @@ -37,6 +37,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -229,7 +230,10 @@ long getNumDocs(CloudSolrClient client, String collectionName) throws Exception if (!slice.getState().equals(Slice.State.ACTIVE)) continue; long lastReplicaCount = -1; for (Replica replica : slice.getReplicas()) { - SolrClient replicaClient = getHttpSolrClient(replica); + SolrClient replicaClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build(); long numFound; try { numFound = diff --git a/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java index a7dc3f8d12fc..3280410bb151 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java @@ -26,6 +26,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.MetricsRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -131,7 +132,8 @@ public void testBasicStats() throws Exception { // check cache metrics StatsCache.StatsCacheMetrics statsCacheMetrics = new StatsCache.StatsCacheMetrics(); for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) { - try (SolrClient client = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { var req = new MetricsRequest(SolrParams.of("wt", "prometheus")); NamedList resp = client.request(req); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java index 9041d42555d0..e7876b54a4bb 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudConsistency.java @@ -32,6 +32,7 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.SolrInputDocument; @@ -351,6 +352,8 @@ private NamedList realTimeGetDocId(SolrClient solr, String docId) } protected SolrClient getHttpSolrClient(Replica replica, String coll) { - return getHttpSolrClient(replica.getBaseUrl(), coll); + return new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(coll) + .build(); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java index 451ef12dab6c..7fe47d4af206 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java @@ -27,6 +27,7 @@ import java.util.UUID; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.common.SolrDocument; @@ -166,17 +167,32 @@ public static void createMiniSolrCloudCluster() throws Exception { assertNotNull("could not find URL for " + shardName + " replica", passiveUrl); if (shardName.equals("shard1")) { - S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl, COLLECTION_NAME); - S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl, COLLECTION_NAME); + S_ONE_LEADER_CLIENT = + new HttpJettySolrClient.Builder(leaderUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); + S_ONE_NON_LEADER_CLIENT = + new HttpJettySolrClient.Builder(passiveUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); } else if (shardName.equals("shard2")) { - S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl, COLLECTION_NAME); - S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl, COLLECTION_NAME); + S_TWO_LEADER_CLIENT = + new HttpJettySolrClient.Builder(leaderUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); + S_TWO_NON_LEADER_CLIENT = + new HttpJettySolrClient.Builder(passiveUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (not hosting either shard)", 1, urlMap.size()); - NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next(), COLLECTION_NAME); + NO_COLLECTION_CLIENT = + new HttpJettySolrClient.Builder(urlMap.values().iterator().next()) + .withDefaultCollection(COLLECTION_NAME) + .build(); assertNotNull(S_ONE_LEADER_CLIENT); assertNotNull(S_TWO_LEADER_CLIENT); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java index 2a979299698d..cd95b51aa38d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java @@ -27,6 +27,7 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -80,7 +81,10 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(COLLECTION_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add(getHttpSolrClient(jetty.getBaseUrl().toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } // index some docs... diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java index 81969dae3452..833b524167a4 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java @@ -35,6 +35,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest.Field; import org.apache.solr.client.solrj.response.QueryResponse; @@ -97,7 +98,10 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(COLLECTION_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add(getHttpSolrClient(jetty.getBaseUrl().toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } assertEquals( diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java index d4af2692573a..2f37f61683d9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java @@ -18,6 +18,7 @@ package org.apache.solr.cloud; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -49,7 +50,8 @@ public static void setupCluster() throws Exception { public void test() throws Exception { JettySolrRunner node1 = cluster.getJettySolrRunner(0); JettySolrRunner node2 = cluster.getJettySolrRunner(1); - try (SolrClient client1 = getHttpSolrClient(node1.getBaseUrl().toString())) { + try (SolrClient client1 = + new HttpJettySolrClient.Builder(node1.getBaseUrl().toString()).build()) { node2.stop(); waitForState("", COLLECTION, (liveNodes, collectionState) -> liveNodes.size() == 1); @@ -63,7 +65,8 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = getHttpSolrClient(node2.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { long numFound = client .query(COLLECTION, new SolrQuery("q", "*:*", "distrib", "false")) @@ -80,7 +83,8 @@ public void test() throws Exception { new UpdateRequest().add("id", "1", "num", "10").commit(client1, COLLECTION); - try (SolrClient client = getHttpSolrClient(node2.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { Object v = client .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) @@ -112,7 +116,8 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = getHttpSolrClient(node2.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { v = client .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) @@ -137,7 +142,8 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = getHttpSolrClient(node2.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { v = client .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) @@ -166,7 +172,8 @@ public void test() throws Exception { node1.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = getHttpSolrClient(node1.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node1.getBaseUrl().toString()).build()) { Object v = client .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) @@ -175,7 +182,8 @@ public void test() throws Exception { .get("num"); assertEquals("30", v.toString()); } - try (SolrClient client = getHttpSolrClient(node2.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { Object v = client .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java index 29c17139d2a4..806d5d49d6b7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -63,6 +63,7 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete; @@ -136,7 +137,7 @@ public void tearDown() throws Exception { @Test public void testCreateErrors() throws Exception { final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - try (final SolrClient solrClient = getHttpSolrClient(baseUrl)) { + try (final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build()) { getConfigSetService().uploadConfig("configSet", configset("configset-2")); // no action @@ -223,7 +224,7 @@ private void verifyCreate( String username) throws Exception { final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - try (final SolrClient solrClient = getHttpSolrClient(baseUrl)) { + try (final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build()) { setupBaseConfigSet(baseConfigSetName, oldProps); try (SolrZkClient zkClient = @@ -1625,7 +1626,7 @@ private byte[] readFile(String fname) throws IOException { @Test public void testDeleteErrors() throws Exception { final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); final Path configDir = getFile("solr").resolve("configsets/configset-2/conf"); final Path tmpConfigDir = createTempDir(); // Ensure ConfigSet is immutable @@ -1660,7 +1661,7 @@ private void verifyException( @Test public void testDelete() throws Exception { final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); final String configSet = "testDelete"; getConfigSetService().uploadConfig(configSet, configset("configset-2")); assertDelete(solrClient, configSet, true); @@ -1692,7 +1693,7 @@ private void assertDelete(SolrClient solrClient, String configSet, boolean asser @Test public void testList() throws Exception { final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); SolrZkClient zkClient = new SolrZkClient.Builder() diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java index 722ed01c1fa7..363a36f27359 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete; @@ -119,7 +120,7 @@ public ConfigSetsAPIThread(MiniSolrCloudCluster solrCluster, int trials) { @Override public void run() { final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); ConfigSetAdminRequest request = createRequest(); for (int i = 0; i < trials; ++i) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java index 0cce6aef96f6..61758f0592af 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -37,6 +37,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.SolrZkClient; @@ -109,7 +110,7 @@ public void tearDown() throws Exception { @Test public void testCreateZkFailure() throws Exception { final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); final ConfigSetService configSetService = solrCluster.getOpenOverseer().getCoreContainer().getConfigSetService(); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestGracefulJettyShutdown.java b/solr/core/src/test/org/apache/solr/cloud/TestGracefulJettyShutdown.java index 8c52096dda0d..e2397df60581 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestGracefulJettyShutdown.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestGracefulJettyShutdown.java @@ -28,6 +28,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -86,7 +87,8 @@ public void testSingleShardInFlightRequestsDuringShutDown() throws Exception { final List> results = new ArrayList<>(13); - try (SolrClient jettyClient = nodeToStop.newClient()) { + try (SolrClient jettyClient = + new HttpJettySolrClient.Builder(nodeToStop.getBaseUrl().toString()).build()) { final QueryRequest req = new QueryRequest(handler, params("q", "foo_s:aaa")); // check inflight requests using both clients... diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java index 8fbbe214fe0c..b546d9eada5d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java @@ -411,6 +411,6 @@ public static SolrClient getRandomizedHttpSolrClient(String url) { if (random().nextBoolean()) { return HttpSolrClient.builder(url).build(); } // else... - return getHttpSolrClient(url); + return new HttpJettySolrClient.Builder(url).build(); } } 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 331b2b7e9f2e..2c5893571d48 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -36,6 +36,7 @@ import org.apache.lucene.tests.util.LuceneTestCase.Nightly; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -296,7 +297,10 @@ public void testAddDocs() throws Exception { log.info("Committed doc {} to leader", numDocs); Slice s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertEquals(numDocs, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } log.info( @@ -531,14 +535,20 @@ public void testRealTimeGet() Slice slice = docCollection.getSlice("shard1"); List ids = new ArrayList<>(slice.getReplicas().size()); for (Replica rAdd : slice.getReplicas()) { - try (SolrClient client = getHttpSolrClient(rAdd.getBaseUrl(), rAdd.getCoreName())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(rAdd.getBaseUrl()) + .withDefaultCollection(rAdd.getCoreName()) + .build()) { client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar")); } SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id)); assertEquals("bar", docCloudClient.getFieldValue("foo_s")); for (Replica rGet : slice.getReplicas()) { - try (SolrClient client = getHttpSolrClient(rGet.getBaseUrl(), rGet.getCoreName())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(rGet.getBaseUrl()) + .withDefaultCollection(rGet.getCoreName()) + .build()) { SolrDocument doc = client.getById(String.valueOf(id)); assertEquals("bar", doc.getFieldValue("foo_s")); } @@ -548,7 +558,10 @@ public void testRealTimeGet() } SolrDocumentList previousAllIdsResult = null; for (Replica rAdd : slice.getReplicas()) { - try (SolrClient client = getHttpSolrClient(rAdd.getBaseUrl(), rAdd.getCoreName())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(rAdd.getBaseUrl()) + .withDefaultCollection(rAdd.getCoreName()) + .build()) { SolrDocumentList allIdsResult = client.getById(ids); if (previousAllIdsResult != null) { assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult)); @@ -579,7 +592,10 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar")); cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -634,7 +650,11 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { // Also fails if I send the update to the pull replica explicitly try (SolrClient pullReplicaClient = - getHttpSolrClient(getReplicas(docCollection, EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + getReplicas(docCollection, EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + getReplicas(docCollection, EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { expectThrows( SolrException.class, () -> @@ -681,7 +701,10 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { // add docs agin cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "zoo")); s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { leaderClient.commit(); assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -878,7 +901,10 @@ static void waitForNumDocsInAllReplicas( TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS, TimeSource.NANO_TIME); for (Replica r : replicas) { String replicaUrl = r.getCoreUrl(); - try (SolrClient replicaClient = getHttpSolrClient(r)) { + try (SolrClient replicaClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build()) { while (true) { QueryRequest req = new QueryRequest(new SolrQuery(query)); if (user != null && pass != null) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java index 5d0ee95b5410..78b805d79b58 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java @@ -29,6 +29,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.common.SolrException; @@ -139,7 +140,10 @@ public void testCantConnectToPullReplica() throws Exception { proxy.close(); for (int i = 1; i <= 10; i++) { addDocs(10 + i); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertNumDocs(10 + i, leaderClient); } } @@ -149,7 +153,11 @@ public void testCantConnectToPullReplica() throws Exception { SolrServerException.class, () -> { try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { pullReplicaClient.query(new SolrQuery("*:*")).getResults().getNumFound(); } }); @@ -174,7 +182,11 @@ public void testCantConnectToPullReplica() throws Exception { } try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { assertNumDocs(20, pullReplicaClient); } } @@ -191,13 +203,21 @@ public void testCantConnectToLeader() throws Exception { try { // wait for replication try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { assertNumDocs(10, pullReplicaClient); } proxy.close(); expectThrows(SolrException.class, () -> addDocs(1)); try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { assertNumDocs(10, pullReplicaClient); } assertNumDocs(10, cluster.getSolrClient(collectionName)); @@ -227,7 +247,11 @@ public void testPullReplicaDisconnectsFromZooKeeper() throws Exception { DocCollection docCollection = assertNumberOfReplicas(numShards, 0, numShards, false, true); Slice s = docCollection.getSlices().iterator().next(); try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { assertNumDocs(10, pullReplicaClient); } addDocs(20); @@ -238,7 +262,11 @@ public void testPullReplicaDisconnectsFromZooKeeper() throws Exception { addDocs(40); waitForState("Expecting node to be reconnected", collectionName, activeReplicaCount(1, 0, 1)); try (SolrClient pullReplicaClient = - getHttpSolrClient(s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0))) { + new HttpJettySolrClient.Builder( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getBaseUrl()) + .withDefaultCollection( + s.getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getCoreName()) + .build()) { assertNumDocs(40, pullReplicaClient); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java index 4439f8fbf353..77e64f382da9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java @@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -93,7 +94,10 @@ public void testPKIAuthWorksForPullReplication() throws Exception { ureq.commit(solrClient, collectionName); Slice s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertEquals( numDocs, queryWithBasicAuth(leaderClient, new SolrQuery("*:*")).getResults().getNumFound()); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java index e95bf3493fb4..58ccc9ed26cf 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -84,7 +84,9 @@ public void testQueryToDownCollectionShouldFailFast() throws Exception { new QueryRequest(new SolrQuery("*:*").setRows(0)) .setBasicAuthCredentials(USERNAME, PASSWORD); - try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { // Without the SOLR-13793 fix, this causes requests to "down collection" to pile up (until the // nodes run out of serviceable threads, and they crash, even for other collections hosted on // the diff --git a/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java b/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java index 8abccaf7fbd1..79dd2341cce1 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java @@ -33,6 +33,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest.Field; @@ -141,7 +142,10 @@ public static void createMiniSolrCloudCluster() throws Exception { assertNotNull("Cluster contains null jetty?", jetty); final URL baseUrl = jetty.getBaseUrl(); assertNotNull("Jetty has null baseUrl: " + jetty, baseUrl); - CLIENTS.add(getHttpSolrClient(baseUrl.toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(baseUrl.toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } // sanity check no one broke the assumptions we make about our schema diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java index af90ea36ee3e..55f173584a95 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java @@ -32,6 +32,7 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.response.RequestStatusState; @@ -243,7 +244,8 @@ private void addDocs(final boolean commit, final int numDocs, final int startId) } // For simplicity, we always add out docs directly to NODE0 // (where the leader should be) and bypass the proxy... - try (SolrClient client = getHttpSolrClient(NODE0.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(NODE0.getBaseUrl().toString()).build()) { assertEquals(0, client.add(COLLECTION, docs).getStatus()); if (commit) { assertEquals(0, client.commit(COLLECTION).getStatus()); @@ -256,8 +258,10 @@ private void addDocs(final boolean commit, final int numDocs, final int startId) * (inclusive) can be found on both the leader and the replica */ private void assertDocsExistInBothReplicas(int firstDocId, int lastDocId) throws Exception { - try (SolrClient leaderSolr = getHttpSolrClient(NODE0.getBaseUrl().toString()); - SolrClient replicaSolr = getHttpSolrClient(NODE1.getBaseUrl().toString())) { + try (SolrClient leaderSolr = + new HttpJettySolrClient.Builder(NODE0.getBaseUrl().toString()).build(); + SolrClient replicaSolr = + new HttpJettySolrClient.Builder(NODE1.getBaseUrl().toString()).build()) { for (int d = firstDocId; d <= lastDocId; d++) { String docId = String.valueOf(d); assertDocExists("leader", leaderSolr, docId); 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 aec3a34ed362..680f779b3999 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -40,6 +40,7 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -254,14 +255,20 @@ public void testAddDocs() throws Exception { cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS, TimeSource.NANO_TIME); for (Replica r : s.getReplicas(EnumSet.of(Replica.Type.TLOG))) { // TODO: assert replication < REPLICATION_TIMEOUT_SECS - try (SolrClient tlogReplicaClient = getHttpSolrClient(r)) { + try (SolrClient tlogReplicaClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build()) { while (true) { try { assertEquals( @@ -440,7 +447,10 @@ private void doReplaceLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar")); cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); - try (SolrClient leaderClient = getHttpSolrClient(s.getLeader())) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) + .withDefaultCollection(s.getLeader().getCoreName()) + .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -891,7 +901,8 @@ public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception { updates.add(simulatedDBQ("inplace_updatable_int:5", 3L)); updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L)); for (JettySolrRunner solrRunner : getSolrRunner(false)) { - try (SolrClient client = solrRunner.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { for (UpdateRequest up : updates) { up.process(client, collectionName); } @@ -995,7 +1006,10 @@ private void waitForNumDocsInAllReplicas( if (!r.isActive(cluster.getSolrClient().getClusterState().getLiveNodes())) { continue; } - try (SolrClient replicaClient = getHttpSolrClient(r)) { + try (SolrClient replicaClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build()) { while (true) { try { assertEquals( @@ -1130,7 +1144,8 @@ private List getSolrCore(boolean isLeader) { private void checkRTG(int from, int to, List solrRunners) throws Exception { for (JettySolrRunner solrRunner : solrRunners) { - try (SolrClient client = solrRunner.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { for (int i = from; i <= to; i++) { SolrQuery query = new SolrQuery(); query.set("distrib", false); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java index dc0a44359498..bbbcafc1a3b8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.UpdateResponse; @@ -145,17 +146,32 @@ public static void createMiniSolrCloudCluster() throws Exception { assertNotNull("could not find URL for " + shardName + " replica", passiveUrl); if (shardName.equals("shard1")) { - S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl, COLLECTION_NAME); - S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl, COLLECTION_NAME); + S_ONE_LEADER_CLIENT = + new HttpJettySolrClient.Builder(leaderUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); + S_ONE_NON_LEADER_CLIENT = + new HttpJettySolrClient.Builder(passiveUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); } else if (shardName.equals("shard2")) { - S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl, COLLECTION_NAME); - S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl, COLLECTION_NAME); + S_TWO_LEADER_CLIENT = + new HttpJettySolrClient.Builder(leaderUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); + S_TWO_NON_LEADER_CLIENT = + new HttpJettySolrClient.Builder(passiveUrl) + .withDefaultCollection(COLLECTION_NAME) + .build(); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (not hosting either shard)", 1, urlMap.size()); - NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next(), COLLECTION_NAME); + NO_COLLECTION_CLIENT = + new HttpJettySolrClient.Builder(urlMap.values().iterator().next()) + .withDefaultCollection(COLLECTION_NAME) + .build(); assertNotNull(S_ONE_LEADER_CLIENT); assertNotNull(S_TWO_LEADER_CLIENT); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java index a39197320cfd..253a90206f60 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java @@ -39,6 +39,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -115,7 +116,10 @@ public static void createMiniSolrCloudCluster() throws Exception { for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { URL jettyURL = jetty.getBaseUrl(); - NODE_CLIENTS.add(getHttpSolrClient(jettyURL.toString(), COLLECTION_NAME)); + NODE_CLIENTS.add( + new HttpJettySolrClient.Builder(jettyURL.toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } assertEquals(numServers, NODE_CLIENTS.size()); } diff --git a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java index fcbc8b23ad11..ddb1cd71acdc 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -32,6 +32,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload; import org.apache.solr.common.SolrInputDocument; @@ -155,7 +156,8 @@ private void testUnloadShardAndCollection() throws Exception { final String unloadCmdCoreName1 = (unloadInOrder ? coreName1 : coreName2); final String unloadCmdCoreName2 = (unloadInOrder ? coreName2 : coreName1); - try (SolrClient adminClient = getHttpSolrClient(buildUrl(jettys.get(0).getLocalPort()))) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(buildUrl(jettys.get(0).getLocalPort())).build()) { // now unload one of the two Unload unloadCmd = new Unload(false); unloadCmd.setCoreName(unloadCmdCoreName1); diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java index 10385f2c54cb..6c4769d3b297 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -190,7 +191,10 @@ private void waitForNumDocsInAllReplicas(int numDocs, Collection replic if (!r.isActive(cluster.getSolrClient().getClusterState().getLiveNodes())) { continue; } - try (SolrClient replicaClient = getHttpSolrClient(r)) { + try (SolrClient replicaClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build()) { assertEquals( "Replica " + r.getName() + " not up to date", numDocs, diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java index c89f46ccf391..da52dbe97c49 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java @@ -24,6 +24,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.cloud.MiniSolrCloudCluster; @@ -68,7 +69,7 @@ public void testConcurrentCreateAndDeleteDoesNotFail() throws IOException { final String collectionName = "collection" + i; solrCluster.uploadConfigSet(configset("configset-2"), collectionName); final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); threads[i] = new CreateDeleteSearchCollectionThread( "create-delete-search-" + i, @@ -95,7 +96,7 @@ public void testConcurrentCreateAndDeleteOverTheSameConfig() throws IOException final CreateDeleteCollectionThread[] threads = new CreateDeleteCollectionThread[2]; for (int i = 0; i < threads.length; i++) { final String collectionName = "collection" + i; - final SolrClient solrClient = getHttpSolrClient(baseUrl); + final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); threads[i] = new CreateDeleteCollectionThread( "create-delete-" + i, collectionName, configName, timeToRunSec, solrClient, failure); 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 c55843dab9d9..6ef8e9048f6d 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 @@ -43,6 +43,7 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -965,7 +966,8 @@ public void splitByRouteFieldTest() throws Exception { getCommonCloudSolrClient(); String baseUrl = getBaseUrlFromZk(cloudClient.getClusterState(), collectionName); - try (SolrClient collectionClient = getHttpSolrClient(baseUrl, collectionName)) { + try (SolrClient collectionClient = + new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(collectionName).build()) { ClusterState clusterState = cloudClient.getClusterState(); final DocRouter router = clusterState.getCollection(collectionName).getRouter(); @@ -1036,7 +1038,8 @@ private void splitByRouteKeyTest() throws Exception { getCommonCloudSolrClient(); String baseUrl = getBaseUrlFromZk(cloudClient.getClusterState(), collectionName); - try (SolrClient collectionClient = getHttpSolrClient(baseUrl, collectionName)) { + try (SolrClient collectionClient = + new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(collectionName).build()) { String splitKey = "b!"; @@ -1191,7 +1194,9 @@ protected void checkDocCountsAndShardStates( Replica shard1_0 = getLeaderFromZk(AbstractFullDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0); QueryResponse response; try (SolrClient shard1_0Client = - getHttpSolrClient(shard1_0.getBaseUrl(), shard1_0.getCoreName())) { + new HttpJettySolrClient.Builder(shard1_0.getBaseUrl()) + .withDefaultCollection(shard1_0.getCoreName()) + .build()) { response = shard1_0Client.query(query); } long shard10Count = response.getResults().getNumFound(); @@ -1199,7 +1204,9 @@ protected void checkDocCountsAndShardStates( Replica shard1_1 = getLeaderFromZk(AbstractFullDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1); QueryResponse response2; try (SolrClient shard1_1Client = - getHttpSolrClient(shard1_1.getBaseUrl(), shard1_1.getCoreName())) { + new HttpJettySolrClient.Builder(shard1_1.getBaseUrl()) + .withDefaultCollection(shard1_1.getCoreName()) + .build()) { response2 = shard1_1Client.query(query); } long shard11Count = response2.getResults().getNumFound(); @@ -1224,7 +1231,10 @@ protected void checkSubShardConsistency(String shard) throws SolrServerException for (Replica replica : slice.getReplicas()) { String coreUrl = replica.getCoreUrl(); QueryResponse response; - try (SolrClient client = getHttpSolrClient(replica)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { response = client.query(query); } numFound[c++] = response.getResults().getNumFound(); diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java index 6fa70f020e68..c3110bff329c 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java @@ -29,6 +29,7 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -157,7 +158,7 @@ public void testSnapshots() throws Exception { assertTrue(snapshotByCoreName.containsKey(coreName)); CoreSnapshotMetaData coreSnapshot = snapshotByCoreName.get(coreName); - try (SolrClient adminClient = getHttpSolrClient(replicaBaseUrl)) { + try (SolrClient adminClient = new HttpJettySolrClient.Builder(replicaBaseUrl).build()) { Collection snapshots = listCoreSnapshots(adminClient, coreName); Optional metaData = snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); @@ -276,7 +277,7 @@ public void testSnapshots() throws Exception { String replicaBaseUrl = replica.getBaseUrl(); String coreName = replica.getCoreName(); - try (SolrClient adminClient = getHttpSolrClient(replicaBaseUrl)) { + try (SolrClient adminClient = new HttpJettySolrClient.Builder(replicaBaseUrl).build()) { Collection snapshots = listCoreSnapshots(adminClient, coreName); Optional metaData = snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java index 431a43a2fb78..33ab744012b3 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java @@ -99,7 +99,9 @@ public void testBackupRestore() throws Exception { String duplicateName = commitName.concat("_duplicate"); try (SolrClient adminClient = - getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + new HttpJettySolrClient.Builder( + cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) + .build(); SolrClient leaderClient = new HttpJettySolrClient.Builder(replica.getBaseUrl()) .withDefaultCollection(replica.getCoreName()) @@ -193,7 +195,9 @@ public void testIndexOptimization() throws Exception { String commitName = TestUtil.randomSimpleString(random(), 1, 5); try (SolrClient adminClient = - getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + new HttpJettySolrClient.Builder( + cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) + .build(); SolrClient leaderClient = new HttpJettySolrClient.Builder(replica.getBaseUrl()) .withDefaultCollection(replica.getCoreName()) diff --git a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java index 8e7b5ab80ed0..3096e9a05a7c 100644 --- a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java +++ b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java @@ -36,6 +36,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.FileStoreApi; import org.apache.solr.client.solrj.request.V2Request; import org.apache.solr.client.solrj.response.SimpleSolrResponse; @@ -173,7 +174,8 @@ public void testFileStoreManagement() throws Exception { for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) { final var fetchReq = new FileStoreApi.FetchFile("/package/mypkg/v1.0/runtimelibs.jar2"); fetchReq.setGetFrom("someFakeSolrNode:8983_solr"); - try (final var solrClient = jettySolrRunner.newClient()) { + try (final var solrClient = + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { final var expectedExc = expectThrows( RemoteSolrException.class, 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 7f45190869a7..f197a3c117eb 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -53,6 +53,7 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoresApi; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -243,7 +244,7 @@ private void reloadCore(JettySolrRunner jettySolrRunner, String core) throws Exc } private SolrClient adminClient(JettySolrRunner client) { - return getHttpSolrClient(client.getBaseUrl().toString()); + return new HttpJettySolrClient.Builder(client.getBaseUrl().toString()).build(); } @Test 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 6305473b94e5..aad31ef2626e 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java @@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -62,7 +63,10 @@ public void beforeTest() throws Exception { (CollectionAdminRequest.createCollection(DEFAULT_TEST_COLLECTION_NAME, "conf1", 1, 1) .process(cluster.getSolrClient()) .getStatus())); - adminClient = getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + adminClient = + new HttpJettySolrClient.Builder( + cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) + .build(); initCoreNameAndSolrCoreClient(); } @@ -80,7 +84,10 @@ private void initCoreNameAndSolrCoreClient() { .iterator() .next(); coreName = r.getCoreName(); - coreClient = getHttpSolrClient(r); + coreClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build(); } @After 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 70db545fced4..c92edb046746 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java @@ -41,6 +41,7 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -96,7 +97,10 @@ public void beforeTest() throws Exception { (CollectionAdminRequest.createCollection(DEFAULT_TEST_COLLECTION_NAME, "conf1", 1, 1) .process(cluster.getSolrClient()) .getStatus())); - adminClient = getHttpSolrClient(cluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + adminClient = + new HttpJettySolrClient.Builder( + cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) + .build(); initCoreNameAndSolrCoreClient(); } @@ -371,7 +375,10 @@ private void initCoreNameAndSolrCoreClient() { .iterator() .next(); coreName = r.getCoreName(); - coreClient = getHttpSolrClient(r); + coreClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()) + .withDefaultCollection(r.getCoreName()) + .build(); } /** diff --git a/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java b/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java index aa76092cf5de..0283d770284d 100644 --- a/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java +++ b/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java @@ -21,6 +21,7 @@ import org.apache.commons.io.file.PathUtils; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.V2Request; import org.apache.solr.common.util.NamedList; import org.apache.solr.embedded.JettyConfig; @@ -39,7 +40,8 @@ public void testWelcomeMessage() throws Exception { new JettySolrRunner(solrHomeTmp.toString(), JettyConfig.builder().build()); jetty.start(); - try (SolrClient client = getHttpSolrClient(buildUrl(jetty.getLocalPort()))) { + try (SolrClient client = + new HttpJettySolrClient.Builder(buildUrl(jetty.getLocalPort())).build()) { NamedList res = client.request(new V2Request.Builder("/").build()); NamedList header = (NamedList) res.get("responseHeader"); assertEquals(0, header.get("status")); 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 66627c225833..7b6890360122 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 @@ -34,6 +34,7 @@ import org.apache.solr.client.api.model.CoreStatusResponse; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.json.JacksonContentWriter; @@ -418,7 +419,8 @@ public void testDeleteInstanceDirAfterCreateFailure() throws Exception { runner.getSolrClient().commit("corex"); Path dataDir = null; - try (SolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(runner.getBaseUrl().toString()).build()) { final var status = CoreAdminRequest.getCoreStatus("corex", true, client); String dataDirectory = status.dataDir; dataDir = Path.of(dataDirectory); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java index 96cb2f4c4256..a839d10ccbcd 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java @@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.HealthCheckRequest; @@ -75,13 +76,15 @@ public void testHealthCheckHandler() throws Exception { // positive check that our exiting "healthy" node works with direct http client try (SolrClient solrClient = - getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); } // successfully create a dummy collection try (SolrClient solrClient = - getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { CollectionAdminResponse collectionAdminResponse = CollectionAdminRequest.createCollection("test", "_default", 1, 1) .withProperty("solr.directoryFactory", "solr.StandardDirectoryFactory") @@ -95,7 +98,8 @@ public void testHealthCheckHandler() throws Exception { // add a new node for the purpose of negative testing JettySolrRunner newJetty = cluster.startJettySolrRunner(); - try (SolrClient solrClient = getHttpSolrClient(newJetty.getBaseUrl().toString())) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(newJetty.getBaseUrl().toString()).build()) { // positive check that our (new) "healthy" node works with direct http client final var response = runHealthcheckWithClient(solrClient); @@ -116,7 +120,8 @@ public void testHealthCheckHandler() throws Exception { // (redundant) positive check that our (previously) exiting "healthy" node (still) works // after getting negative results from our broken node and failed core container try (SolrClient solrClient = - getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); } @@ -127,7 +132,8 @@ public void testHealthCheckHandlerSolrJ() throws IOException, SolrServerExceptio // positive check of a HealthCheckRequest using http client HealthCheckRequest req = new HealthCheckRequest(); try (SolrClient solrClient = - getHttpSolrClient(cluster.getJettySolrRunner(0).getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { HealthCheckResponse rsp = req.process(solrClient); assertEquals(CommonParams.OK, rsp.getNodeStatus()); } @@ -148,7 +154,8 @@ public void testHealthCheckHandlerSolrJ() throws IOException, SolrServerExceptio @Test public void testV1FailureResponseIncludesStatusField() throws Exception { JettySolrRunner newJetty = cluster.startJettySolrRunner(); - try (SolrClient solrClient = getHttpSolrClient(newJetty.getBaseUrl().toString())) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(newJetty.getBaseUrl().toString()).build()) { // Sanity check: the new node is initially healthy. assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java b/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java index c9ddbabe2bbc..2c270eef2b93 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.LukeRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -137,7 +138,10 @@ public void testInconsistentIndexFlagsAcrossShards() throws Exception { String targetSliceName = null; for (Slice slice : docColl.getSlices()) { Replica leader = slice.getLeader(); - try (SolrClient client = getHttpSolrClient(leader)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) + .build()) { SolrQuery q = new SolrQuery("id:target"); q.set(DISTRIB, "false"); QueryResponse qr = client.query(q); @@ -153,7 +157,10 @@ public void testInconsistentIndexFlagsAcrossShards() throws Exception { for (Slice slice : docColl.getSlices()) { if (!slice.getName().equals(targetSliceName)) { Replica leader = slice.getLeader(); - try (SolrClient client = getHttpSolrClient(leader)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) + .build()) { SolrQuery q = new SolrQuery("*:*"); q.setRows(1); q.set(DISTRIB, "false"); diff --git a/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java b/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java index fcc0efde3ba5..4077b78cbd5a 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -90,7 +91,8 @@ public void test() throws Exception { .equals(getCollectionState(COLLECTION).getLeader("shard1").getBaseUrl())) { specialIdx = solrClients.size(); } - solrClients.add(jettySolrRunner.newClient()); + solrClients.add( + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()); } new UpdateRequest() diff --git a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java index ad9bcf5a479d..7a9a65360f65 100644 --- a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.cloud.MiniSolrCloudCluster; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.NodeConfig; @@ -123,7 +124,8 @@ public void testZkMetrics() throws Exception { reader, "solr_zk_ops", baseLabels.merge(Labels.of("ops", type)))); } - try (SolrClient solrClient = j.newClient()) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(j.getBaseUrl().toString()).build()) { assertNotNull(solrClient); HttpClient httpClient = j.getSolrClient().getHttpClient(); var initialChildFetches = 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 610b7267cbe3..88bf8a94f40f 100644 --- a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.MetricsRequest; import org.apache.solr.client.solrj.response.InputStreamResponseParser; import org.apache.solr.common.params.ModifiableSolrParams; @@ -68,7 +69,8 @@ public void testPrometheusStructureOutput() throws Exception { params.set("wt", "prometheus"); var req = new MetricsRequest(params); // response parser set in MetricsRequest constructor - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); String output = InputStreamResponseParser.consumeResponseToString(res); @@ -119,7 +121,8 @@ public void testAcceptHeaderOpenMetricsFormat() throws Exception { req.addHeader("Accept", "application/openmetrics-text;version=1.0.0"); - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); try (InputStream in = (InputStream) res.get(STREAM_KEY)) { @@ -137,7 +140,8 @@ public void testWtParameterOpenMetricsFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("openmetrics")); - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); try (InputStream in = (InputStream) res.get(STREAM_KEY)) { @@ -155,7 +159,8 @@ public void testDefaultPrometheusFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("prometheus")); - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); try (InputStream in = (InputStream) res.get(STREAM_KEY)) { @@ -173,7 +178,8 @@ public void testDefaultPrometheusFormatNoWtParam() throws Exception { req.setResponseParser(new InputStreamResponseParser(null)); - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); try (InputStream in = (InputStream) res.get(STREAM_KEY)) { @@ -191,7 +197,8 @@ public void testUnsupportedMetricsFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("unknownFormat")); - try (SolrClient adminClient = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient adminClient = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { NamedList res = adminClient.request(req); InputStream stream = (InputStream) res.get("stream"); if (stream != null) stream.close(); diff --git a/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java index 0190653249be..a59b39daf495 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java @@ -26,6 +26,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.InputStreamResponseParser; @@ -62,13 +63,13 @@ public static void beforeClass() throws Exception { initStandalone(); JSR.start(); if (random().nextBoolean()) { - CLIENT = JSR.newClient(); + CLIENT = new HttpJettySolrClient.Builder(JSR.getBaseUrl().toString()).build(); } else { CLIENT = new EmbeddedSolrServer(JSR.getCoreContainer(), null); } } else { initCloud(); - CLIENT = JSR.newClient(); + CLIENT = new HttpJettySolrClient.Builder(JSR.getBaseUrl().toString()).build(); JSR = null; } initIndex(); diff --git a/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java b/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java index 2b770f7f23c6..3d235e40d962 100644 --- a/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java +++ b/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest; import org.apache.solr.client.solrj.response.schema.SchemaResponse; @@ -58,7 +59,9 @@ public void testAddFieldsRoundRobin() throws Exception { try { for (int shardNum = 0; shardNum < NUM_SHARDS; ++shardNum) { clients.add( - getHttpSolrClient(cluster.getJettySolrRunners().get(shardNum).getBaseUrl().toString())); + new HttpJettySolrClient.Builder( + cluster.getJettySolrRunners().get(shardNum).getBaseUrl().toString()) + .build()); } int shardNum = 0; for (int fieldNum = 0; fieldNum < NUM_FIELDS_TO_ADD; ++fieldNum) { diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java index 3dbe061559fb..9a641323d5ef 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java +++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java @@ -219,7 +219,8 @@ public void testNRTRestart() throws Exception { } assertNotNull(nrtJetty); assertNotNull(pullJetty); - try (SolrClient client = pullJetty.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(pullJetty.getBaseUrl().toString()).build()) { client.add(COLL, sid); client.commit(COLL); assertEquals( diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java index 2853d1c7c3fd..c993c4a49013 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java @@ -31,6 +31,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -123,7 +124,10 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) - CLIENTS.add(getHttpSolrClient(jetty.getBaseUrl().toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); final int numDocs = atLeast(100); for (int id = 0; id < numDocs; id++) { diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java index 48ccb4a133f3..53b44f60af36 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java @@ -34,6 +34,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -150,7 +151,10 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add(getHttpSolrClient(jetty.getBaseUrl().toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } final int numDocs = atLeast(100); diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java index deec286fd215..a5952bd235ee 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java @@ -37,6 +37,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -142,7 +143,10 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add(getHttpSolrClient(jetty.getBaseUrl().toString(), COLLECTION_NAME)); + CLIENTS.add( + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) + .withDefaultCollection(COLLECTION_NAME) + .build()); } final int numDocs = atLeast(100); diff --git a/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java b/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java index 4f63b16f52f7..a7b39837c590 100644 --- a/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java +++ b/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java @@ -22,6 +22,7 @@ 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.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -108,9 +109,10 @@ public void testSimpleQuery() throws Exception { // Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - try (SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { try (SolrClient solrClient_local = - getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { SolrQuery query = new SolrQuery("cat:football"); query.setFields("*,score"); @@ -160,10 +162,11 @@ public void testMultiCollectionQuery() throws Exception { // Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - try (SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { try (SolrClient solrClient_local = - getHttpSolrClient(jettySolrRunner.getBaseUrl().toString())) { + new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { SolrQuery query = new SolrQuery("cat:football"); query.setFields("*,score").add("collection", "collection1,collection2"); QueryResponse queryResponse = solrClient.query("collection1", query); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index 9684d5447cf7..3666befc374b 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -31,6 +31,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -210,7 +211,7 @@ public void testBasicAuth() throws Exception { CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(COLLECTION); - try (var solrClient2 = getHttpSolrClient(baseUrl)) { + try (var solrClient2 = new HttpJettySolrClient.Builder(baseUrl).build()) { expectThrows(RemoteSolrException.class, () -> solrClient2.request(reload)); reload.setMethod(SolrRequest.METHOD.POST); expectThrows(RemoteSolrException.class, () -> solrClient2.request(reload)); @@ -247,7 +248,8 @@ public void testBasicAuth() throws Exception { // Test for SOLR-12514. Create a new jetty . This jetty does not have the collection. // Make a request to that jetty and it should fail JettySolrRunner aNewJetty = cluster.startJettySolrRunner(); - SolrClient aNewClient = aNewJetty.newClient(); + SolrClient aNewClient = + new HttpJettySolrClient.Builder(aNewJetty.getBaseUrl().toString()).build(); UpdateRequest delQuery = null; delQuery = new UpdateRequest().deleteByQuery("*:*"); delQuery.setBasicAuthCredentials("harry", "HarryIsUberCool"); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java index 63c83c135792..efbedee74f43 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.util.Utils; import org.apache.solr.embedded.JettySolrRunner; @@ -75,7 +76,7 @@ public void testBasicAuth() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 20); diff --git a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java index 9cb8d774989a..fd05a64a72f1 100644 --- a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java +++ b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java @@ -39,6 +39,7 @@ import java.util.stream.Collectors; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.util.CommandOperation; @@ -90,7 +91,7 @@ public void testMultiAuthEditAPI() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -266,7 +267,7 @@ public void testMultiAuthXBasicLookup() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -308,7 +309,7 @@ public void testMultiAuthWithBasicAndXBasic() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -354,7 +355,7 @@ public void testMultiAuthWithSinglePlugin() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -395,7 +396,7 @@ public void testMultiAuthWithBasicAndMockPlugin() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -432,7 +433,7 @@ public void testMultiAuthWithBasicPluginAndAjax() throws Exception { try { var httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = getHttpSolrClient(baseUrl); + solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); 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 4a92852cbdc5..9f77d3bd636c 100644 --- a/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java +++ b/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java @@ -27,6 +27,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.impl.LBSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.cloud.CloudInspectUtil; @@ -114,10 +115,16 @@ private void checkShardsConsistentNumFound() throws Exception { final String shardName = entry.getKey(); final Slice slice = entry.getValue(); final Replica leader = entry.getValue().getLeader(); - try (SolrClient leaderClient = getHttpSolrClient(leader)) { + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) + .build()) { final SolrDocumentList leaderResults = leaderClient.query(params).getResults(); for (Replica replica : slice) { - try (SolrClient replicaClient = getHttpSolrClient(replica)) { + try (SolrClient replicaClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { final SolrDocumentList replicaResults = replicaClient.query(params).getResults(); assertEquals( "inconsistency w/leader: shard=" + shardName + "core=" + replica.getCoreName(), diff --git a/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java b/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java index 6c1dcc0fa8b9..c4e03ae5b25f 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java +++ b/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.lucene.util.IOUtils; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.json.JsonQueryRequest; @@ -59,7 +60,7 @@ public static void setupCluster() throws Exception { CLIENTS.add(cluster.getSolrClient()); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - final SolrClient c = getHttpSolrClient(jetty.getBaseUrl().toString()); + final SolrClient c = new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build(); NODE_CLIENTS.add(c); CLIENTS.add(c); } 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 c791c7fe7eb9..ba5a7fd73e3e 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 @@ -439,7 +439,7 @@ public void testExampleConfig() throws Exception { if (solrTestRule.getJetty() != null) { // check system wide system handler + "/admin/info/system" String url = solrTestRule.getBaseUrl(); - try (SolrClient adminClient = getHttpSolrClient(url)) { + try (SolrClient adminClient = new HttpJettySolrClient.Builder(url).build()) { SolrQuery q = new SolrQuery(); final var rsp = new SystemInfoRequest().process(adminClient); 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 8d41ab9ce224..f4716ee0de1a 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 @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; 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; @@ -78,8 +79,9 @@ protected SolrClient getSolrClient() { * options. */ public SolrClient createNewSolrClient() { - return SolrTestCaseJ4.getHttpSolrClient( - solrTestRule.getBaseUrl(), DEFAULT_TEST_COLLECTION_NAME); + return new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()) + .withDefaultCollection(DEFAULT_TEST_COLLECTION_NAME) + .build(); } /** query the example */ diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java index 88ae42fc32c4..913253ec2754 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java @@ -406,7 +406,8 @@ public void testRouting() throws Exception { params.add("distrib", "false"); QueryRequest queryRequest = new QueryRequest(params); - try (SolrClient solrClient = getHttpSolrClient(baseUrl, coreName)) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(coreName).build()) { QueryResponse queryResponse = queryRequest.process(solrClient); SolrDocumentList docList = queryResponse.getResults(); assertEquals(1, docList.getNumFound()); @@ -455,7 +456,8 @@ public void testRouting() throws Exception { params.add("q", "id:" + id); params.add("distrib", "false"); QueryRequest queryRequest = new QueryRequest(params); - try (SolrClient solrClient = getHttpSolrClient(baseUrl, coreName)) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(coreName).build()) { QueryResponse queryResponse = queryRequest.process(solrClient); SolrDocumentList docList = queryResponse.getResults(); assertEquals(1, docList.getNumFound()); @@ -847,7 +849,8 @@ public void stateVersionParamTest() throws Exception { SolrQuery q = new SolrQuery().setQuery("*:*"); RemoteSolrException sse = null; - try (SolrClient solrClient = getHttpSolrClient(r.getBaseUrl(), COLLECTION)) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(r.getBaseUrl()).withDefaultCollection(COLLECTION).build()) { if (log.isInfoEnabled()) { log.info("should work query, result {}", solrClient.query(q)); @@ -893,7 +896,8 @@ public void stateVersionParamTest() throws Exception { log.info("the node which does not serve this collection{} ", theNode); assertNotNull(theNode); - try (SolrClient solrClient = getHttpSolrClient(theNode, COLLECTION)) { + try (SolrClient solrClient = + new HttpJettySolrClient.Builder(theNode).withDefaultCollection(COLLECTION).build()) { q.setParam(CloudSolrClient.STATE_VERSION, COLLECTION + ":" + (coll.getZNodeVersion() - 1)); try { 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 e9c4e9e093a6..0a1c81363e9a 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 @@ -23,6 +23,7 @@ import java.util.List; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.util.EnvUtils; import org.apache.solr.util.ExternalPaths; import org.apache.solr.util.SolrJettyTestRule; @@ -50,7 +51,10 @@ public static void beforeTest() throws Exception { @Test public void testDeleteByIdReportsInvalidIdLists() throws Exception { - try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl(), ANY_COLLECTION)) { + try (SolrClient client = + new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()) + .withDefaultCollection(ANY_COLLECTION) + .build()) { assertExceptionThrownWithMessageContaining( IllegalArgumentException.class, List.of("ids", "null"), @@ -77,7 +81,7 @@ public void testDeleteByIdReportsInvalidIdLists() throws Exception { }); } - try (SolrClient client = getHttpSolrClient(solrTestRule.getBaseUrl())) { + try (SolrClient client = new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { assertExceptionThrownWithMessageContaining( IllegalArgumentException.class, List.of("ids", "null"), diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LB2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LB2SolrClientTest.java index 849d8953c0fa..5fca5e8f7898 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LB2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LB2SolrClientTest.java @@ -91,7 +91,9 @@ private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerEx } SolrResponseBase resp; try (SolrClient client = - getHttpSolrClient(solrInstance.getBaseUrl(), solrInstance.getDefaultCollection())) { + new HttpJettySolrClient.Builder(solrInstance.getBaseUrl()) + .withDefaultCollection(solrInstance.getDefaultCollection()) + .build()) { resp = client.add(docs); assertEquals(0, resp.getStatus()); resp = client.commit(); diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java index 2cc6ea7ce5af..332863410cbe 100644 --- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java +++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java @@ -51,6 +51,7 @@ import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -455,7 +456,9 @@ public SequencedMap, String> getExtraRequestFilters() { } protected HttpSolrClient createNewSolrClient(int port) { - return getHttpSolrClient(buildUrl(port), DEFAULT_TEST_CORENAME); + return new HttpJettySolrClient.Builder(buildUrl(port)) + .withDefaultCollection(DEFAULT_TEST_CORENAME) + .build(); } protected static void addFields(SolrInputDocument doc, Object... fields) { diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java index 160da2b1a85f..a2f4b24834a9 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java @@ -35,6 +35,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.InputStreamResponseParser; @@ -405,7 +406,8 @@ public String getShardURL() { public SolrClient getSolrJ() { if (solrj == null) { - solrj = getHttpSolrClient(getBaseURL(), collection); + solrj = + new HttpJettySolrClient.Builder(getBaseURL()).withDefaultCollection(collection).build(); } return solrj; } 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 b3c50f8e151b..902d70e3b56b 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -89,7 +89,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputField; -import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.MultiMapSolrParams; @@ -2557,38 +2556,6 @@ private void randomizeCloudSolrClient() { } } - /** - * This method creates a basic HttpSolrClient. Tests that want to control the creation process - * should use the {@link org.apache.solr.client.solrj.jetty.HttpJettySolrClient.Builder} class - * directly - * - * @param url the base URL for a Solr node. Should not contain a core or collection name. - */ - @Deprecated // probably use an existing client like on a testRule/jettyRunner - public static HttpJettySolrClient getHttpSolrClient(String url) { - return new HttpJettySolrClient.Builder(url).build(); - } - - /** Create a basic HttpSolrClient pointed at the specified replica */ - @Deprecated // probably use an existing client like on a testRule/jettyRunner - public static HttpJettySolrClient getHttpSolrClient(Replica replica) { - return getHttpSolrClient(replica.getBaseUrl(), replica.getCoreName()); - } - - /** - * This method creates a basic HttpSolrClient. Tests that want to control the creation process - * should use the {@link org.apache.solr.client.solrj.jetty.HttpJettySolrClient.Builder} class - * directly - * - * @param url the base URL of a Solr node. Should not include a collection or core name. - * @param defaultCoreName the name of a core that the created client should default to when making - * core-aware requests - */ - @Deprecated // probably use an existing client like on a testRule/jettyRunner - public static HttpJettySolrClient getHttpSolrClient(String url, String defaultCoreName) { - return new HttpJettySolrClient.Builder(url).withDefaultCollection(defaultCoreName).build(); - } - /** * Returns a randomly generated Date in the appropriate Solr external (input) format * diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 56227abba3eb..0c83cc3d8a72 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -2838,7 +2838,7 @@ protected String printClusterStateInfo(String collection) throws Exception { protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { String coreName = replica.getCoreName(); boolean reloadedOk = false; - try (SolrClient client = getHttpSolrClient(replica.getBaseUrl())) { + try (SolrClient client = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java index f4bc7e54bb8f..7548f869401e 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java @@ -40,6 +40,7 @@ import org.apache.solr.client.solrj.SolrRequest.METHOD; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; @@ -555,7 +556,7 @@ private void collectStartTimes(String collectionName, Map urlToTim for (Slice shard : collectionState) { for (Replica replica : shard) { CoreStatusResponse.SingleCoreData coreStatus; - try (SolrClient server = getHttpSolrClient(replica.getBaseUrl())) { + try (SolrClient server = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) { coreStatus = CoreAdminRequest.getCoreStatus(replica.getCoreName(), false, server); } long before = coreStatus.startTime.getTime(); @@ -635,7 +636,7 @@ public void addReplicaTest() throws Exception { assertNotNull(newReplica); cluster.waitForActiveCollection(collectionName, 2, 6); - try (SolrClient coreclient = getHttpSolrClient(newReplica.getBaseUrl())) { + try (SolrClient coreclient = new HttpJettySolrClient.Builder(newReplica.getBaseUrl()).build()) { CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); final var coreStatus = status.getCoreStatus(newReplica.getStr("core")); String instanceDirStr = coreStatus.instanceDir; diff --git a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java index 0a0f8554da0c..f3d5112f5a5f 100644 --- a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java +++ b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java @@ -690,7 +690,7 @@ public void dumpCoresInfo(PrintStream pw) { if (getCoreContainer() != null) { final var coreStatusReq = new CoresApi.GetAllCoreStatus(); coreStatusReq.setIndexInfo(true); - try (final var client = newClient()) { + try (final var client = new HttpJettySolrClient.Builder(getBaseUrl().toString()).build()) { final var coreStatusRsp = coreStatusReq.process(client); Utils.writeJson(coreStatusRsp, pw, true); } catch (SolrServerException | IOException e) { @@ -785,11 +785,6 @@ public URL getProxyBaseUrl() { } } - @Deprecated - public HttpJettySolrClient newClient() { - return new HttpJettySolrClient.Builder(getBaseUrl().toString()).build(); - } - public HttpJettySolrClient newClient(int connectionTimeoutMillis, int socketTimeoutMillis) { return new HttpJettySolrClient.Builder(getBaseUrl().toString()) .withConnectionTimeout(connectionTimeoutMillis, TimeUnit.MILLISECONDS) diff --git a/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java b/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java index 230a279864dd..a941574e7acf 100644 --- a/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java +++ b/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java @@ -25,6 +25,7 @@ import java.util.Properties; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.cloud.MiniSolrCloudCluster; import org.junit.Test; @@ -55,7 +56,8 @@ public void testPassSolrHomeToRunner() throws Exception { try { runner.start(); - try (SolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { + try (SolrClient client = + new HttpJettySolrClient.Builder(runner.getBaseUrl().toString()).build()) { CoreAdminRequest.Create createReq = new CoreAdminRequest.Create(); createReq.setCoreName("newcore"); createReq.setConfigSet("minimal"); From 92ed892c26ca11aba8a21e3d0f2859b29f750f53 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Fri, 21 Aug 2026 14:10:07 +0300 Subject: [PATCH 02/24] SOLR-18390: evaluate Slice.getLeader() once per client, not twice The mechanical migration called .getLeader() separately for getBaseUrl() and getCoreName(). For PRS collections getLeader() recomputes the leader on every call (its own comment: 'leader may keep changing') -- calling it twice risked getBaseUrl() and getCoreName() coming from two different replicas if the leader changed in between. Capture it once instead. --- .../cloud/FullSolrCloudDistribCmdsTest.java | 20 +++++++++++-------- .../apache/solr/cloud/TestPullReplica.java | 15 ++++++++------ .../cloud/TestPullReplicaErrorHandling.java | 5 +++-- .../solr/cloud/TestPullReplicaWithAuth.java | 5 +++-- .../apache/solr/cloud/TestTlogReplica.java | 10 ++++++---- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java index e162c35b15a6..451fadbeae13 100644 --- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java @@ -171,13 +171,15 @@ public void testDeleteByIdImplicitRouter() throws Exception { (n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2)); final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); + Replica shard1Leader = docCol.getSlice("shard1").getLeader(); + Replica shard2Leader = docCol.getSlice("shard2").getLeader(); try (SolrClient shard1 = - new HttpJettySolrClient.Builder(docCol.getSlice("shard1").getLeader().getBaseUrl()) - .withDefaultCollection(docCol.getSlice("shard1").getLeader().getCoreName()) + new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl()) + .withDefaultCollection(shard1Leader.getCoreName()) .build(); SolrClient shard2 = - new HttpJettySolrClient.Builder(docCol.getSlice("shard2").getLeader().getBaseUrl()) - .withDefaultCollection(docCol.getSlice("shard2").getLeader().getCoreName()) + new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl()) + .withDefaultCollection(shard2Leader.getCoreName()) .build()) { // Add three documents to shard1 @@ -332,13 +334,15 @@ public void testDeleteByIdCompositeRouterWithRouterField() throws Exception { (n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2)); final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); + Replica shard1Leader = docCol.getSlice("shard1").getLeader(); + Replica shard2Leader = docCol.getSlice("shard2").getLeader(); try (SolrClient shard1 = - new HttpJettySolrClient.Builder(docCol.getSlice("shard1").getLeader().getBaseUrl()) - .withDefaultCollection(docCol.getSlice("shard1").getLeader().getCoreName()) + new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl()) + .withDefaultCollection(shard1Leader.getCoreName()) .build(); SolrClient shard2 = - new HttpJettySolrClient.Builder(docCol.getSlice("shard2").getLeader().getBaseUrl()) - .withDefaultCollection(docCol.getSlice("shard2").getLeader().getCoreName()) + new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl()) + .withDefaultCollection(shard2Leader.getCoreName()) .build()) { // Add six documents w/diff routes (all sent to shard1 leader's core) 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 2c5893571d48..13ba5dff4994 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -297,9 +297,10 @@ public void testAddDocs() throws Exception { log.info("Committed doc {} to leader", numDocs); Slice s = docCollection.getSlices().iterator().next(); + Replica sliceLeader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) + .withDefaultCollection(sliceLeader.getCoreName()) .build()) { assertEquals(numDocs, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -592,9 +593,10 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar")); cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); + Replica sliceLeader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) + .withDefaultCollection(sliceLeader.getCoreName()) .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -701,9 +703,10 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { // add docs agin cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "zoo")); s = docCollection.getSlices().iterator().next(); + sliceLeader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) + .withDefaultCollection(sliceLeader.getCoreName()) .build()) { leaderClient.commit(); assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java index 78b805d79b58..f3ff272d21f8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java @@ -140,9 +140,10 @@ public void testCantConnectToPullReplica() throws Exception { proxy.close(); for (int i = 1; i <= 10; i++) { addDocs(10 + i); + Replica leader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) .build()) { assertNumDocs(10 + i, leaderClient); } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java index 77e64f382da9..d9079ceefb1e 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java @@ -94,9 +94,10 @@ public void testPKIAuthWorksForPullReplication() throws Exception { ureq.commit(solrClient, collectionName); Slice s = docCollection.getSlices().iterator().next(); + Replica leader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(leader.getBaseUrl()) + .withDefaultCollection(leader.getCoreName()) .build()) { assertEquals( numDocs, 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 680f779b3999..635a19049580 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -255,9 +255,10 @@ public void testAddDocs() throws Exception { cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); + Replica sliceLeader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) + .withDefaultCollection(sliceLeader.getCoreName()) .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } @@ -447,9 +448,10 @@ private void doReplaceLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar")); cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); + Replica sliceLeader = s.getLeader(); try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(s.getLeader().getBaseUrl()) - .withDefaultCollection(s.getLeader().getCoreName()) + new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) + .withDefaultCollection(sliceLeader.getCoreName()) .build()) { assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); } From 0282e5770b69706a80aa02505506ad623829d295 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 22 Aug 2026 13:50:19 +0300 Subject: [PATCH 03/24] SOLR-18390: fix CI -- migrate solr:webapp's 8 missed JettySolrRunner.newClient() call sites CI (ecjLintTest / compileTestJava) failed: the solr/webapp module wasn't covered by the original migration sweep, so its 8 call sites across 5 test files still called the now-removed no-arg newClient(). Migrated them to the same new HttpJettySolrClient.Builder(baseUrl).build() pattern used everywhere else in this PR. --- .../solr/webapp/AdminUiCoreAdminStandaloneTest.java | 7 +++++-- .../org/apache/solr/webapp/AdminUiQueryScreenTest.java | 5 ++++- .../solr/webapp/AdminUiReplicationStandaloneTest.java | 7 +++++-- .../org/apache/solr/webapp/AdminUiSecurityAuthTest.java | 9 +++++++-- .../src/test/org/apache/solr/webapp/AdminUiTestBase.java | 4 +++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java index 0508fd636e79..eab18b6b9937 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java @@ -18,6 +18,7 @@ import java.nio.file.Path; import java.util.Map; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; @@ -95,7 +96,8 @@ public void testRenameCoreViaUi() throws Exception { @Test public void testSwapCoresViaUi() throws Exception { // make the cores distinguishable: swapa gets one document, swapb stays empty - try (var client = standaloneJetty.newClient()) { + try (var client = + new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { var doc = new SolrInputDocument(); doc.addField("id", "swap-doc"); client.add("swapa", doc); @@ -136,7 +138,8 @@ private boolean coreExists(String coreName) { } private long numDocs(String coreName) { - try (var client = standaloneJetty.newClient()) { + try (var client = + new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { return client.query(coreName, new SolrQuery("*:*")).getResults().getNumFound(); } catch (Exception e) { throw new RuntimeException(e); diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java index 86ee2ba1fe0f..e052b826e394 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java @@ -18,6 +18,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.common.SolrInputDocument; @@ -93,7 +94,9 @@ public void testParamsetDropdown() throws Exception { setParams.setContentWriter( new RequestWriter.StringPayloadContentWriter( "{\"set\":{\"" + paramset + "\":{\"rows\":\"2\"}}}", CommonParams.JSON_MIME)); - try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { client.request(setParams); } diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java index 3d0f636f75d5..636724854812 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java @@ -21,6 +21,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Properties; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; @@ -90,7 +91,8 @@ public void testReplicationScreenAndActions() throws Exception { "polling should be disabled", () -> "true".equals(followerDetail("isPollingDisabled"))); // index documents on the leader; the follower does not poll them - try (var client = leaderJetty.newClient()) { + try (var client = + new HttpJettySolrClient.Builder(leaderJetty.getBaseUrl().toString()).build()) { for (int i = 1; i <= 2; i++) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "repl-doc-" + i); @@ -150,7 +152,8 @@ private String followerDetail(String key) { } private long followerNumDocs() { - try (var client = standaloneJetty.newClient()) { + try (var client = + new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { return client.query(CORE, new SolrQuery("*:*")).getResults().getNumFound(); } catch (Exception e) { throw new RuntimeException(e); diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java index db53010a6a67..250807a62dc8 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java @@ -20,6 +20,7 @@ import java.util.Map; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.util.NamedList; import org.junit.BeforeClass; @@ -139,7 +140,9 @@ public void testLoginAndSecurityScreen() throws Exception { /** Returns the authorization config as fetched with credentials. */ private NamedList authorizationApi() { - try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { GenericSolrRequest req = new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/authorization", params()); req.setBasicAuthCredentials(USER, PASS); @@ -163,7 +166,9 @@ private String permissionRole(String permission) { /** Checks via the authentication API (with credentials) whether the user exists. */ private boolean userExists(String user) { - try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) + .build()) { GenericSolrRequest req = new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/authentication", params()); req.setBasicAuthCredentials(USER, PASS); diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java index 5d0ea91fe9f4..476aeef6e6aa 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java @@ -41,6 +41,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.SolrCloudTestCase; @@ -382,7 +383,8 @@ protected static NamedList adminApi(String path, SolrParams params) throws IOException, SolrServerException { ensureCloudCluster(); JettySolrRunner jetty = standaloneMode ? standaloneJetty : cluster.getJettySolrRunner(0); - try (SolrClient client = jetty.newClient()) { + try (SolrClient client = + new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { return client.request(new GenericSolrRequest(SolrRequest.METHOD.GET, path, params)); } } From ca5b9123d07c3442501b89e2ceb5f47dc5d6d8be Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sun, 23 Aug 2026 09:45:46 +0300 Subject: [PATCH 04/24] SOLR-18390: reuse the runner's shared client instead of constructing a new one Where a JettySolrRunner reference is directly available, use its own getSolrClient()/newSolrClient(collection) instead of building a fresh HttpJettySolrClient. 59 call sites (51 core/benchmark, 8 webapp). newSolrClient() builds a fresh, uncached client per call (unlike getSolrClient()), so those sites keep an explicit close -- caught via ObjectReleaseTracker flagging 9 leaked clients before this fix. 3 sites left as constructed clients for verified reasons: explicit close ownership elsewhere, a stop()/start() cycle invalidating a cached client mid-test, or an in-flight request needing to survive a runner shutdown that closes the cached client first. --- .../solr/bench/lifecycle/SolrStartup.java | 9 +- .../solr/cloud/AliasIntegrationTest.java | 12 +- .../solr/cloud/DeleteInactiveReplicaTest.java | 31 +++-- .../solr/cloud/RemoteQueryErrorTest.java | 21 ++-- .../solr/cloud/TestBaseStatsCacheCloud.java | 81 +++++++------ ...stCloudPhrasesIdentificationComponent.java | 6 +- .../cloud/TestCloudPseudoReturnFields.java | 6 +- .../apache/solr/cloud/TestCloudRecovery2.java | 41 ++++--- .../cloud/TestQueryingOnDownCollection.java | 61 ++++------ .../solr/cloud/TestTlogReplayVsRecovery.java | 26 ++--- .../apache/solr/cloud/TestTlogReplica.java | 30 +++-- .../core/snapshots/TestSolrCoreSnapshots.java | 26 ++--- .../solr/filestore/TestDistribFileStore.java | 25 ++-- .../solr/handler/TestReplicationHandler.java | 57 +++++---- .../handler/TestStressIncrementalBackup.java | 8 +- .../solr/handler/TestStressThreadBackup.java | 8 +- .../handler/admin/CoreAdminHandlerTest.java | 13 +-- .../handler/admin/HealthCheckHandlerTest.java | 41 +++---- .../metrics/SolrMetricsIntegrationTest.java | 45 ++++---- .../solr/response/TestRawTransformer.java | 5 +- .../ManagedSchemaRoundRobinCloudTest.java | 30 ++--- .../solr/search/TestCoordinatorRole.java | 4 +- .../facet/TestCloudJSONFacetJoinDomain.java | 6 +- .../search/facet/TestCloudJSONFacetSKG.java | 6 +- .../facet/TestCloudJSONFacetSKGEquiv.java | 6 +- .../solr/search/stats/TestDistribIDF.java | 108 ++++++++---------- .../security/BasicAuthIntegrationTest.java | 4 +- .../processor/TestCloudDeduplication.java | 3 +- .../AdminUiCoreAdminStandaloneTest.java | 22 ++-- .../solr/webapp/AdminUiQueryScreenTest.java | 7 +- .../AdminUiReplicationStandaloneTest.java | 26 ++--- .../solr/webapp/AdminUiSecurityAuthTest.java | 14 +-- .../apache/solr/webapp/AdminUiTestBase.java | 9 +- 33 files changed, 329 insertions(+), 468 deletions(-) diff --git a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java index e308aba70b9d..359be6e2e68a 100644 --- a/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/lifecycle/SolrStartup.java @@ -23,7 +23,6 @@ import org.apache.commons.io.file.PathUtils; import org.apache.lucene.util.IOUtils; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; import org.apache.solr.embedded.JettyConfig; @@ -79,11 +78,9 @@ public void bootstrapJettyServer() throws Exception { solrRunner = new JettySolrRunner(tmpSolrHome.toString(), buildJettyConfig()); solrRunner.start(false); - try (SolrClient client = - new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { - for (int i = 0; i < NUM_CORES; i++) { - createCore(client, "core-prefix-" + i); - } + SolrClient client = solrRunner.getSolrClient(); + for (int i = 0; i < NUM_CORES; i++) { + createCore(client, "core-prefix-" + i); } solrRunner.stop(); } diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java index 1349f8868be6..c5b5fdd050f6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -33,7 +33,6 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.ClusterStateProvider; import org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -960,17 +959,12 @@ private void searchSeveralWays( // HttpSolrClient JettySolrRunner jetty = cluster.getRandomJetty(random()); if (random().nextBoolean()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(collectionList) - .build()) { + try (SolrClient client = jetty.newSolrClient(collectionList)) { responseConsumer.accept(client.query(null, solrQuery)); } } else { - try (SolrClient client = - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { - responseConsumer.accept(client.query(collectionList, solrQuery)); - } + SolrClient client = jetty.getSolrClient(); + responseConsumer.accept(client.query(collectionList, solrQuery)); } // Recursively do again; this time with the &collection= param diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java index 606a7235b9fd..35b017aef123 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java @@ -20,7 +20,6 @@ import java.nio.file.Files; import java.util.concurrent.TimeUnit; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.common.cloud.DocCollection; @@ -109,21 +108,19 @@ public void deleteInactiveReplicaTest() throws Exception { && !FileUtils.fileExists(replicaCd.getDataDir())); // Check that we can't create a core with no coreNodeName - try (SolrClient queryClient = - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { - Exception e = - expectThrows( - Exception.class, - () -> { - CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); - createRequest.setCoreName("testcore"); - createRequest.setCollection(collectionName); - createRequest.setShardId("shard2"); - queryClient.request(createRequest); - }); - assertTrue( - "Unexpected error message: " + e.getMessage(), - e.getMessage().contains("coreNodeName missing")); - } + SolrClient queryClient = jetty.getSolrClient(); + Exception e = + expectThrows( + Exception.class, + () -> { + CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); + createRequest.setCoreName("testcore"); + createRequest.setCollection(collectionName); + createRequest.setShardId("shard2"); + queryClient.request(createRequest); + }); + assertTrue( + "Unexpected error message: " + e.getMessage(), + e.getMessage().contains("coreNodeName missing")); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java b/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java index ddaf414e5d0c..a1465260522c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/RemoteQueryErrorTest.java @@ -19,7 +19,6 @@ import static org.hamcrest.core.StringContains.containsString; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; @@ -44,17 +43,15 @@ public void test() throws Exception { .process(cluster.getSolrClient()); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { - SolrException e = - expectThrows( - SolrException.class, - () -> { - client.add("collection", new SolrInputDocument()); - }); - assertThat( - e.getMessage(), containsString("Document is missing mandatory uniqueKey field: id")); - } + SolrClient client = jetty.getSolrClient(); + SolrException e = + expectThrows( + SolrException.class, + () -> { + client.add("collection", new SolrInputDocument()); + }); + assertThat( + e.getMessage(), containsString("Document is missing mandatory uniqueKey field: id")); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java index 3280410bb151..f73c44470592 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestBaseStatsCacheCloud.java @@ -26,7 +26,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.MetricsRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -132,47 +131,45 @@ public void testBasicStats() throws Exception { // check cache metrics StatsCache.StatsCacheMetrics statsCacheMetrics = new StatsCache.StatsCacheMetrics(); for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - var req = new MetricsRequest(SolrParams.of("wt", "prometheus")); - - NamedList resp = client.request(req); - try (InputStream in = (InputStream) resp.get("stream")) { - String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); - - for (String line : output.lines().toList()) { - if (line.startsWith("solr_core_indexsearcher_termstats_cache")) { - String type = extractTypeAttribute(line); - long value = extractMetricValue(line); - switch (type) { - case "lookups": - statsCacheMetrics.lookups.add(value); - break; - case "return_local": - statsCacheMetrics.returnLocalStats.add(value); - break; - case "merge_to_global": - statsCacheMetrics.mergeToGlobalStats.add(value); - break; - case "missing_global_field": - statsCacheMetrics.missingGlobalFieldStats.add(value); - break; - case "missing_global_term": - statsCacheMetrics.missingGlobalTermStats.add(value); - break; - case "receive_global": - statsCacheMetrics.receiveGlobalStats.add(value); - break; - case "retrieve": - statsCacheMetrics.retrieveStats.add(value); - break; - case "send_global": - statsCacheMetrics.sendGlobalStats.add(value); - break; - case "use_cached_global": - statsCacheMetrics.useCachedGlobalStats.add(value); - break; - } + SolrClient client = jettySolrRunner.getSolrClient(); + var req = new MetricsRequest(SolrParams.of("wt", "prometheus")); + + NamedList resp = client.request(req); + try (InputStream in = (InputStream) resp.get("stream")) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + + for (String line : output.lines().toList()) { + if (line.startsWith("solr_core_indexsearcher_termstats_cache")) { + String type = extractTypeAttribute(line); + long value = extractMetricValue(line); + switch (type) { + case "lookups": + statsCacheMetrics.lookups.add(value); + break; + case "return_local": + statsCacheMetrics.returnLocalStats.add(value); + break; + case "merge_to_global": + statsCacheMetrics.mergeToGlobalStats.add(value); + break; + case "missing_global_field": + statsCacheMetrics.missingGlobalFieldStats.add(value); + break; + case "missing_global_term": + statsCacheMetrics.missingGlobalTermStats.add(value); + break; + case "receive_global": + statsCacheMetrics.receiveGlobalStats.add(value); + break; + case "retrieve": + statsCacheMetrics.retrieveStats.add(value); + break; + case "send_global": + statsCacheMetrics.sendGlobalStats.add(value); + break; + case "use_cached_global": + statsCacheMetrics.useCachedGlobalStats.add(value); + break; } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java index cd95b51aa38d..cedc2927c737 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPhrasesIdentificationComponent.java @@ -27,7 +27,6 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -81,10 +80,7 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(COLLECTION_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add( - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(jetty.newSolrClient(COLLECTION_NAME)); } // index some docs... diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java index 833b524167a4..848d88fc2b6b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPseudoReturnFields.java @@ -35,7 +35,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest.Field; import org.apache.solr.client.solrj.response.QueryResponse; @@ -98,10 +97,7 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(COLLECTION_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add( - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(jetty.newSolrClient(COLLECTION_NAME)); } assertEquals( diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java index 2f37f61683d9..b1962539f186 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudRecovery2.java @@ -18,7 +18,6 @@ package org.apache.solr.cloud; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -50,8 +49,8 @@ public static void setupCluster() throws Exception { public void test() throws Exception { JettySolrRunner node1 = cluster.getJettySolrRunner(0); JettySolrRunner node2 = cluster.getJettySolrRunner(1); - try (SolrClient client1 = - new HttpJettySolrClient.Builder(node1.getBaseUrl().toString()).build()) { + { + SolrClient client1 = node1.getSolrClient(); node2.stop(); waitForState("", COLLECTION, (liveNodes, collectionState) -> liveNodes.size() == 1); @@ -65,10 +64,10 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = - new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { + { long numFound = - client + node2 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "*:*", "distrib", "false")) .getResults() .getNumFound(); @@ -83,10 +82,10 @@ public void test() throws Exception { new UpdateRequest().add("id", "1", "num", "10").commit(client1, COLLECTION); - try (SolrClient client = - new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { + { Object v = - client + node2 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) .getResults() .get(0) @@ -116,10 +115,10 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = - new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { + { v = - client + node2 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) .getResults() .get(0) @@ -142,10 +141,10 @@ public void test() throws Exception { node2.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = - new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { + { v = - client + node2 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) .getResults() .get(0) @@ -172,20 +171,20 @@ public void test() throws Exception { node1.start(); waitForState("", COLLECTION, clusterShape(1, 2)); - try (SolrClient client = - new HttpJettySolrClient.Builder(node1.getBaseUrl().toString()).build()) { + { Object v = - client + node1 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) .getResults() .get(0) .get("num"); assertEquals("30", v.toString()); } - try (SolrClient client = - new HttpJettySolrClient.Builder(node2.getBaseUrl().toString()).build()) { + { Object v = - client + node2 + .getSolrClient() .query(COLLECTION, new SolrQuery("q", "id:1", "distrib", "false")) .getResults() .get(0) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java index 58ccc9ed26cf..e66c9fc2b7a9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -20,7 +20,6 @@ import java.util.Map; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -84,43 +83,33 @@ public void testQueryToDownCollectionShouldFailFast() throws Exception { new QueryRequest(new SolrQuery("*:*").setRows(0)) .setBasicAuthCredentials(USERNAME, PASSWORD); - try (SolrClient client = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - // Without the SOLR-13793 fix, this causes requests to "down collection" to pile up (until the - // nodes run out of serviceable threads, and they crash, even for other collections hosted on - // the - // nodes). - SolrException error = - expectThrows( - SolrException.class, - "Request should fail after trying all replica nodes once", - () -> client.request(req, COLLECTION_NAME)); - - assertEquals(error.code(), SolrException.ErrorCode.INVALID_STATE.code); - assertTrue( - error - .getMessage() - .contains("No active replicas found for collection: " + COLLECTION_NAME)); - } + SolrClient client = cluster.getJettySolrRunner(0).getSolrClient(); + // Without the SOLR-13793 fix, this causes requests to "down collection" to pile up (until the + // nodes run out of serviceable threads, and they crash, even for other collections hosted on + // the + // nodes). + SolrException error = + expectThrows( + SolrException.class, + "Request should fail after trying all replica nodes once", + () -> client.request(req, COLLECTION_NAME)); + + assertEquals(error.code(), SolrException.ErrorCode.INVALID_STATE.code); + assertTrue( + error.getMessage().contains("No active replicas found for collection: " + COLLECTION_NAME)); // run same set of tests on v2 client which uses V2HttpCall - try (SolrClient v2Client = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - - SolrException error = - expectThrows( - SolrException.class, - "Request should fail after trying all replica nodes once", - () -> v2Client.request(req, COLLECTION_NAME)); - - assertEquals(error.code(), SolrException.ErrorCode.INVALID_STATE.code); - assertTrue( - error - .getMessage() - .contains("No active replicas found for collection: " + COLLECTION_NAME)); - } + SolrClient v2Client = cluster.getJettySolrRunner(0).getSolrClient(); + + error = + expectThrows( + SolrException.class, + "Request should fail after trying all replica nodes once", + () -> v2Client.request(req, COLLECTION_NAME)); + + assertEquals(error.code(), SolrException.ErrorCode.INVALID_STATE.code); + assertTrue( + error.getMessage().contains("No active replicas found for collection: " + COLLECTION_NAME)); } @SuppressWarnings({"unchecked"}) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java index 55f173584a95..b181eaa7cb36 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplayVsRecovery.java @@ -32,7 +32,6 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.response.RequestStatusState; @@ -244,12 +243,10 @@ private void addDocs(final boolean commit, final int numDocs, final int startId) } // For simplicity, we always add out docs directly to NODE0 // (where the leader should be) and bypass the proxy... - try (SolrClient client = - new HttpJettySolrClient.Builder(NODE0.getBaseUrl().toString()).build()) { - assertEquals(0, client.add(COLLECTION, docs).getStatus()); - if (commit) { - assertEquals(0, client.commit(COLLECTION).getStatus()); - } + SolrClient client = NODE0.getSolrClient(); + assertEquals(0, client.add(COLLECTION, docs).getStatus()); + if (commit) { + assertEquals(0, client.commit(COLLECTION).getStatus()); } } @@ -258,15 +255,12 @@ private void addDocs(final boolean commit, final int numDocs, final int startId) * (inclusive) can be found on both the leader and the replica */ private void assertDocsExistInBothReplicas(int firstDocId, int lastDocId) throws Exception { - try (SolrClient leaderSolr = - new HttpJettySolrClient.Builder(NODE0.getBaseUrl().toString()).build(); - SolrClient replicaSolr = - new HttpJettySolrClient.Builder(NODE1.getBaseUrl().toString()).build()) { - for (int d = firstDocId; d <= lastDocId; d++) { - String docId = String.valueOf(d); - assertDocExists("leader", leaderSolr, docId); - assertDocExists("replica", replicaSolr, docId); - } + SolrClient leaderSolr = NODE0.getSolrClient(); + SolrClient replicaSolr = NODE1.getSolrClient(); + for (int d = firstDocId; d <= lastDocId; d++) { + String docId = String.valueOf(d); + assertDocExists("leader", leaderSolr, docId); + assertDocExists("replica", replicaSolr, docId); } } 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 635a19049580..f9d581407745 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -903,11 +903,9 @@ public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception { updates.add(simulatedDBQ("inplace_updatable_int:5", 3L)); updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L)); for (JettySolrRunner solrRunner : getSolrRunner(false)) { - try (SolrClient client = - new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { - for (UpdateRequest up : updates) { - up.process(client, collectionName); - } + SolrClient client = solrRunner.getSolrClient(); + for (UpdateRequest up : updates) { + up.process(client, collectionName); } } JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0); @@ -1146,18 +1144,16 @@ private List getSolrCore(boolean isLeader) { private void checkRTG(int from, int to, List solrRunners) throws Exception { for (JettySolrRunner solrRunner : solrRunners) { - try (SolrClient client = - new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) { - for (int i = from; i <= to; i++) { - SolrQuery query = new SolrQuery(); - query.set("distrib", false); - query.setRequestHandler("/get"); - query.set("id", i); - QueryResponse res = client.query(collectionName, query); - assertNotNull( - "Can not find doc " + i + " in " + solrRunner.getBaseUrl(), - res.getResponse().get("doc")); - } + SolrClient client = solrRunner.getSolrClient(); + for (int i = from; i <= to; i++) { + SolrQuery query = new SolrQuery(); + query.set("distrib", false); + query.setRequestHandler("/get"); + query.set("id", i); + QueryResponse res = client.query(collectionName, query); + assertNotNull( + "Can not find doc " + i + " in " + solrRunner.getBaseUrl(), + res.getResponse().get("doc")); } } } diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java index 33ab744012b3..269e3ee65f8a 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java @@ -98,14 +98,11 @@ public void testBackupRestore() throws Exception { String commitName = TestUtil.randomSimpleString(random(), 1, 5); String duplicateName = commitName.concat("_duplicate"); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder( - cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) - .build(); - SolrClient leaderClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { + SolrClient adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); // Create another snapshot referring to the same index commit to verify the @@ -194,14 +191,11 @@ public void testIndexOptimization() throws Exception { String coreName = replica.getStr(ZkStateReader.CORE_NAME_PROP); String commitName = TestUtil.randomSimpleString(random(), 1, 5); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder( - cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) - .build(); - SolrClient leaderClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { + SolrClient adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); + try (SolrClient leaderClient = + new HttpJettySolrClient.Builder(replica.getBaseUrl()) + .withDefaultCollection(replica.getCoreName()) + .build()) { SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); diff --git a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java index 3096e9a05a7c..133116e6908b 100644 --- a/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java +++ b/solr/core/src/test/org/apache/solr/filestore/TestDistribFileStore.java @@ -36,7 +36,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.FileStoreApi; import org.apache.solr.client.solrj.request.V2Request; import org.apache.solr.client.solrj.response.SimpleSolrResponse; @@ -174,19 +173,17 @@ public void testFileStoreManagement() throws Exception { for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) { final var fetchReq = new FileStoreApi.FetchFile("/package/mypkg/v1.0/runtimelibs.jar2"); fetchReq.setGetFrom("someFakeSolrNode:8983_solr"); - try (final var solrClient = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - final var expectedExc = - expectThrows( - RemoteSolrException.class, - () -> { - fetchReq.process(solrClient); - }); - assertEquals(400, expectedExc.code()); - assertThat( - expectedExc.getMessage(), containsString("File store cannot fetch from source node")); - assertThat(expectedExc.getMessage(), containsString("does not appear in live-nodes")); - } + final var solrClient = jettySolrRunner.getSolrClient(); + final var expectedExc = + expectThrows( + RemoteSolrException.class, + () -> { + fetchReq.process(solrClient); + }); + assertEquals(400, expectedExc.code()); + assertThat( + expectedExc.getMessage(), containsString("File store cannot fetch from source node")); + assertThat(expectedExc.getMessage(), containsString("does not appear in live-nodes")); } // Delete Jars 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 f197a3c117eb..0a0d3d926345 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -53,7 +53,6 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoresApi; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -237,14 +236,13 @@ private void reloadCore(JettySolrRunner jettySolrRunner, String core) throws Exc new GenericSolrRequest( SolrRequest.METHOD.POST, "/admin/cores", SolrRequestType.ADMIN, params); - try (SolrClient adminClient = adminClient(jettySolrRunner)) { - NamedList res = adminClient.request(req); - assertNotNull("null response from server", res); - } + SolrClient adminClient = adminClient(jettySolrRunner); + NamedList res = adminClient.request(req); + assertNotNull("null response from server", res); } private SolrClient adminClient(JettySolrRunner client) { - return new HttpJettySolrClient.Builder(client.getBaseUrl().toString()).build(); + return client.getSolrClient(); } @Test @@ -1660,33 +1658,32 @@ private Date watchCoreStartAt(JettySolrRunner jettySolrRunner, final Date min) final long sleepInterval = 200; long timeSlept = 0; - try (SolrClient adminClient = adminClient(jettySolrRunner)) { - final var statusRequest = new CoresApi.GetCoreStatus("collection1"); - while (timeSlept < TIMEOUT) { - try { - final var statusResponse = statusRequest.process(adminClient); - assertNotNull(statusResponse.status); - assertTrue(statusResponse.status.containsKey("collection1")); - final var coreStatus = statusResponse.status.get("collection1"); - Date startTime = coreStatus.startTime; - - assertNotNull("core has null startTime", startTime); - if (null == min || startTime.after(min)) { - return startTime; - } - } catch (SolrException e) { - // workaround for SOLR-4668 - if (500 != e.code()) { - throw e; - } // else server possibly from the core reload in progress... + SolrClient adminClient = adminClient(jettySolrRunner); + final var statusRequest = new CoresApi.GetCoreStatus("collection1"); + while (timeSlept < TIMEOUT) { + try { + final var statusResponse = statusRequest.process(adminClient); + assertNotNull(statusResponse.status); + assertTrue(statusResponse.status.containsKey("collection1")); + final var coreStatus = statusResponse.status.get("collection1"); + Date startTime = coreStatus.startTime; + + assertNotNull("core has null startTime", startTime); + if (null == min || startTime.after(min)) { + return startTime; } - - timeSlept += sleepInterval; - Thread.sleep(sleepInterval); + } catch (SolrException e) { + // workaround for SOLR-4668 + if (500 != e.code()) { + throw e; + } // else server possibly from the core reload in progress... } - fail("timed out waiting for collection1 startAt time to exceed: " + min); - return min; // compilation necessity + + timeSlept += sleepInterval; + Thread.sleep(sleepInterval); } + fail("timed out waiting for collection1 startAt time to exceed: " + min); + return min; // compilation necessity } @Test 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 aad31ef2626e..0bfbe1f2b019 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java @@ -63,10 +63,7 @@ public void beforeTest() throws Exception { (CollectionAdminRequest.createCollection(DEFAULT_TEST_COLLECTION_NAME, "conf1", 1, 1) .process(cluster.getSolrClient()) .getStatus())); - adminClient = - new HttpJettySolrClient.Builder( - cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) - .build(); + adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); initCoreNameAndSolrCoreClient(); } @@ -95,9 +92,6 @@ public void afterTest() throws Exception { // we use a clean cluster instance for every test, so we need to clean it up shutdownCluster(); - if (null != adminClient) { - adminClient.close(); - } if (null != coreClient) { coreClient.close(); } 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 c92edb046746..acb4bd15701d 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java @@ -97,10 +97,7 @@ public void beforeTest() throws Exception { (CollectionAdminRequest.createCollection(DEFAULT_TEST_COLLECTION_NAME, "conf1", 1, 1) .process(cluster.getSolrClient()) .getStatus())); - adminClient = - new HttpJettySolrClient.Builder( - cluster.getJettySolrRunners().get(0).getBaseUrl().toString()) - .build(); + adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); initCoreNameAndSolrCoreClient(); } @@ -109,9 +106,6 @@ public void afterTest() throws Exception { // we use a clean cluster instance for every test, so we need to clean it up shutdownCluster(); - if (null != adminClient) { - adminClient.close(); - } if (null != coreClient) { coreClient.close(); } 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 7b6890360122..eea04fe3c7e2 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 @@ -34,7 +34,6 @@ import org.apache.solr.client.api.model.CoreStatusResponse; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.json.JacksonContentWriter; @@ -419,13 +418,11 @@ public void testDeleteInstanceDirAfterCreateFailure() throws Exception { runner.getSolrClient().commit("corex"); Path dataDir = null; - try (SolrClient client = - new HttpJettySolrClient.Builder(runner.getBaseUrl().toString()).build()) { - final var status = CoreAdminRequest.getCoreStatus("corex", true, client); - String dataDirectory = status.dataDir; - dataDir = Path.of(dataDirectory); - assertTrue(Files.exists(dataDir)); - } + SolrClient client = runner.getSolrClient(); + final var status = CoreAdminRequest.getCoreStatus("corex", true, client); + String dataDirectory = status.dataDir; + dataDir = Path.of(dataDirectory); + assertTrue(Files.exists(dataDir)); Path subHome = solrHomeDirectory.resolve("corex").resolve("conf"); Path top = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf"); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java index a839d10ccbcd..4fadec44fef9 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java @@ -29,7 +29,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.HealthCheckRequest; @@ -75,16 +74,13 @@ public void testHealthCheckHandler() throws Exception { genericHealthcheck.process(cluster.getSolrClient()).getResponse().get(CommonParams.STATUS)); // positive check that our exiting "healthy" node works with direct http client - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); - } + assertEquals( + CommonParams.OK, + runHealthcheckWithClient(cluster.getJettySolrRunner(0).getSolrClient()).getNodeStatus()); // successfully create a dummy collection - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { + try { + SolrClient solrClient = cluster.getJettySolrRunner(0).getSolrClient(); CollectionAdminResponse collectionAdminResponse = CollectionAdminRequest.createCollection("test", "_default", 1, 1) .withProperty("solr.directoryFactory", "solr.StandardDirectoryFactory") @@ -98,8 +94,8 @@ public void testHealthCheckHandler() throws Exception { // add a new node for the purpose of negative testing JettySolrRunner newJetty = cluster.startJettySolrRunner(); - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(newJetty.getBaseUrl().toString()).build()) { + try { + SolrClient solrClient = newJetty.getSolrClient(); // positive check that our (new) "healthy" node works with direct http client final var response = runHealthcheckWithClient(solrClient); @@ -119,24 +115,17 @@ public void testHealthCheckHandler() throws Exception { // (redundant) positive check that our (previously) exiting "healthy" node (still) works // after getting negative results from our broken node and failed core container - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - - assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); - } + assertEquals( + CommonParams.OK, + runHealthcheckWithClient(cluster.getJettySolrRunner(0).getSolrClient()).getNodeStatus()); } @Test public void testHealthCheckHandlerSolrJ() throws IOException, SolrServerException { // positive check of a HealthCheckRequest using http client HealthCheckRequest req = new HealthCheckRequest(); - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - HealthCheckResponse rsp = req.process(solrClient); - assertEquals(CommonParams.OK, rsp.getNodeStatus()); - } + HealthCheckResponse rsp = req.process(cluster.getJettySolrRunner(0).getSolrClient()); + assertEquals(CommonParams.OK, rsp.getNodeStatus()); } /** @@ -154,10 +143,10 @@ public void testHealthCheckHandlerSolrJ() throws IOException, SolrServerExceptio @Test public void testV1FailureResponseIncludesStatusField() throws Exception { JettySolrRunner newJetty = cluster.startJettySolrRunner(); - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(newJetty.getBaseUrl().toString()).build()) { + try { // Sanity check: the new node is initially healthy. - assertEquals(CommonParams.OK, runHealthcheckWithClient(solrClient).getNodeStatus()); + assertEquals( + CommonParams.OK, runHealthcheckWithClient(newJetty.getSolrClient()).getNodeStatus()); String nodeName = newJetty.getCoreContainer().getZkController().getNodeName(); diff --git a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java index 7a9a65360f65..78120c4ed553 100644 --- a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java @@ -27,7 +27,6 @@ import java.util.Set; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.cloud.MiniSolrCloudCluster; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.NodeConfig; @@ -124,32 +123,30 @@ public void testZkMetrics() throws Exception { reader, "solr_zk_ops", baseLabels.merge(Labels.of("ops", type)))); } - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(j.getBaseUrl().toString()).build()) { - assertNotNull(solrClient); - HttpClient httpClient = j.getSolrClient().getHttpClient(); - var initialChildFetches = - SolrMetricTestUtils.getCounterDatapoint(reader, "solr_zk_get_children_ops", baseLabels) - .getValue(); - var initialExistsOp = - SolrMetricTestUtils.getCounterDatapoint( - reader, "solr_zk_ops", baseLabels.merge(Labels.of("ops", "exists"))) - .getValue(); + SolrClient solrClient = j.getSolrClient(); + assertNotNull(solrClient); + HttpClient httpClient = j.getSolrClient().getHttpClient(); + var initialChildFetches = + SolrMetricTestUtils.getCounterDatapoint(reader, "solr_zk_get_children_ops", baseLabels) + .getValue(); + var initialExistsOp = + SolrMetricTestUtils.getCounterDatapoint( + reader, "solr_zk_ops", baseLabels.merge(Labels.of("ops", "exists"))) + .getValue(); - // Send GET request to trigger some metrics - httpClient.GET(j.getBaseURLV2() + "/cluster/zookeeper/children/live_nodes"); + // Send GET request to trigger some metrics + httpClient.GET(j.getBaseURLV2() + "/cluster/zookeeper/children/live_nodes"); - var childFetches = - SolrMetricTestUtils.getCounterDatapoint(reader, "solr_zk_get_children_ops", baseLabels) - .getValue(); - var existsOp = - SolrMetricTestUtils.getCounterDatapoint( - reader, "solr_zk_ops", builder.label("ops", "exists").build()) - .getValue(); + var childFetches = + SolrMetricTestUtils.getCounterDatapoint(reader, "solr_zk_get_children_ops", baseLabels) + .getValue(); + var existsOp = + SolrMetricTestUtils.getCounterDatapoint( + reader, "solr_zk_ops", builder.label("ops", "exists").build()) + .getValue(); - assertTrue(childFetches - initialChildFetches >= 1.0); - assertTrue(existsOp - initialExistsOp >= 4.0); - } + assertTrue(childFetches - initialChildFetches >= 1.0); + assertTrue(existsOp - initialExistsOp >= 4.0); cluster.shutdown(); } diff --git a/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java index a59b39daf495..1fff683d95ae 100644 --- a/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java +++ b/solr/core/src/test/org/apache/solr/response/TestRawTransformer.java @@ -26,7 +26,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.InputStreamResponseParser; @@ -63,13 +62,13 @@ public static void beforeClass() throws Exception { initStandalone(); JSR.start(); if (random().nextBoolean()) { - CLIENT = new HttpJettySolrClient.Builder(JSR.getBaseUrl().toString()).build(); + CLIENT = JSR.getSolrClient(); } else { CLIENT = new EmbeddedSolrServer(JSR.getCoreContainer(), null); } } else { initCloud(); - CLIENT = new HttpJettySolrClient.Builder(JSR.getBaseUrl().toString()).build(); + CLIENT = JSR.getSolrClient(); JSR = null; } initIndex(); diff --git a/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java b/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java index 3d235e40d962..bd75970eca20 100644 --- a/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java +++ b/solr/core/src/test/org/apache/solr/schema/ManagedSchemaRoundRobinCloudTest.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest; import org.apache.solr.client.solrj.response.schema.SchemaResponse; @@ -56,25 +55,16 @@ public static void setupCluster() throws Exception { @Test public void testAddFieldsRoundRobin() throws Exception { List clients = new ArrayList<>(NUM_SHARDS); - try { - for (int shardNum = 0; shardNum < NUM_SHARDS; ++shardNum) { - clients.add( - new HttpJettySolrClient.Builder( - cluster.getJettySolrRunners().get(shardNum).getBaseUrl().toString()) - .build()); - } - int shardNum = 0; - for (int fieldNum = 0; fieldNum < NUM_FIELDS_TO_ADD; ++fieldNum) { - addField( - clients.get(shardNum), - keyValueArrayToMap("name", FIELD_PREFIX + fieldNum, "type", "string")); - if (++shardNum == NUM_SHARDS) { - shardNum = 0; - } - } - } finally { - for (int shardNum = 0; shardNum < NUM_SHARDS; ++shardNum) { - clients.get(shardNum).close(); + for (int shardNum = 0; shardNum < NUM_SHARDS; ++shardNum) { + clients.add(cluster.getJettySolrRunners().get(shardNum).getSolrClient()); + } + int shardNum = 0; + for (int fieldNum = 0; fieldNum < NUM_FIELDS_TO_ADD; ++fieldNum) { + addField( + clients.get(shardNum), + keyValueArrayToMap("name", FIELD_PREFIX + fieldNum, "type", "string")); + if (++shardNum == NUM_SHARDS) { + shardNum = 0; } } } diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java index 9a641323d5ef..6983c096e734 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java +++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java @@ -219,8 +219,8 @@ public void testNRTRestart() throws Exception { } assertNotNull(nrtJetty); assertNotNull(pullJetty); - try (SolrClient client = - new HttpJettySolrClient.Builder(pullJetty.getBaseUrl().toString()).build()) { + { + SolrClient client = pullJetty.getSolrClient(); client.add(COLL, sid); client.commit(COLL); assertEquals( diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java index c993c4a49013..eb205f2bddff 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetJoinDomain.java @@ -31,7 +31,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -124,10 +123,7 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) - CLIENTS.add( - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(jetty.newSolrClient(COLLECTION_NAME)); final int numDocs = atLeast(100); for (int id = 0; id < numDocs; id++) { diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java index 53b44f60af36..6092fa811373 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKG.java @@ -34,7 +34,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -151,10 +150,7 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add( - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(jetty.newSolrClient(COLLECTION_NAME)); } final int numDocs = atLeast(100); diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java index a5952bd235ee..5446cea09453 100644 --- a/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java +++ b/solr/core/src/test/org/apache/solr/search/facet/TestCloudJSONFacetSKGEquiv.java @@ -37,7 +37,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -143,10 +142,7 @@ public static void createMiniSolrCloudCluster() throws Exception { waitForRecoveriesToFinish(CLOUD_CLIENT); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - CLIENTS.add( - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(jetty.newSolrClient(COLLECTION_NAME)); } final int numDocs = atLeast(100); diff --git a/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java b/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java index a7b39837c590..0522942543c4 100644 --- a/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java +++ b/solr/core/src/test/org/apache/solr/search/stats/TestDistribIDF.java @@ -22,7 +22,6 @@ 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.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -109,35 +108,31 @@ public void testSimpleQuery() throws Exception { // Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - try (SolrClient solrClient_local = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - - SolrQuery query = new SolrQuery("cat:football"); - query.setFields("*,score"); - QueryResponse queryResponse = solrClient.query("onecollection", query); - assertEquals(2, queryResponse.getResults().getNumFound()); - float score1 = (float) queryResponse.getResults().get(0).get("score"); - float score2 = (float) queryResponse.getResults().get(1).get("score"); - assertEquals( - "Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2)); - - query = new SolrQuery("cat:football"); - query.setShowDebugInfo(true); - query.setFields("*,score"); - queryResponse = solrClient_local.query("onecollection_local", query); - assertEquals(2, queryResponse.getResults().getNumFound()); - assertEquals("2", queryResponse.getResults().get(0).get("id")); - assertEquals("1", queryResponse.getResults().get(1).get("id")); - float score1_local = (float) queryResponse.getResults().get(0).get("score"); - float score2_local = (float) queryResponse.getResults().get(1).get("score"); - assertEquals( - "Doc1 score=" + score1_local + " Doc2 score=" + score2_local, - 1, - Float.compare(score1_local, score2_local)); - } - } + SolrClient solrClient = jettySolrRunner.getSolrClient(); + SolrClient solrClient_local = jettySolrRunner.getSolrClient(); + + SolrQuery query = new SolrQuery("cat:football"); + query.setFields("*,score"); + QueryResponse queryResponse = solrClient.query("onecollection", query); + assertEquals(2, queryResponse.getResults().getNumFound()); + float score1 = (float) queryResponse.getResults().get(0).get("score"); + float score2 = (float) queryResponse.getResults().get(1).get("score"); + assertEquals( + "Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2)); + + query = new SolrQuery("cat:football"); + query.setShowDebugInfo(true); + query.setFields("*,score"); + queryResponse = solrClient_local.query("onecollection_local", query); + assertEquals(2, queryResponse.getResults().getNumFound()); + assertEquals("2", queryResponse.getResults().get(0).get("id")); + assertEquals("1", queryResponse.getResults().get(1).get("id")); + float score1_local = (float) queryResponse.getResults().get(0).get("score"); + float score2_local = (float) queryResponse.getResults().get(1).get("score"); + assertEquals( + "Doc1 score=" + score1_local + " Doc2 score=" + score2_local, + 1, + Float.compare(score1_local, score2_local)); } } @@ -161,35 +156,30 @@ public void testMultiCollectionQuery() throws Exception { // Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - - try (SolrClient solrClient_local = - new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()) { - SolrQuery query = new SolrQuery("cat:football"); - query.setFields("*,score").add("collection", "collection1,collection2"); - QueryResponse queryResponse = solrClient.query("collection1", query); - assertEquals(2, queryResponse.getResults().getNumFound()); - float score1 = (float) queryResponse.getResults().get(0).get("score"); - float score2 = (float) queryResponse.getResults().get(1).get("score"); - assertEquals( - "Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2)); - - query = new SolrQuery("cat:football"); - query.setFields("*,score").add("collection", "collection1_local,collection2_local"); - queryResponse = solrClient_local.query("collection1_local", query); - assertEquals(2, queryResponse.getResults().getNumFound()); - assertEquals("2", queryResponse.getResults().get(0).get("id")); - assertEquals("1", queryResponse.getResults().get(1).get("id")); - float score1_local = (float) queryResponse.getResults().get(0).get("score"); - float score2_local = (float) queryResponse.getResults().get(1).get("score"); - assertEquals( - "Doc1 score=" + score1_local + " Doc2 score=" + score2_local, - 1, - Float.compare(score1_local, score2_local)); - } - } + SolrClient solrClient = jettySolrRunner.getSolrClient(); + SolrClient solrClient_local = jettySolrRunner.getSolrClient(); + + SolrQuery query = new SolrQuery("cat:football"); + query.setFields("*,score").add("collection", "collection1,collection2"); + QueryResponse queryResponse = solrClient.query("collection1", query); + assertEquals(2, queryResponse.getResults().getNumFound()); + float score1 = (float) queryResponse.getResults().get(0).get("score"); + float score2 = (float) queryResponse.getResults().get(1).get("score"); + assertEquals( + "Doc1 score=" + score1 + " Doc2 score=" + score2, 0, Float.compare(score1, score2)); + + query = new SolrQuery("cat:football"); + query.setFields("*,score").add("collection", "collection1_local,collection2_local"); + queryResponse = solrClient_local.query("collection1_local", query); + assertEquals(2, queryResponse.getResults().getNumFound()); + assertEquals("2", queryResponse.getResults().get(0).get("id")); + assertEquals("1", queryResponse.getResults().get(1).get("id")); + float score1_local = (float) queryResponse.getResults().get(0).get("score"); + float score2_local = (float) queryResponse.getResults().get(1).get("score"); + assertEquals( + "Doc1 score=" + score1_local + " Doc2 score=" + score2_local, + 1, + Float.compare(score1_local, score2_local)); } } diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index 3666befc374b..7049410f7096 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -248,8 +248,7 @@ public void testBasicAuth() throws Exception { // Test for SOLR-12514. Create a new jetty . This jetty does not have the collection. // Make a request to that jetty and it should fail JettySolrRunner aNewJetty = cluster.startJettySolrRunner(); - SolrClient aNewClient = - new HttpJettySolrClient.Builder(aNewJetty.getBaseUrl().toString()).build(); + SolrClient aNewClient = aNewJetty.getSolrClient(); UpdateRequest delQuery = null; delQuery = new UpdateRequest().deleteByQuery("*:*"); delQuery.setBasicAuthCredentials("harry", "HarryIsUberCool"); @@ -263,7 +262,6 @@ public void testBasicAuth() throws Exception { }); assertEquals(401, e.code()); // Authentication failed } finally { - aNewClient.close(); cluster.stopJettySolrRunner(aNewJetty); } diff --git a/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java b/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java index c4e03ae5b25f..5c8b2f140437 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java +++ b/solr/core/src/test/org/apache/solr/update/processor/TestCloudDeduplication.java @@ -21,7 +21,6 @@ import java.util.List; import org.apache.lucene.util.IOUtils; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.json.JsonQueryRequest; @@ -60,7 +59,7 @@ public static void setupCluster() throws Exception { CLIENTS.add(cluster.getSolrClient()); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - final SolrClient c = new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build(); + final SolrClient c = jetty.getSolrClient(); NODE_CLIENTS.add(c); CLIENTS.add(c); } diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java index eab18b6b9937..1707bc9f2a3e 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiCoreAdminStandaloneTest.java @@ -18,7 +18,6 @@ import java.nio.file.Path; import java.util.Map; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; @@ -96,13 +95,11 @@ public void testRenameCoreViaUi() throws Exception { @Test public void testSwapCoresViaUi() throws Exception { // make the cores distinguishable: swapa gets one document, swapb stays empty - try (var client = - new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { - var doc = new SolrInputDocument(); - doc.addField("id", "swap-doc"); - client.add("swapa", doc); - client.commit("swapa"); - } + var client = standaloneJetty.getSolrClient(); + var doc = new SolrInputDocument(); + doc.addField("id", "swap-doc"); + client.add("swapa", doc); + client.commit("swapa"); assertEquals(1, numDocs("swapa")); assertEquals(0, numDocs("swapb")); @@ -138,9 +135,12 @@ private boolean coreExists(String coreName) { } private long numDocs(String coreName) { - try (var client = - new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { - return client.query(coreName, new SolrQuery("*:*")).getResults().getNumFound(); + try { + return standaloneJetty + .getSolrClient() + .query(coreName, new SolrQuery("*:*")) + .getResults() + .getNumFound(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java index e052b826e394..08b9d18e6f15 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiQueryScreenTest.java @@ -18,7 +18,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.common.SolrInputDocument; @@ -94,11 +93,7 @@ public void testParamsetDropdown() throws Exception { setParams.setContentWriter( new RequestWriter.StringPayloadContentWriter( "{\"set\":{\"" + paramset + "\":{\"rows\":\"2\"}}}", CommonParams.JSON_MIME)); - try (SolrClient client = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { - client.request(setParams); - } + cluster.getJettySolrRunner(0).getSolrClient().request(setParams); openPage(COLLECTION + "/query", By.id("query")); chosenSelect("useParams", paramset); diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java index 636724854812..3fe1cf6891c3 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiReplicationStandaloneTest.java @@ -21,7 +21,6 @@ import java.nio.file.Path; import java.util.List; import java.util.Properties; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.util.NamedList; @@ -91,16 +90,14 @@ public void testReplicationScreenAndActions() throws Exception { "polling should be disabled", () -> "true".equals(followerDetail("isPollingDisabled"))); // index documents on the leader; the follower does not poll them - try (var client = - new HttpJettySolrClient.Builder(leaderJetty.getBaseUrl().toString()).build()) { - for (int i = 1; i <= 2; i++) { - SolrInputDocument doc = new SolrInputDocument(); - doc.addField("id", "repl-doc-" + i); - doc.addField("name", "replicated"); - client.add(CORE, doc); - } - client.commit(CORE); + var client = leaderJetty.getSolrClient(); + for (int i = 1; i <= 2; i++) { + SolrInputDocument doc = new SolrInputDocument(); + doc.addField("id", "repl-doc-" + i); + doc.addField("name", "replicated"); + client.add(CORE, doc); } + client.commit(CORE); // replicate on demand and watch the docs arrive on the follower click(By.cssSelector("#replication button.replicate-now")); @@ -152,9 +149,12 @@ private String followerDetail(String key) { } private long followerNumDocs() { - try (var client = - new HttpJettySolrClient.Builder(standaloneJetty.getBaseUrl().toString()).build()) { - return client.query(CORE, new SolrQuery("*:*")).getResults().getNumFound(); + try { + return standaloneJetty + .getSolrClient() + .query(CORE, new SolrQuery("*:*")) + .getResults() + .getNumFound(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java index 250807a62dc8..f50ae1e915f0 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java @@ -18,9 +18,7 @@ import java.util.List; import java.util.Map; -import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.util.NamedList; import org.junit.BeforeClass; @@ -140,13 +138,11 @@ public void testLoginAndSecurityScreen() throws Exception { /** Returns the authorization config as fetched with credentials. */ private NamedList authorizationApi() { - try (SolrClient client = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { + try { GenericSolrRequest req = new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/authorization", params()); req.setBasicAuthCredentials(USER, PASS); - return client.request(req); + return cluster.getJettySolrRunner(0).getSolrClient().request(req); } catch (Exception e) { throw new RuntimeException(e); } @@ -166,13 +162,11 @@ private String permissionRole(String permission) { /** Checks via the authentication API (with credentials) whether the user exists. */ private boolean userExists(String user) { - try (SolrClient client = - new HttpJettySolrClient.Builder(cluster.getJettySolrRunner(0).getBaseUrl().toString()) - .build()) { + try { GenericSolrRequest req = new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/authentication", params()); req.setBasicAuthCredentials(USER, PASS); - NamedList response = client.request(req); + NamedList response = cluster.getJettySolrRunner(0).getSolrClient().request(req); Map authentication = (Map) response.get("authentication"); Map credentials = (Map) authentication.get("credentials"); return credentials.containsKey(user); diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java index 476aeef6e6aa..5a007b2f501d 100644 --- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java +++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiTestBase.java @@ -38,10 +38,8 @@ import org.apache.lucene.util.SuppressForbidden; import org.apache.solr.SolrIgnoredThreadsFilter; 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.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.SolrCloudTestCase; @@ -383,10 +381,9 @@ protected static NamedList adminApi(String path, SolrParams params) throws IOException, SolrServerException { ensureCloudCluster(); JettySolrRunner jetty = standaloneMode ? standaloneJetty : cluster.getJettySolrRunner(0); - try (SolrClient client = - new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) { - return client.request(new GenericSolrRequest(SolrRequest.METHOD.GET, path, params)); - } + return jetty + .getSolrClient() + .request(new GenericSolrRequest(SolrRequest.METHOD.GET, path, params)); } /** From 272fe025d40d3a662ba9e423128cc44c12879eae Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sun, 23 Aug 2026 10:07:32 +0300 Subject: [PATCH 05/24] SOLR-18390: also remove newClient(int, int) -- there are only 4 callers Removed the 2-arg timeout overload too, per the reviewer's follow-up: he'd rather not keep it either, and it has few callers. Migrated the 4 callers to the shared getSolrClient() rather than reconstructing a custom-timeout client: their explicit timeouts (15s conn/60s idle, 30s/300s) are all shorter than the client's own default (60s/600s), so nothing was relying on them -- the shared client's default gives at least as much headroom either way. --- .../solr/cloud/BasicDistributedZkTest.java | 114 +++++++++--------- .../solr/cloud/UnloadDistributedZkTest.java | 93 +++++++------- .../cloud/api/collections/ShardSplitTest.java | 8 +- .../apache/solr/embedded/JettySolrRunner.java | 7 -- 4 files changed, 105 insertions(+), 117 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index a78b7ad299df..116830fd0e32 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -1046,26 +1046,25 @@ private void testShardParamVariations() throws Exception { private void testStopAndStartCoresInOneInstance() throws Exception { JettySolrRunner jetty = jettys.get(0); - try (final var httpSolrClient = jetty.newClient(15000, 60000)) { - ThreadPoolExecutor executor = null; - try { - executor = - new ExecutorUtil.MDCAwareThreadPoolExecutor( - 0, - Integer.MAX_VALUE, - 5, - TimeUnit.SECONDS, - new SynchronousQueue(), - new SolrNamedThreadFactory("testExecutor")); - int cnt = 3; - - // create the cores - createCollectionInOneInstance( - httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt); - } finally { - if (executor != null) { - ExecutorUtil.shutdownAndAwaitTermination(executor); - } + var httpSolrClient = jetty.getSolrClient(); + ThreadPoolExecutor executor = null; + try { + executor = + new ExecutorUtil.MDCAwareThreadPoolExecutor( + 0, + Integer.MAX_VALUE, + 5, + TimeUnit.SECONDS, + new SynchronousQueue(), + new SolrNamedThreadFactory("testExecutor")); + int cnt = 3; + + // create the cores + createCollectionInOneInstance( + httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt); + } finally { + if (executor != null) { + ExecutorUtil.shutdownAndAwaitTermination(executor); } } @@ -1381,47 +1380,46 @@ private void testANewCollectionInOneInstanceWithManualShardAssignement() throws .getLeader("shard1"); // now test that unloading a core gets us a new leader - try (SolrClient unloadClient = jettys.getFirst().newClient(15000, 60000)) { - Unload unloadCmd = new Unload(true); - unloadCmd.setCoreName(leader.getCoreName()); - - String leaderUrl = leader.getCoreUrl(); - - testExecutor.execute( - new Runnable() { - - @Override - public void run() { - try { - unloadClient.request(unloadCmd); - } catch (SolrServerException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } + SolrClient unloadClient = jettys.getFirst().getSolrClient(); + Unload unloadCmd = new Unload(true); + unloadCmd.setCoreName(leader.getCoreName()); + + String leaderUrl = leader.getCoreUrl(); + + testExecutor.execute( + new Runnable() { + + @Override + public void run() { + try { + unloadClient.request(unloadCmd); + } catch (SolrServerException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); } - }); + } + }); - try { - ZkStateReader.from(getCommonCloudSolrClient()) - .waitForState( - oneInstanceCollection2, - 20000, - TimeUnit.MILLISECONDS, - (n, c) -> { - try { - if (leaderUrl.equals( - zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) { - return false; - } - } catch (InterruptedException e) { - throw new RuntimeException(e); + try { + ZkStateReader.from(getCommonCloudSolrClient()) + .waitForState( + oneInstanceCollection2, + 20000, + TimeUnit.MILLISECONDS, + (n, c) -> { + try { + if (leaderUrl.equals( + zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) { + return false; } - return true; - }); - } catch (TimeoutException | InterruptedException e) { - fail("Leader never changed"); - } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return true; + }); + } catch (TimeoutException | InterruptedException e) { + fail("Leader never changed"); } IOUtils.close(collectionClients); diff --git a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java index ddb1cd71acdc..753ce0a9aabf 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -388,56 +388,55 @@ private SolrClient getReplicaNodeClient(Replica replica) { private void testUnloadLotsOfCores() throws Exception { JettySolrRunner jetty = jettys.get(0); int shards = TEST_NIGHTLY ? 2 : 1; - try (final SolrClient adminClient = jetty.newClient(15000, 60000)) { - int numReplicas = atLeast(3); - ThreadPoolExecutor executor = - new ExecutorUtil.MDCAwareThreadPoolExecutor( - 0, - Integer.MAX_VALUE, - 5, - TimeUnit.SECONDS, - new SynchronousQueue<>(), - new SolrNamedThreadFactory("testExecutor")); - try { - // create the cores - BasicDistributedZkTest.createCollectionInOneInstance( - adminClient, jetty.getNodeName(), executor, "multiunload", shards, numReplicas); - } finally { - ExecutorUtil.shutdownAndAwaitTermination(executor); - } + final SolrClient adminClient = jetty.getSolrClient(); + int numReplicas = atLeast(3); + ThreadPoolExecutor executor = + new ExecutorUtil.MDCAwareThreadPoolExecutor( + 0, + Integer.MAX_VALUE, + 5, + TimeUnit.SECONDS, + new SynchronousQueue<>(), + new SolrNamedThreadFactory("testExecutor")); + try { + // create the cores + BasicDistributedZkTest.createCollectionInOneInstance( + adminClient, jetty.getNodeName(), executor, "multiunload", shards, numReplicas); + } finally { + ExecutorUtil.shutdownAndAwaitTermination(executor); + } - if (TEST_NIGHTLY == false) { - // with nightly tests, we can try doing the unloads before the creates are done - // it still works, but takes much longer since we end up waiting for a timeout - waitForRecoveriesToFinish("multiunload", false); - } + if (TEST_NIGHTLY == false) { + // with nightly tests, we can try doing the unloads before the creates are done + // it still works, but takes much longer since we end up waiting for a timeout + waitForRecoveriesToFinish("multiunload", false); + } - executor = - new ExecutorUtil.MDCAwareThreadPoolExecutor( - 0, - Integer.MAX_VALUE, - 5, - TimeUnit.SECONDS, - new SynchronousQueue<>(), - new SolrNamedThreadFactory("testExecutor")); - try { - for (int j = 0; j < numReplicas; j++) { - final int freezeJ = j; - executor.execute( - () -> { - Unload unloadCmd = new Unload(true); - unloadCmd.setCoreName("multiunload" + freezeJ); - try { - adminClient.request(unloadCmd); - } catch (SolrServerException | IOException e) { - throw new RuntimeException(e); - } - }); - Thread.sleep(random().nextInt(50)); - } - } finally { - ExecutorUtil.shutdownAndAwaitTermination(executor); + executor = + new ExecutorUtil.MDCAwareThreadPoolExecutor( + 0, + Integer.MAX_VALUE, + 5, + TimeUnit.SECONDS, + new SynchronousQueue<>(), + new SolrNamedThreadFactory("testExecutor")); + try { + for (int j = 0; j < numReplicas; j++) { + final int freezeJ = j; + executor.execute( + () -> { + Unload unloadCmd = new Unload(true); + unloadCmd.setCoreName("multiunload" + freezeJ); + try { + adminClient.request(unloadCmd); + } catch (SolrServerException | IOException e) { + throw new RuntimeException(e); + } + }); + Thread.sleep(random().nextInt(50)); } + } finally { + ExecutorUtil.shutdownAndAwaitTermination(executor); } } } 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 6ef8e9048f6d..33ebd5e09dff 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 @@ -1285,11 +1285,9 @@ protected void splitShard( new GenericSolrRequest(METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, params); JettySolrRunner jetty = shardToJetty.get(SHARD1).getFirst().jetty; - try (SolrClient baseServer = jetty.newClient(30_000, 300_000)) { - NamedList rsp = baseServer.request(request); - if (log.isInfoEnabled()) { - log.info("Shard split response: {}", Utils.toJSONString(rsp)); - } + NamedList rsp = jetty.getSolrClient().request(request); + if (log.isInfoEnabled()) { + log.info("Shard split response: {}", Utils.toJSONString(rsp)); } } diff --git a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java index f3d5112f5a5f..aea83190d9f7 100644 --- a/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java +++ b/solr/test-framework/src/java/org/apache/solr/embedded/JettySolrRunner.java @@ -785,13 +785,6 @@ public URL getProxyBaseUrl() { } } - public HttpJettySolrClient newClient(int connectionTimeoutMillis, int socketTimeoutMillis) { - return new HttpJettySolrClient.Builder(getBaseUrl().toString()) - .withConnectionTimeout(connectionTimeoutMillis, TimeUnit.MILLISECONDS) - .withIdleTimeout(socketTimeoutMillis, TimeUnit.MILLISECONDS) - .build(); - } - // -------------------------------------------------------------- // -------------------------------------------------------------- From 0455c86681a37fd85f8724762b61a79407cc1e9a Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sun, 23 Aug 2026 10:17:42 +0300 Subject: [PATCH 06/24] SOLR-18390: remove an unnecessary bare block left over from the migration No variable-name collision in the enclosing method required scoping this off from a try(...) block; de-indented instead of wrapping in a pointless bare {}. --- .../solr/search/TestCoordinatorRole.java | 420 +++++++++--------- 1 file changed, 209 insertions(+), 211 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java index 6983c096e734..45bed7f214cf 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java +++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java @@ -219,226 +219,224 @@ public void testNRTRestart() throws Exception { } assertNotNull(nrtJetty); assertNotNull(pullJetty); - { - SolrClient client = pullJetty.getSolrClient(); - client.add(COLL, sid); - client.commit(COLL); - assertEquals( - nrtCore, - getHostCoreName( - COLL, qaJettyBase, p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"))); - assertEquals( - pullCore, - getHostCoreName( - COLL, qaJettyBase, p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:PULL"))); - // Now , kill NRT jetty - JettySolrRunner nrtJettyF = nrtJetty; - JettySolrRunner pullJettyF = pullJetty; - Random r = random(); - final long establishBaselineMs = r.nextInt(1000); - final long nrtDowntimeMs = r.nextInt(10000); - // NOTE: for `pullServiceTimeMs`, it can't be super-short. This is just to simplify our - // indexing code, - // based on the fact that our indexing is based on a PULL-node client. - final long pullServiceTimeMs = 1000 + (long) r.nextInt(9000); - Future jettyManipulationFuture = - executor.submit( - () -> { - // we manipulate the jetty instances in a separate thread to more closely mimic - // the behavior we'd see irl. + SolrClient client = pullJetty.getSolrClient(); + client.add(COLL, sid); + client.commit(COLL); + assertEquals( + nrtCore, + getHostCoreName( + COLL, qaJettyBase, p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"))); + assertEquals( + pullCore, + getHostCoreName( + COLL, qaJettyBase, p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:PULL"))); + // Now , kill NRT jetty + JettySolrRunner nrtJettyF = nrtJetty; + JettySolrRunner pullJettyF = pullJetty; + Random r = random(); + final long establishBaselineMs = r.nextInt(1000); + final long nrtDowntimeMs = r.nextInt(10000); + // NOTE: for `pullServiceTimeMs`, it can't be super-short. This is just to simplify our + // indexing code, + // based on the fact that our indexing is based on a PULL-node client. + final long pullServiceTimeMs = 1000 + (long) r.nextInt(9000); + Future jettyManipulationFuture = + executor.submit( + () -> { + // we manipulate the jetty instances in a separate thread to more closely mimic + // the behavior we'd see irl. + try { + Thread.sleep(establishBaselineMs); + log.info("stopping NRT jetty ..."); + nrtJettyF.stop(); + log.info("NRT jetty stopped."); + Thread.sleep(nrtDowntimeMs); // let NRT be down for a while + log.info("restarting NRT jetty ..."); + nrtJettyF.start(true); + log.info("NRT jetty restarted."); + // once NRT is back up, we expect PULL to continue serving until the TTL on ZK + // state used for query request routing has expired (60s). But here we force a + // return to NRT by stopping the PULL replica after a brief delay ... + Thread.sleep(pullServiceTimeMs); + log.info("stopping PULL jetty ..."); + pullJettyF.stop(); + log.info("PULL jetty stopped."); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + String hostCore; + long start = new Date().getTime(); + long individualRequestStart = start; + int count = 0; + while (nrtCore.equals( + hostCore = + getHostCoreName( + COLL, + qaJettyBase, + p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT")))) { + count++; + Thread.sleep(100); + individualRequestStart = new Date().getTime(); + } + long now = new Date().getTime(); + log.info( + "phase1 NRT queries count={}, overall_duration={}, baseline_expected_overall_duration={}, switch-to-pull_duration={}", + count, + now - start, + establishBaselineMs, + now - individualRequestStart); + // default tolerance of 500ms below should suffice. Failover to PULL for this case should be + // very fast, because our QA-based client already knows both replicas are active, the index + // is stable, so the moment the client finds NRT is down it should be able to failover + // immediately and transparently to PULL. + assertEquals( + "when we break out of the NRT query loop, should be b/c routed to PULL", + pullCore, + hostCore); + SolrInputDocument d = new SolrInputDocument(); + d.addField("id", "345"); + d.addField("desc_s", "Another Document"); + // attempts to add another doc while NRT is down should fail, then eventually succeed when + // NRT comes back up + count = 0; + start = new Date().getTime(); + individualRequestStart = start; + for (; ; ) { + try { + client.add(COLL, d); + client.commit(COLL); + break; + } catch (SolrException ex) { + // we expect these until nrtJetty is back up. + count++; + Thread.sleep(100); + } + individualRequestStart = new Date().getTime(); + } + now = new Date().getTime(); + log.info( + "successfully added another doc; duration: {}, overall_duration={}, baseline_expected_overall_duration={}, exception_count={}", + now - individualRequestStart, + now - start, + nrtDowntimeMs, + count); + // NRT replica is back up, registered as available with Zk, and availability info has been + // pulled down by our PULL-replica-based `client`, forwarded indexing command to NRT, + // index/commit completed. All of this accounts for the 3000ms tolerance allowed for below. + // This is not a strict value, and if it causes failures regularly we should feel free to + // increase the tolerance; but it's meant to provide a stable baseline from which to detect + // regressions. + count = 0; + start = new Date().getTime(); + individualRequestStart = start; + while (pullCore.equals( + hostCore = + getHostCoreName( + COLL, + qaJettyBase, + p -> { + p.set(CommonParams.Q, "id:345"); + p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"); + }))) { + count++; + Thread.sleep(100); + individualRequestStart = new Date().getTime(); + } + now = new Date().getTime(); + log.info( + "query retries between NRT index-ready and query-ready: {}; overall_duration={}; baseline_expected_overall_duration={}; failover-request_duration={}", + count, + now - start, + pullServiceTimeMs, + now - individualRequestStart); + assertEquals(nrtCore, hostCore); + // allow any exceptions to propagate + jettyManipulationFuture.get(); + + // next phase: just toggle a bunch + // TODO: could separate this out into a different test method, but this should suffice for + // now + pullJetty.start(true); + waitForState( + "Pull jetty replicas didn't become active in time", + COLL, + ((liveNodes, collectionState) -> + collectionState.getReplicasOnNode(pullJettyF.getNodeName()).stream() + .allMatch(rep -> rep.getState() == Replica.State.ACTIVE))); + AtomicBoolean done = new AtomicBoolean(); + long runMinutes = 1; + long finishTimeMs = + new Date().getTime() + TimeUnit.MILLISECONDS.convert(runMinutes, TimeUnit.MINUTES); + JettySolrRunner[] jettys = new JettySolrRunner[] {pullJettyF, nrtJettyF}; + Random threadRandom = new Random(r.nextInt()); + Future f = + executor.submit( + () -> { + int iteration = 0; + while (new Date().getTime() < finishTimeMs && !done.get()) { + int idx = iteration++ % jettys.length; + JettySolrRunner toManipulate = jettys[idx]; try { - Thread.sleep(establishBaselineMs); - log.info("stopping NRT jetty ..."); - nrtJettyF.stop(); - log.info("NRT jetty stopped."); - Thread.sleep(nrtDowntimeMs); // let NRT be down for a while - log.info("restarting NRT jetty ..."); - nrtJettyF.start(true); - log.info("NRT jetty restarted."); - // once NRT is back up, we expect PULL to continue serving until the TTL on ZK - // state used for query request routing has expired (60s). But here we force a - // return to NRT by stopping the PULL replica after a brief delay ... - Thread.sleep(pullServiceTimeMs); - log.info("stopping PULL jetty ..."); - pullJettyF.stop(); - log.info("PULL jetty stopped."); + int serveTogetherTime = threadRandom.nextInt(7000); + int downTime = threadRandom.nextInt(7000); + log.info("serving together for {}ms", serveTogetherTime); + Thread.sleep(serveTogetherTime); + log.info("stopping {} ...", idx); + toManipulate.stop(); + log.info("stopped {}.", idx); + Thread.sleep(downTime); + log.info("restarting {} ...", idx); + toManipulate.start(true); + log.info("restarted {}.", idx); + waitForState( + toManipulate.getNodeName() + " replicas didn't become active in time", + COLL, + ((liveNodes, collectionState) -> + collectionState.getReplicasOnNode(toManipulate.getNodeName()).stream() + .allMatch(rep -> rep.getState() == Replica.State.ACTIVE))); } catch (Exception e) { throw new RuntimeException(e); } - }); - String hostCore; - long start = new Date().getTime(); - long individualRequestStart = start; - int count = 0; - while (nrtCore.equals( - hostCore = - getHostCoreName( - COLL, - qaJettyBase, - p -> p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT")))) { - count++; - Thread.sleep(100); - individualRequestStart = new Date().getTime(); - } - long now = new Date().getTime(); - log.info( - "phase1 NRT queries count={}, overall_duration={}, baseline_expected_overall_duration={}, switch-to-pull_duration={}", - count, - now - start, - establishBaselineMs, - now - individualRequestStart); - // default tolerance of 500ms below should suffice. Failover to PULL for this case should be - // very fast, because our QA-based client already knows both replicas are active, the index - // is stable, so the moment the client finds NRT is down it should be able to failover - // immediately and transparently to PULL. - assertEquals( - "when we break out of the NRT query loop, should be b/c routed to PULL", - pullCore, - hostCore); - SolrInputDocument d = new SolrInputDocument(); - d.addField("id", "345"); - d.addField("desc_s", "Another Document"); - // attempts to add another doc while NRT is down should fail, then eventually succeed when - // NRT comes back up - count = 0; - start = new Date().getTime(); - individualRequestStart = start; - for (; ; ) { - try { - client.add(COLL, d); - client.commit(COLL); - break; - } catch (SolrException ex) { - // we expect these until nrtJetty is back up. - count++; - Thread.sleep(100); + } + done.set(true); + return iteration; + }); + count = 0; + start = new Date().getTime(); + try { + do { + if (pullCore.equals( + getHostCoreName( + COLL, + qaJettyBase, + p -> { + p.set(CommonParams.Q, "id:345"); + p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"); + }))) { + done.set(true); } - individualRequestStart = new Date().getTime(); - } - now = new Date().getTime(); - log.info( - "successfully added another doc; duration: {}, overall_duration={}, baseline_expected_overall_duration={}, exception_count={}", - now - individualRequestStart, - now - start, - nrtDowntimeMs, - count); - // NRT replica is back up, registered as available with Zk, and availability info has been - // pulled down by our PULL-replica-based `client`, forwarded indexing command to NRT, - // index/commit completed. All of this accounts for the 3000ms tolerance allowed for below. - // This is not a strict value, and if it causes failures regularly we should feel free to - // increase the tolerance; but it's meant to provide a stable baseline from which to detect - // regressions. - count = 0; - start = new Date().getTime(); - individualRequestStart = start; - while (pullCore.equals( - hostCore = - getHostCoreName( - COLL, - qaJettyBase, - p -> { - p.set(CommonParams.Q, "id:345"); - p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"); - }))) { count++; Thread.sleep(100); - individualRequestStart = new Date().getTime(); + } while (!done.get()); + } finally { + final String result; + if (done.getAndSet(true)) { + result = "Success"; + } else { + // not yet set to done, completed abnormally (exception will be thrown beyond `finally` + // block) + result = "Failure"; } - now = new Date().getTime(); + Integer toggleCount = f.get(); + long secondsDuration = + TimeUnit.SECONDS.convert(new Date().getTime() - start, TimeUnit.MILLISECONDS); log.info( - "query retries between NRT index-ready and query-ready: {}; overall_duration={}; baseline_expected_overall_duration={}; failover-request_duration={}", - count, - now - start, - pullServiceTimeMs, - now - individualRequestStart); - assertEquals(nrtCore, hostCore); - // allow any exceptions to propagate - jettyManipulationFuture.get(); - - // next phase: just toggle a bunch - // TODO: could separate this out into a different test method, but this should suffice for - // now - pullJetty.start(true); - waitForState( - "Pull jetty replicas didn't become active in time", - COLL, - ((liveNodes, collectionState) -> - collectionState.getReplicasOnNode(pullJettyF.getNodeName()).stream() - .allMatch(rep -> rep.getState() == Replica.State.ACTIVE))); - AtomicBoolean done = new AtomicBoolean(); - long runMinutes = 1; - long finishTimeMs = - new Date().getTime() + TimeUnit.MILLISECONDS.convert(runMinutes, TimeUnit.MINUTES); - JettySolrRunner[] jettys = new JettySolrRunner[] {pullJettyF, nrtJettyF}; - Random threadRandom = new Random(r.nextInt()); - Future f = - executor.submit( - () -> { - int iteration = 0; - while (new Date().getTime() < finishTimeMs && !done.get()) { - int idx = iteration++ % jettys.length; - JettySolrRunner toManipulate = jettys[idx]; - try { - int serveTogetherTime = threadRandom.nextInt(7000); - int downTime = threadRandom.nextInt(7000); - log.info("serving together for {}ms", serveTogetherTime); - Thread.sleep(serveTogetherTime); - log.info("stopping {} ...", idx); - toManipulate.stop(); - log.info("stopped {}.", idx); - Thread.sleep(downTime); - log.info("restarting {} ...", idx); - toManipulate.start(true); - log.info("restarted {}.", idx); - waitForState( - toManipulate.getNodeName() + " replicas didn't become active in time", - COLL, - ((liveNodes, collectionState) -> - collectionState.getReplicasOnNode(toManipulate.getNodeName()).stream() - .allMatch(rep -> rep.getState() == Replica.State.ACTIVE))); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - done.set(true); - return iteration; - }); - count = 0; - start = new Date().getTime(); - try { - do { - if (pullCore.equals( - getHostCoreName( - COLL, - qaJettyBase, - p -> { - p.set(CommonParams.Q, "id:345"); - p.add(ShardParams.SHARDS_PREFERENCE, "replica.type:NRT"); - }))) { - done.set(true); - } - count++; - Thread.sleep(100); - } while (!done.get()); - } finally { - final String result; - if (done.getAndSet(true)) { - result = "Success"; - } else { - // not yet set to done, completed abnormally (exception will be thrown beyond `finally` - // block) - result = "Failure"; - } - Integer toggleCount = f.get(); - long secondsDuration = - TimeUnit.SECONDS.convert(new Date().getTime() - start, TimeUnit.MILLISECONDS); - log.info( - "{}! {} seconds, {} toggles, {} requests served", - result, - secondsDuration, - toggleCount, - count); - } + "{}! {} seconds, {} toggles, {} requests served", + result, + secondsDuration, + toggleCount, + count); } } finally { try { From ff141be5beca03762536f5371ed0a45fcd66fe90 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sun, 23 Aug 2026 10:37:33 +0300 Subject: [PATCH 07/24] SOLR-18390: also reuse getSolrClient() where it's reachable via CloudJettyRunner.jetty shardToJetty.get(SHARD2).get(0) is a CloudJettyRunner, which carries a public JettySolrRunner jetty field right next to the Replica-shaped info map the code was pulling a raw base_url string from. Same fix as the other 59 sites, just reached through a different field on the same object instead of a direct JettySolrRunner variable. --- .../solr/cloud/BasicDistributedZk2Test.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java index 71bf9cffe162..7d3d550d6c52 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -445,29 +445,25 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception { checkShardConsistency(true, false); // try a backup command - try (final SolrClient client = - new HttpJettySolrClient.Builder( - (String) shardToJetty.get(SHARD2).get(0).info.get("base_url")) - .build()) { - final String backupName = "the_backup"; - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("command", "backup"); - params.set("name", backupName); - final Path location = FilterPath.unwrap(createTempDir()).toRealPath(); - // Allow non-standard location outside SOLR_HOME - jettys.forEach(j -> j.getCoreContainer().getAllowPaths().add(location)); - params.set("location", location.toString()); - - QueryRequest request = new QueryRequest(ReplicationHandler.PATH, params); - client.request(request, DEFAULT_TEST_COLLECTION_NAME); - - final BackupStatusChecker backupStatus = - new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication"); - final String backupDirName = backupStatus.waitForBackupSuccess(backupName, 30); - assertTrue( - "Backup dir does not exist: " + backupDirName, - Files.exists(location.resolve(backupDirName))); - } + final SolrClient client = shardToJetty.get(SHARD2).get(0).jetty.getSolrClient(); + final String backupName = "the_backup"; + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("command", "backup"); + params.set("name", backupName); + final Path location = FilterPath.unwrap(createTempDir()).toRealPath(); + // Allow non-standard location outside SOLR_HOME + jettys.forEach(j -> j.getCoreContainer().getAllowPaths().add(location)); + params.set("location", location.toString()); + + QueryRequest request = new QueryRequest(ReplicationHandler.PATH, params); + client.request(request, DEFAULT_TEST_COLLECTION_NAME); + + final BackupStatusChecker backupStatus = + new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication"); + final String backupDirName = backupStatus.waitForBackupSuccess(backupName, 30); + assertTrue( + "Backup dir does not exist: " + backupDirName, + Files.exists(location.resolve(backupDirName))); } private void addNewReplica() throws Exception { From cff9aa8d8f7631274cc2e18633e0ee7bb9b3d503 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sun, 23 Aug 2026 10:59:44 +0300 Subject: [PATCH 08/24] SOLR-18390: migrate TestCustomStream off the legacy AbstractFullDistribZkTestBase Experiment: this test never used any AbstractFullDistribZkTestBase-specific machinery (ChaosMonkey, control_collection, shard-consistency checks) -- setupRestTestHarnesses()/randomRestTestHarness() already delegated to JettySolrRunner.getRestClient() internally, so the only real work was replicating the implicit cluster/collection setup explicitly on SolrCloudTestCase. Passed first try. Not a template for a blanket migration -- most subclasses of the legacy base actually use the machinery this one didn't. --- .../org/apache/solr/core/TestCustomStream.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/core/TestCustomStream.java b/solr/core/src/test/org/apache/solr/core/TestCustomStream.java index 73c8afc93de5..e167c798aadf 100644 --- a/solr/core/src/test/org/apache/solr/core/TestCustomStream.java +++ b/solr/core/src/test/org/apache/solr/core/TestCustomStream.java @@ -18,21 +18,30 @@ package org.apache.solr.core; import java.util.Arrays; -import org.apache.solr.cloud.AbstractFullDistribZkTestBase; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.util.RestTestHarness; +import org.junit.BeforeClass; import org.junit.Test; -public class TestCustomStream extends AbstractFullDistribZkTestBase { +public class TestCustomStream extends SolrCloudTestCase { + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(2).addConfig("conf1", configset("cloud-minimal")).configure(); + CollectionAdminRequest.createCollection("collection1", "conf1", 1, 2) + .process(cluster.getSolrClient()); + cluster.waitForActiveCollection("collection1", 1, 2); + } @Test public void testDynamicLoadingCustomStream() throws Exception { - setupRestTestHarnesses(); String payload = "{\n" + "'create-expressible' : { 'name' : 'hello', 'class': 'org.apache.solr.core.HelloStream' }\n" + "}"; - RestTestHarness client = randomRestTestHarness(); + RestTestHarness client = cluster.getRandomJetty(random()).getRestClient("collection1"); TestSolrConfigHandler.runConfigCommand(client, "/config", payload); TestSolrConfigHandler.testForResponseElement( client, From 05f75098f0fa11c4a0d5e48cc226ee814f8fd46d Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Tue, 25 Aug 2026 18:05:56 +0300 Subject: [PATCH 09/24] SOLR-18390: apply newSolrClient() where a runner is in scope Replaces manual HttpJettySolrClient.Builder(...) construction with JettySolrRunner.newSolrClient() across this PR's test changes, per David's review comment. Also removes BasicDistributedZkTest.createSolrCore, a private method with zero callers found during the sweep. --- .../solr/cloud/BasicDistributedZk2Test.java | 11 ++--- .../solr/cloud/BasicDistributedZkTest.java | 43 ------------------- .../ConcurrentCreateRoutedAliasTest.java | 7 +-- .../apache/solr/cloud/TestConfigSetsAPI.java | 16 +++---- .../cloud/TestConfigSetsAPIExclusivity.java | 4 +- .../cloud/TestConfigSetsAPIZkFailure.java | 4 +- ...ncurrentDeleteAndCreateCollectionTest.java | 7 +-- .../security/BasicAuthIntegrationTest.java | 6 +-- .../security/BasicAuthStandaloneTest.java | 3 +- .../solr/security/MultiAuthPluginTest.java | 13 +++--- .../solrj/impl/CloudHttp2SolrClientTest.java | 11 ++--- .../solr/util/SolrJMetricTestUtils.java | 6 ++- 12 files changed, 32 insertions(+), 99 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java index 7d3d550d6c52..d4c1ad631ede 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -26,7 +26,6 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -211,21 +210,17 @@ private void testNodeWithoutCollectionForwarding() throws Exception { int docs = 2; for (JettySolrRunner jetty : jettys) { - final String clientUrl = getBaseUrl(jetty); - addAndQueryDocs(clientUrl, docs); + addAndQueryDocs(jetty, docs); docs += 2; } } // 2 docs added every call - private void addAndQueryDocs(final String baseUrl, int docs) throws Exception { + private void addAndQueryDocs(final JettySolrRunner jetty, int docs) throws Exception { SolrQuery query = new SolrQuery("*:*"); - try (SolrClient client = - new HttpJettySolrClient.Builder(baseUrl) - .withDefaultCollection("onenodecollection") - .build()) { + try (SolrClient client = jetty.newSolrClient("onenodecollection")) { // add a doc client.add(sdoc("id", docs)); client.commit(); diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 5317d605fe74..9b67d37502a0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -36,7 +36,6 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import org.apache.lucene.util.IOUtils; @@ -50,7 +49,6 @@ import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.CoreAdminRequest.Create; import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.MetricsRequest; @@ -112,8 +110,6 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { private String oneInstanceCollection = "oneInstanceCollection"; private String oneInstanceCollection2 = "oneInstanceCollection2"; - private AtomicInteger nodeCounter = new AtomicInteger(); - CompletionService completionService; Set> pending; @@ -1499,45 +1495,6 @@ private void testANewCollectionInOneInstance() throws Exception { IOUtils.close(collectionClients); } - private void createSolrCore( - final String collection, - List collectionClients, - final String baseUrl, - final int num, - final String shardId) { - Callable call = - () -> { - try (SolrClient client = new HttpJettySolrClient.Builder(baseUrl).build()) { - // client.setConnectionTimeout(15000); - Create createCmd = new Create(); - createCmd.setCoreName(collection + num); - createCmd.setCollection(collection); - - if (random().nextBoolean()) { - // sometimes we use an explicit core node name - createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet()); - } - - if (shardId == null) { - createCmd.setNumShards(2); - } - createCmd.setDataDir(getDataDir(createTempDir(collection).toString())); - if (shardId != null) { - createCmd.setShardId(shardId); - } - client.request(createCmd); - } catch (Exception e) { - log.error("error creating core", e); - // fail - } - return null; - }; - - pending.add(completionService.submit(call)); - - collectionClients.add(createNewSolrClient(baseUrl, collection + num)); - } - private void testMultipleCollections() throws Exception { log.info("### STARTING testMultipleCollections"); // create another 2 collections and search across them diff --git a/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java b/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java index f52ab1df0b2d..50a177d5effe 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ConcurrentCreateRoutedAliasTest.java @@ -21,7 +21,6 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.common.util.IOUtils; @@ -96,8 +95,7 @@ public void testConcurrentCreateRoutedAliasMinimal() { int numStart = num; for (; num < threads.length + numStart; num++) { final String aliasName = "testAlias" + num; - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); int i = num - numStart; threads[i] = @@ -120,8 +118,7 @@ public void testConcurrentCreateRoutedAliasComplex() { System.out.println("NUM ==> " + num); for (; num < threads.length + numStart; num++) { final String aliasName = "testAliasCplx" + num; - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); int i = num - numStart; threads[i] = diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java index 0806953b4004..fe7e8b0b52ec 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -63,7 +63,6 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete; @@ -137,8 +136,7 @@ public void tearDown() throws Exception { @Test public void testCreateErrors() throws Exception { - final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - try (final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build()) { + try (final SolrClient solrClient = cluster.getJettySolrRunners().get(0).newSolrClient(null)) { getConfigSetService().uploadConfig("configSet", configset("configset-2")); // no action @@ -224,8 +222,7 @@ private void verifyCreate( Map newProps, String username) throws Exception { - final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - try (final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build()) { + try (final SolrClient solrClient = cluster.getJettySolrRunners().get(0).newSolrClient(null)) { setupBaseConfigSet(baseConfigSetName, oldProps); try (SolrZkClient zkClient = @@ -1640,8 +1637,7 @@ private byte[] readFile(String fname) throws IOException { @Test public void testDeleteErrors() throws Exception { - final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = cluster.getJettySolrRunners().get(0).newSolrClient(null); final Path configDir = getFile("solr").resolve("configsets/configset-2/conf"); final Path tmpConfigDir = createTempDir(); // Ensure ConfigSet is immutable @@ -1676,8 +1672,7 @@ private void verifyException( @Test public void testDelete() throws Exception { - final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = cluster.getJettySolrRunners().get(0).newSolrClient(null); final String configSet = "testDelete"; getConfigSetService().uploadConfig(configSet, configset("configset-2")); assertDelete(solrClient, configSet, true); @@ -1708,8 +1703,7 @@ private void assertDelete(SolrClient solrClient, String configSet, boolean asser @Test public void testList() throws Exception { - final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = cluster.getJettySolrRunners().get(0).newSolrClient(null); SolrZkClient zkClient = new SolrZkClient.Builder() diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java index 363a36f27359..64c1ca203da6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete; @@ -119,8 +118,7 @@ public ConfigSetsAPIThread(MiniSolrCloudCluster solrCluster, int trials) { @Override public void run() { - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); ConfigSetAdminRequest request = createRequest(); for (int i = 0; i < trials; ++i) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java index 61758f0592af..35448bf572f9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -37,7 +37,6 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.SolrZkClient; @@ -109,8 +108,7 @@ public void tearDown() throws Exception { @Test public void testCreateZkFailure() throws Exception { - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); final ConfigSetService configSetService = solrCluster.getOpenOverseer().getCoreContainer().getConfigSetService(); diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java index da52dbe97c49..44edb664e3cf 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/ConcurrentDeleteAndCreateCollectionTest.java @@ -24,7 +24,6 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.RemoteSolrException; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.cloud.MiniSolrCloudCluster; @@ -68,8 +67,7 @@ public void testConcurrentCreateAndDeleteDoesNotFail() throws IOException { for (int i = 0; i < threads.length; i++) { final String collectionName = "collection" + i; solrCluster.uploadConfigSet(configset("configset-2"), collectionName); - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); threads[i] = new CreateDeleteSearchCollectionThread( "create-delete-search-" + i, @@ -90,13 +88,12 @@ public void testConcurrentCreateAndDeleteOverTheSameConfig() throws IOException final String configName = "testconfig"; // upload config once, to be used by all collections solrCluster.uploadConfigSet(configset("configset-2"), configName); - final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); final AtomicReference failure = new AtomicReference<>(); final int timeToRunSec = 30; final CreateDeleteCollectionThread[] threads = new CreateDeleteCollectionThread[2]; for (int i = 0; i < threads.length; i++) { final String collectionName = "collection" + i; - final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + final SolrClient solrClient = solrCluster.getJettySolrRunners().get(0).newSolrClient(null); threads[i] = new CreateDeleteCollectionThread( "create-delete-" + i, collectionName, configName, timeToRunSec, solrClient, failure); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index 7049410f7096..b64b38b46528 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -31,7 +31,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -177,7 +176,8 @@ public void testBasicAuth() throws Exception { executeCommand(httpClient, baseUrl + authzPrefix, command, "solr", "SolrRocks"); assertAuthMetricsMinimums(5, 2, 3, 0, 0, 0); - baseUrl = cluster.getBaseUrl(random()); + final JettySolrRunner secondRandomJetty = cluster.getRandomJetty(random()); + baseUrl = secondRandomJetty.getBaseUrl().toString(); verifySecurityStatus( httpClient, baseUrl + authzPrefix, "authorization/user-role/harry", NOT_NULL_PREDICATE, 20); @@ -211,7 +211,7 @@ public void testBasicAuth() throws Exception { CollectionAdminRequest.Reload reload = CollectionAdminRequest.reloadCollection(COLLECTION); - try (var solrClient2 = new HttpJettySolrClient.Builder(baseUrl).build()) { + try (var solrClient2 = secondRandomJetty.newSolrClient(null)) { expectThrows(RemoteSolrException.class, () -> solrClient2.request(reload)); reload.setMethod(SolrRequest.METHOD.POST); expectThrows(RemoteSolrException.class, () -> solrClient2.request(reload)); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java index efbedee74f43..222c7dfdc91a 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthStandaloneTest.java @@ -27,7 +27,6 @@ import java.util.Map; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.util.Utils; import org.apache.solr.embedded.JettySolrRunner; @@ -76,7 +75,7 @@ public void testBasicAuth() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 20); diff --git a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java index fd05a64a72f1..c8dd0a89c87a 100644 --- a/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java +++ b/solr/core/src/test/org/apache/solr/security/MultiAuthPluginTest.java @@ -39,7 +39,6 @@ import java.util.stream.Collectors; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.util.CommandOperation; @@ -91,7 +90,7 @@ public void testMultiAuthEditAPI() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -267,7 +266,7 @@ public void testMultiAuthXBasicLookup() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -309,7 +308,7 @@ public void testMultiAuthWithBasicAndXBasic() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -355,7 +354,7 @@ public void testMultiAuthWithSinglePlugin() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -396,7 +395,7 @@ public void testMultiAuthWithBasicAndMockPlugin() throws Exception { try { httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); @@ -433,7 +432,7 @@ public void testMultiAuthWithBasicPluginAndAjax() throws Exception { try { var httpClient = jetty.getSolrClient().getHttpClient(); String baseUrl = buildUrl(jetty.getLocalPort()); - solrClient = new HttpJettySolrClient.Builder(baseUrl).build(); + solrClient = jetty.newSolrClient(null); verifySecurityStatus(httpClient, baseUrl + authcPrefix, "/errorMessages", null, 5); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java index 913253ec2754..70eae04540ec 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java @@ -741,9 +741,7 @@ public void testNonRetryableRequests() throws Exception { for (JettySolrRunner runner : cluster.getJettySolrRunners()) { Double numRequests = SolrJMetricTestUtils.getNumNodeRequestErrors( - runner.getBaseUrl().toString(), - SolrRequest.SolrRequestType.ADMIN.name(), - adminPath); + runner, SolrRequest.SolrRequestType.ADMIN.name(), adminPath); errorsBefore += numRequests.longValue(); if (log.isInfoEnabled()) { log.info( @@ -767,9 +765,7 @@ public void testNonRetryableRequests() throws Exception { for (JettySolrRunner runner : cluster.getJettySolrRunners()) { Double numRequests = SolrJMetricTestUtils.getNumNodeRequestErrors( - runner.getBaseUrl().toString(), - SolrRequest.SolrRequestType.ADMIN.name(), - adminPath); + runner, SolrRequest.SolrRequestType.ADMIN.name(), adminPath); errorsAfter += numRequests.longValue(); if (log.isInfoEnabled()) { log.info( @@ -946,7 +942,8 @@ public void testWrongZkChrootTest() throws IOException { @Test public void customHttpClientTest() throws Exception { String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString(); - try (HttpJettySolrClient httpClient = new HttpJettySolrClient.Builder(baseUrl).build()) { + try (HttpJettySolrClient httpClient = + cluster.getJettySolrRunners().get(0).newSolrClient(null)) { try (CloudSolrClient cloudClient = new CloudJettySolrClient.Builder(List.of(baseUrl)).withHttpClient(httpClient).build()) { // Verify the CloudJettySolrClient uses the provided HttpJettySolrClient diff --git a/solr/test-framework/src/java/org/apache/solr/util/SolrJMetricTestUtils.java b/solr/test-framework/src/java/org/apache/solr/util/SolrJMetricTestUtils.java index 7669c3755cf0..f589887b49e8 100644 --- a/solr/test-framework/src/java/org/apache/solr/util/SolrJMetricTestUtils.java +++ b/solr/test-framework/src/java/org/apache/solr/util/SolrJMetricTestUtils.java @@ -26,6 +26,7 @@ import org.apache.solr.client.solrj.request.MetricsRequest; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; +import org.apache.solr.embedded.JettySolrRunner; public final class SolrJMetricTestUtils { @@ -72,10 +73,11 @@ public static Double getNumCoreRequests( } } - public static Double getNumNodeRequestErrors(String baseUrl, String category, String handler) + public static Double getNumNodeRequestErrors( + JettySolrRunner runner, String category, String handler) throws SolrServerException, IOException { - try (var client = new HttpJettySolrClient.Builder(baseUrl).build()) { + try (var client = runner.newSolrClient(null)) { var req = new MetricsRequest(SolrParams.of("wt", "prometheus")); NamedList resp = client.request(req); From 4da7efcc3604b664eb5910f4d2595bf8df5b1948 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Wed, 26 Aug 2026 08:01:46 +0300 Subject: [PATCH 10/24] SOLR-18390: address David's review on the remaining call sites Use newSolrClient() where a JettySolrRunner is already in scope, and add MiniSolrCloudCluster.getJetty(nodeNameOrUrl) / getSolrClient(Replica) so the other two tests can reuse a jetty's shared client instead of opening and closing their own. --- .../CloudExitableDirectoryReaderTest.java | 5 +- .../solr/cloud/CollectionsAPISolrJTest.java | 18 +++-- ...stribDocExpirationUpdateProcessorTest.java | 65 +++++++++---------- .../solr/cloud/MiniSolrCloudCluster.java | 24 +++++++ 4 files changed, 63 insertions(+), 49 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java b/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java index 6dc0c7d61f5c..28bd7dc9d4b6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java @@ -30,7 +30,6 @@ import java.util.concurrent.TimeUnit; import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -82,9 +81,7 @@ public static void setupCluster() throws Exception { clusterBuilder.configure(); // pick an arbitrary node to use for our requests - client = - new HttpJettySolrClient.Builder(cluster.getRandomJetty(random()).getBaseUrl().toString()) - .build(); + client = cluster.getRandomJetty(random()).newSolrClient(null); CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1) .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT); diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java index f4c942a5f167..15af63761044 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java @@ -48,7 +48,6 @@ import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CollectionPropertiesApi; import org.apache.solr.client.solrj.request.CollectionsApi; @@ -300,15 +299,14 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException String nodeName = response._getStr("success[0]/key"); String corename = response._getStr(asList("success", nodeName, "core"), null); - try (SolrClient coreClient = - new HttpJettySolrClient.Builder(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName)) - .build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient); - assertEquals( - collectionName, status._get(asList("status", corename, "cloud", "collection"), null)); - assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null)); - assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null)); - } + // nodeName is actually "nodeName/coreNodeName" (see CollectionHandlingUtils.requestKey) + SolrClient coreClient = + cluster.getJetty(nodeName.substring(0, nodeName.indexOf('/'))).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient); + assertEquals( + collectionName, status._get(asList("status", corename, "cloud", "collection"), null)); + assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null)); + assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null)); } @Test diff --git a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java index 17175d63df80..b7e8558b1297 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java @@ -28,7 +28,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -289,40 +288,36 @@ private Map getTestDataForAllReplicas() for (Replica replica : collectionState.getReplicas()) { String coreName = replica.getCoreName(); - try (SolrClient client = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("command", "indexversion"); - params.set("_trace", "getIndexVersion"); - QueryRequest req = setAuthIfNeeded(new QueryRequest(ReplicationHandler.PATH, params)); - - NamedList res = client.request(req); - assertNotNull("null response from server: " + coreName, res); - - Object version = res.get("indexversion"); - assertNotNull("null version from server: " + coreName, version); - assertTrue("version isn't a long: " + coreName, version instanceof Long); - - long numDocs = - setAuthIfNeeded( - new QueryRequest( - params( - "q", "*:*", - "distrib", "false", - "rows", "0", - "_trace", "counting_docs"))) - .process(client) - .getResults() - .getNumFound(); - - final ReplicaData data = - new ReplicaData(replica.getShard(), coreName, (Long) version, numDocs); - log.info("{}", data); - results.put(coreName, data); - } + SolrClient client = cluster.getSolrClient(replica); + + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("command", "indexversion"); + params.set("_trace", "getIndexVersion"); + QueryRequest req = setAuthIfNeeded(new QueryRequest(ReplicationHandler.PATH, params)); + + NamedList res = client.request(req); + assertNotNull("null response from server: " + coreName, res); + + Object version = res.get("indexversion"); + assertNotNull("null version from server: " + coreName, version); + assertTrue("version isn't a long: " + coreName, version instanceof Long); + + long numDocs = + setAuthIfNeeded( + new QueryRequest( + params( + "q", "*:*", + "distrib", "false", + "rows", "0", + "_trace", "counting_docs"))) + .process(client) + .getResults() + .getNumFound(); + + final ReplicaData data = + new ReplicaData(replica.getShard(), coreName, (Long) version, numDocs); + log.info("{}", data); + results.put(coreName, data); } return results; diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java index b1cbb83362d7..74aff256b2fb 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java @@ -53,8 +53,10 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.SolrBackend; 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.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; import org.apache.solr.client.solrj.jetty.CloudJettySolrClient; import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; @@ -738,6 +740,28 @@ public JettySolrRunner getReplicaJetty(Replica replica) { "Cannot find Jetty for a replica with core url " + replica.getCoreUrl()); } + /** Return the jetty for a node, identified by either its node name or its base URL. */ + public JettySolrRunner getJetty(String nodeNameOrUrl) { + for (JettySolrRunner jetty : jettys) { + if (jetty.isStopped()) continue; + if (nodeNameOrUrl.equals(jetty.getNodeName()) + || nodeNameOrUrl.equals(jetty.getBaseUrl().toString())) { + return jetty; + } + } + throw new IllegalArgumentException("Cannot find Jetty for node " + nodeNameOrUrl); + } + + /** + * Returns the jetty-owned client for the node hosting {@code replica}, scoped to that replica's + * core. The caller must not close the returned client -- it delegates to the jetty's own shared + * client, which the jetty itself owns. + */ + public SolrClient getSolrClient(Replica replica) { + return new CollectionScopedSolrClient( + getReplicaJetty(replica).getSolrClient(), replica.getCoreName()); + } + /** Make the zookeeper session on a particular jetty lose connection and expire */ public void expireZkSession(JettySolrRunner jetty) { ChaosMonkey.expireSession(jetty, zkServer); From af1ef74faf8704a4a3640d8b67fccc9cd6900ef6 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 08:59:39 +0300 Subject: [PATCH 11/24] SOLR-18390: use cluster.getSolrClient(Replica) where a replica is in scope Replaces 34 hand-built clients across 14 test classes. Since the returned client is cluster-owned, try-with-resources and explicit close() calls on them are dropped. --- .../cloud/DistributedVersionInfoTest.java | 96 ++-- .../cloud/FullSolrCloudDistribCmdsTest.java | 422 ++++++++---------- .../solr/cloud/MigrateRouteKeyTest.java | 100 ++--- .../org/apache/solr/cloud/SplitShardTest.java | 20 +- .../apache/solr/cloud/TestPullReplica.java | 122 ++--- .../cloud/TestPullReplicaErrorHandling.java | 2 + .../solr/cloud/TestPullReplicaWithAuth.java | 13 +- .../apache/solr/cloud/TestTlogReplica.java | 121 +++-- .../solr/cloud/ZkShardTermsRecoveryTest.java | 15 +- .../core/snapshots/TestSolrCoreSnapshots.java | 259 +++++------ .../handler/TestStressIncrementalBackup.java | 10 +- .../solr/handler/TestStressThreadBackup.java | 10 +- .../handler/admin/LukeHandlerCloudTest.java | 36 +- .../update/DeleteByIdWithRouterFieldTest.java | 35 +- 14 files changed, 549 insertions(+), 712 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java index a96fd1a7a6ac..859f551dfab0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java @@ -111,35 +111,29 @@ public void testReplicaVersionHandling() throws Exception { maxOnReplica); // send the same doc but with a lower version than the max in the index - try (SolrClient client = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - String docId = String.valueOf(1); - SolrInputDocument doc = new SolrInputDocument(); - doc.setField("id", docId); - doc.setField("_version_", maxOnReplica - 1); // bad version!!! - - // simulate what the leader does when sending a doc to a replica - ModifiableSolrParams params = new ModifiableSolrParams(); - params.set( - DISTRIB_UPDATE_PARAM, DistributedUpdateProcessor.DistribPhase.FROMLEADER.toString()); - params.set(DISTRIB_FROM, leader.getCoreUrl()); - - UpdateRequest req = new UpdateRequest(); - req.setParams(params); - req.add(doc); - - log.info( - "Sending doc with out-of-date version ({}) document directly to replica", - maxOnReplica - 1); - - client.request(req); - client.commit(); - - Long docVersion = getVersionFromIndex(replica, docId); - assertEquals("older version should have been thrown away", maxOnReplica, docVersion); - } + SolrClient client = cluster.getSolrClient(replica); + String docId = String.valueOf(1); + SolrInputDocument doc = new SolrInputDocument(); + doc.setField("id", docId); + doc.setField("_version_", maxOnReplica - 1); // bad version!!! + + // simulate what the leader does when sending a doc to a replica + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set(DISTRIB_UPDATE_PARAM, DistributedUpdateProcessor.DistribPhase.FROMLEADER.toString()); + params.set(DISTRIB_FROM, leader.getCoreUrl()); + + UpdateRequest req = new UpdateRequest(); + req.setParams(params); + req.add(doc); + + log.info( + "Sending doc with out-of-date version ({}) document directly to replica", maxOnReplica - 1); + + client.request(req); + client.commit(); + + Long docVersion = getVersionFromIndex(replica, docId); + assertEquals("older version should have been thrown away", maxOnReplica, docVersion); reloadCollection(leader, COLLECTION); @@ -305,16 +299,12 @@ protected long getVersionFromIndex(Replica replica, String docId) query.addSort(new SolrQuery.SortClause("_version_", SolrQuery.ORDER.desc)); query.setParam("distrib", false); - try (SolrClient client = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - QueryResponse qr = client.query(query); - SolrDocumentList hits = qr.getResults(); - if (hits.isEmpty()) fail("No results returned from query: " + query); + SolrClient client = cluster.getSolrClient(replica); + QueryResponse qr = client.query(query); + SolrDocumentList hits = qr.getResults(); + if (hits.isEmpty()) fail("No results returned from query: " + query); - vers = (Long) hits.get(0).getFirstValue("_version_"); - } + vers = (Long) hits.get(0).getFirstValue("_version_"); if (vers == null) fail("Failed to get version using query " + query + " from " + replica.getCoreUrl()); @@ -330,34 +320,18 @@ protected void assertDocsExistInAllReplicas( int lastDocId, Set deletedDocs) throws Exception { - SolrClient leaderSolr = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build(); + SolrClient leaderSolr = cluster.getSolrClient(leader); List replicas = new ArrayList(notLeaders.size()); - for (Replica r : notLeaders) - replicas.add( - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build()); + for (Replica r : notLeaders) replicas.add(cluster.getSolrClient(r)); - try { - for (int d = firstDocId; d <= lastDocId; d++) { + for (int d = firstDocId; d <= lastDocId; d++) { - if (deletedDocs != null && deletedDocs.contains(d)) continue; + if (deletedDocs != null && deletedDocs.contains(d)) continue; - String docId = String.valueOf(d); - Long leaderVers = assertDocExists(leaderSolr, docId, null); - for (SolrClient replicaSolr : replicas) { - assertDocExists(replicaSolr, docId, leaderVers); - } - } - } finally { - if (leaderSolr != null) { - leaderSolr.close(); - } + String docId = String.valueOf(d); + Long leaderVers = assertDocExists(leaderSolr, docId, null); for (SolrClient replicaSolr : replicas) { - replicaSolr.close(); + assertDocExists(replicaSolr, docId, leaderVers); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java index 451fadbeae13..84de1bb043c9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java @@ -173,112 +173,103 @@ public void testDeleteByIdImplicitRouter() throws Exception { final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); Replica shard1Leader = docCol.getSlice("shard1").getLeader(); Replica shard2Leader = docCol.getSlice("shard2").getLeader(); - try (SolrClient shard1 = - new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl()) - .withDefaultCollection(shard1Leader.getCoreName()) - .build(); - SolrClient shard2 = - new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl()) - .withDefaultCollection(shard2Leader.getCoreName()) - .build()) { - - // Add three documents to shard1 - shard1.add(sdoc("id", "1", "title", "s1 one")); - shard1.add(sdoc("id", "2", "title", "s1 two")); - shard1.add(sdoc("id", "3", "title", "s1 three")); - shard1.commit(); - final AtomicInteger docCounts1 = new AtomicInteger(3); - - // Add two documents to shard2 - shard2.add(sdoc("id", "4", "title", "s2 four")); - shard2.add(sdoc("id", "5", "title", "s2 five")); - shard2.commit(); - final AtomicInteger docCounts2 = new AtomicInteger(2); - - // A re-usable helper to verify that the expected number of documents can be found on each - // shard... - Runnable checkShardCounts = - () -> { - try { - // including cloudClient helps us test view from other nodes that aren't the - // leaders... - for (SolrClient c : Arrays.asList(cloudClient, shard1, shard2)) { - - ModifiableSolrParams params = params("q", "*:*"); - if (c instanceof CloudSolrClient) { - params.add("collection", testCollectionName); - } - assertEquals( - docCounts1.get() + docCounts2.get(), - c.query(params).getResults().getNumFound()); - - assertEquals( - docCounts1.get(), - c.query(params.set("shards", "shard1")).getResults().getNumFound()); - assertEquals( - docCounts2.get(), - c.query(params.set("shards", "shard2")).getResults().getNumFound()); - - assertEquals( - docCounts1.get() + docCounts2.get(), - c.query(params.set("shards", "shard2,shard1")).getResults().getNumFound()); + SolrClient shard1 = cluster.getSolrClient(shard1Leader); + SolrClient shard2 = cluster.getSolrClient(shard2Leader); + // Add three documents to shard1 + shard1.add(sdoc("id", "1", "title", "s1 one")); + shard1.add(sdoc("id", "2", "title", "s1 two")); + shard1.add(sdoc("id", "3", "title", "s1 three")); + shard1.commit(); + final AtomicInteger docCounts1 = new AtomicInteger(3); + + // Add two documents to shard2 + shard2.add(sdoc("id", "4", "title", "s2 four")); + shard2.add(sdoc("id", "5", "title", "s2 five")); + shard2.commit(); + final AtomicInteger docCounts2 = new AtomicInteger(2); + + // A re-usable helper to verify that the expected number of documents can be found on each + // shard... + Runnable checkShardCounts = + () -> { + try { + // including cloudClient helps us test view from other nodes that aren't the + // leaders... + for (SolrClient c : Arrays.asList(cloudClient, shard1, shard2)) { + + ModifiableSolrParams params = params("q", "*:*"); + if (c instanceof CloudSolrClient) { + params.add("collection", testCollectionName); } + assertEquals( + docCounts1.get() + docCounts2.get(), c.query(params).getResults().getNumFound()); assertEquals( docCounts1.get(), - shard1.query(params("q", "*:*", "distrib", "false")).getResults().getNumFound()); + c.query(params.set("shards", "shard1")).getResults().getNumFound()); assertEquals( docCounts2.get(), - shard2.query(params("q", "*:*", "distrib", "false")).getResults().getNumFound()); + c.query(params.set("shards", "shard2")).getResults().getNumFound()); - } catch (Exception sse) { - throw new RuntimeException(sse); + assertEquals( + docCounts1.get() + docCounts2.get(), + c.query(params.set("shards", "shard2,shard1")).getResults().getNumFound()); } - }; - checkShardCounts.run(); - - { // Send a delete request for a doc on shard1 to core hosting shard1 with NO routing info - // Should delete (implicitly) since doc is (implicitly) located on this shard - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("1"); - shard1.request(deleteRequest); - shard1.commit(); - docCounts1.decrementAndGet(); - } - checkShardCounts.run(); - - { // Send a delete request to core hosting shard1 with a route param for a document that is - // actually in shard2 should delete. - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("4").withRoute("shard2"); - shard1.request(deleteRequest); - shard1.commit(); - docCounts2.decrementAndGet(); - } - checkShardCounts.run(); - - { // Send a delete request to core hosting shard1 with NO route param for a document that is - // actually in shard2. Shouldn't delete, since deleteById requests are not broadcast to all - // shard leaders. (This is effectively a request to delete "5" if and only if it is on - // shard1) - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("5"); - shard1.request(deleteRequest); - shard1.commit(); - } - checkShardCounts.run(); - - { // Multiple deleteById commands for different shards in a single request - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("2", "shard1"); - deleteRequest.deleteById("5", "shard2"); - shard1.request(deleteRequest); - shard1.commit(); - docCounts1.decrementAndGet(); - docCounts2.decrementAndGet(); - } - checkShardCounts.run(); + + assertEquals( + docCounts1.get(), + shard1.query(params("q", "*:*", "distrib", "false")).getResults().getNumFound()); + assertEquals( + docCounts2.get(), + shard2.query(params("q", "*:*", "distrib", "false")).getResults().getNumFound()); + + } catch (Exception sse) { + throw new RuntimeException(sse); + } + }; + checkShardCounts.run(); + + { // Send a delete request for a doc on shard1 to core hosting shard1 with NO routing info + // Should delete (implicitly) since doc is (implicitly) located on this shard + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("1"); + shard1.request(deleteRequest); + shard1.commit(); + docCounts1.decrementAndGet(); + } + checkShardCounts.run(); + + { // Send a delete request to core hosting shard1 with a route param for a document that is + // actually in shard2 should delete. + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("4").withRoute("shard2"); + shard1.request(deleteRequest); + shard1.commit(); + docCounts2.decrementAndGet(); + } + checkShardCounts.run(); + + { // Send a delete request to core hosting shard1 with NO route param for a document that is + // actually in shard2. Shouldn't delete, since deleteById requests are not broadcast to all + // shard leaders. (This is effectively a request to delete "5" if and only if it is on + // shard1) + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("5"); + shard1.request(deleteRequest); + shard1.commit(); + } + checkShardCounts.run(); + + { // Multiple deleteById commands for different shards in a single request + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("2", "shard1"); + deleteRequest.deleteById("5", "shard2"); + shard1.request(deleteRequest); + shard1.commit(); + docCounts1.decrementAndGet(); + docCounts2.decrementAndGet(); } + checkShardCounts.run(); } public void testRTGCompositeRouterWithRouterField() throws Exception { @@ -336,108 +327,100 @@ public void testDeleteByIdCompositeRouterWithRouterField() throws Exception { final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName); Replica shard1Leader = docCol.getSlice("shard1").getLeader(); Replica shard2Leader = docCol.getSlice("shard2").getLeader(); - try (SolrClient shard1 = - new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl()) - .withDefaultCollection(shard1Leader.getCoreName()) - .build(); - SolrClient shard2 = - new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl()) - .withDefaultCollection(shard2Leader.getCoreName()) - .build()) { + SolrClient shard1 = cluster.getSolrClient(shard1Leader); + SolrClient shard2 = cluster.getSolrClient(shard2Leader); + // Add six documents w/diff routes (all sent to shard1 leader's core) + shard1.add(sdoc("id", "1", "routefield_s", "europe")); + shard1.add(sdoc("id", "3", "routefield_s", "europe")); + shard1.add(sdoc("id", "5", "routefield_s", "africa")); + shard1.add(sdoc("id", "7", "routefield_s", "europe")); + shard1.add(sdoc("id", "9", "routefield_s", "europe")); + shard1.add(sdoc("id", "11", "routefield_s", "africa")); + shard1.commit(); + + // Add four documents w/diff routes (all sent to shard2 leader's core) + shard2.add(sdoc("id", "8", "routefield_s", "africa")); + shard2.add(sdoc("id", "6", "routefield_s", "europe")); + shard2.add(sdoc("id", "4", "routefield_s", "africa")); + shard2.add(sdoc("id", "2", "routefield_s", "europe")); + shard2.commit(); + + final AtomicInteger docCountsEurope = new AtomicInteger(6); + final AtomicInteger docCountsAfrica = new AtomicInteger(4); + + // A re-usable helper to verify that the expected number of documents can be found based on + // _route_ key... + Runnable checkShardCounts = + () -> { + try { + // including cloudClient helps us test view from other nodes that aren't the + // leaders... + for (SolrClient c : Arrays.asList(cloudClient, shard1, shard2)) { + + ModifiableSolrParams params = params("q", "*:*"); + if (c instanceof CloudSolrClient) { + params.add("collection", testCollectionName); + } + assertEquals( + docCountsEurope.get() + docCountsAfrica.get(), + c.query(params).getResults().getNumFound()); - // Add six documents w/diff routes (all sent to shard1 leader's core) - shard1.add(sdoc("id", "1", "routefield_s", "europe")); - shard1.add(sdoc("id", "3", "routefield_s", "europe")); - shard1.add(sdoc("id", "5", "routefield_s", "africa")); - shard1.add(sdoc("id", "7", "routefield_s", "europe")); - shard1.add(sdoc("id", "9", "routefield_s", "europe")); - shard1.add(sdoc("id", "11", "routefield_s", "africa")); + assertEquals( + docCountsEurope.get(), + c.query(params.set("_route_", "europe")).getResults().getNumFound()); + assertEquals( + docCountsAfrica.get(), + c.query(params.set("_route_", "africa")).getResults().getNumFound()); + } + } catch (Exception sse) { + throw new RuntimeException(sse); + } + }; + checkShardCounts.run(); + + { // Send a delete request to core hosting shard1 with a route param for a document that was + // originally added via core on shard2 + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("4", "africa"); + shard1.request(deleteRequest); shard1.commit(); + docCountsAfrica.decrementAndGet(); + } + checkShardCounts.run(); - // Add four documents w/diff routes (all sent to shard2 leader's core) - shard2.add(sdoc("id", "8", "routefield_s", "africa")); - shard2.add(sdoc("id", "6", "routefield_s", "europe")); - shard2.add(sdoc("id", "4", "routefield_s", "africa")); - shard2.add(sdoc("id", "2", "routefield_s", "europe")); - shard2.commit(); - - final AtomicInteger docCountsEurope = new AtomicInteger(6); - final AtomicInteger docCountsAfrica = new AtomicInteger(4); - - // A re-usable helper to verify that the expected number of documents can be found based on - // _route_ key... - Runnable checkShardCounts = - () -> { - try { - // including cloudClient helps us test view from other nodes that aren't the - // leaders... - for (SolrClient c : Arrays.asList(cloudClient, shard1, shard2)) { - - ModifiableSolrParams params = params("q", "*:*"); - if (c instanceof CloudSolrClient) { - params.add("collection", testCollectionName); - } - assertEquals( - docCountsEurope.get() + docCountsAfrica.get(), - c.query(params).getResults().getNumFound()); - - assertEquals( - docCountsEurope.get(), - c.query(params.set("_route_", "europe")).getResults().getNumFound()); - assertEquals( - docCountsAfrica.get(), - c.query(params.set("_route_", "africa")).getResults().getNumFound()); - } - } catch (Exception sse) { - throw new RuntimeException(sse); - } - }; - checkShardCounts.run(); - - { // Send a delete request to core hosting shard1 with a route param for a document that was - // originally added via core on shard2 - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("4", "africa"); - shard1.request(deleteRequest); - shard1.commit(); - docCountsAfrica.decrementAndGet(); - } - checkShardCounts.run(); - - { // Multiple deleteById commands with different routes in a single request - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("2", "europe"); - deleteRequest.deleteById("5", "africa"); - shard1.request(deleteRequest); - shard1.commit(); - docCountsEurope.decrementAndGet(); - docCountsAfrica.decrementAndGet(); - } - checkShardCounts.run(); - - // Tests for distributing delete by id when route is missing from the request - { // Send a delete request with no route to shard1 for document on shard2, should be - // distributed - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("8"); - shard1.request(deleteRequest); - shard1.commit(); - docCountsAfrica.decrementAndGet(); - } - checkShardCounts.run(); - - { // Multiple deleteById commands with missing route in a single request, should be - // distributed - final UpdateRequest deleteRequest = new UpdateRequest(); - deleteRequest.deleteById("6"); - deleteRequest.deleteById("11"); - shard1.request(deleteRequest); - shard1.commit(); - docCountsEurope.decrementAndGet(); - docCountsAfrica.decrementAndGet(); - } - checkShardCounts.run(); + { // Multiple deleteById commands with different routes in a single request + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("2", "europe"); + deleteRequest.deleteById("5", "africa"); + shard1.request(deleteRequest); + shard1.commit(); + docCountsEurope.decrementAndGet(); + docCountsAfrica.decrementAndGet(); } + checkShardCounts.run(); + + // Tests for distributing delete by id when route is missing from the request + { // Send a delete request with no route to shard1 for document on shard2, should be + // distributed + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("8"); + shard1.request(deleteRequest); + shard1.commit(); + docCountsAfrica.decrementAndGet(); + } + checkShardCounts.run(); + + { // Multiple deleteById commands with missing route in a single request, should be + // distributed + final UpdateRequest deleteRequest = new UpdateRequest(); + deleteRequest.deleteById("6"); + deleteRequest.deleteById("11"); + shard1.request(deleteRequest); + shard1.commit(); + docCountsEurope.decrementAndGet(); + docCountsAfrica.decrementAndGet(); + } + checkShardCounts.run(); } public void testThatCantForwardToLeaderFails() throws Exception { @@ -882,36 +865,27 @@ private void checkShardConsistency(String collectionName, final SolrParams param final Slice slice = entry.getValue(); log.info("Checking: {} -> {}", shardName, slice); final Replica leader = entry.getValue().getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - final SolrDocumentList leaderResults = leaderClient.query(perReplicaParams).getResults(); - log.debug("Shard {}: Leader results: {}", shardName, leaderResults); - for (Replica replica : slice) { - try (SolrClient replicaClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - final SolrDocumentList replicaResults = - replicaClient.query(perReplicaParams).getResults(); - if (log.isDebugEnabled()) { - log.debug( - "Shard {}: Replica ({}) results: {}", - shardName, - replica.getCoreName(), - replicaResults); - } - assertEquals( - "inconsistency w/leader: shard=" + shardName + "core=" + replica.getCoreName(), - Set.of(), - CloudInspectUtil.showDiff( - leaderResults, - replicaResults, - shardName + " leader: " + leader.getCoreUrl(), - shardName + ": " + replica.getCoreUrl())); - } + SolrClient leaderClient = cluster.getSolrClient(leader); + final SolrDocumentList leaderResults = leaderClient.query(perReplicaParams).getResults(); + log.debug("Shard {}: Leader results: {}", shardName, leaderResults); + for (Replica replica : slice) { + SolrClient replicaClient = cluster.getSolrClient(replica); + final SolrDocumentList replicaResults = replicaClient.query(perReplicaParams).getResults(); + if (log.isDebugEnabled()) { + log.debug( + "Shard {}: Replica ({}) results: {}", + shardName, + replica.getCoreName(), + replicaResults); } + assertEquals( + "inconsistency w/leader: shard=" + shardName + "core=" + replica.getCoreName(), + Set.of(), + CloudInspectUtil.showDiff( + leaderResults, + replicaResults, + shardName + " leader: " + leader.getCoreUrl(), + shardName + ": " + replica.getCoreUrl())); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java index 5721282fa41f..400283901f1f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java @@ -24,7 +24,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; @@ -135,59 +134,54 @@ public void multipleShardMigrateTest() throws Exception { DocCollection state = getCollectionState(targetCollection); Replica replica = state.replicaStream().findFirst().orElseThrow(); - try (SolrClient collectionClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - - SolrQuery solrQuery = new SolrQuery("*:*"); - assertEquals( - "DocCount on target collection does not match", - 0, - collectionClient.query(solrQuery).getResults().getNumFound()); - - invokeCollectionMigration( - CollectionAdminRequest.migrateData( - sourceCollection, targetCollection, splitKey + "/" + BIT_SEP + "!") - .setForwardTimeout(45)); - - long finishTime = System.nanoTime(); - - indexer.join(); - splitKeyCount += indexer.getSplitKeyCount(); - - try { - cluster.getSolrClient().deleteById(sourceCollection, "a/" + BIT_SEP + "!104"); - splitKeyCount--; - } catch (Exception e) { - log.warn("Error deleting document a/{}!104", BIT_SEP, e); - } - cluster.getSolrClient().commit(sourceCollection); - collectionClient.commit(); - - solrQuery = new SolrQuery("*:*").setRows(1000); - QueryResponse response = collectionClient.query(solrQuery); - log.info("Response from target collection: {}", response); - assertEquals( - "DocCount on target collection does not match", - splitKeyCount, - response.getResults().getNumFound()); - - waitForState( - "Expected to find routing rule for split key " + splitKey, - sourceCollection, - c -> { - if (c == null) return false; - Slice shard = c.getSlice("shard2"); - if (shard == null) return false; - if (shard.getRoutingRules() == null || shard.getRoutingRules().isEmpty()) return false; - if (shard.getRoutingRules().get(splitKey + "!") == null) return false; - return true; - }); - - boolean ruleRemoved = waitForRuleToExpire(sourceCollection, "shard2", splitKey, finishTime); - assertTrue("Routing rule was not expired", ruleRemoved); + SolrClient collectionClient = cluster.getSolrClient(replica); + SolrQuery solrQuery = new SolrQuery("*:*"); + assertEquals( + "DocCount on target collection does not match", + 0, + collectionClient.query(solrQuery).getResults().getNumFound()); + + invokeCollectionMigration( + CollectionAdminRequest.migrateData( + sourceCollection, targetCollection, splitKey + "/" + BIT_SEP + "!") + .setForwardTimeout(45)); + + long finishTime = System.nanoTime(); + + indexer.join(); + splitKeyCount += indexer.getSplitKeyCount(); + + try { + cluster.getSolrClient().deleteById(sourceCollection, "a/" + BIT_SEP + "!104"); + splitKeyCount--; + } catch (Exception e) { + log.warn("Error deleting document a/{}!104", BIT_SEP, e); } + cluster.getSolrClient().commit(sourceCollection); + collectionClient.commit(); + + solrQuery = new SolrQuery("*:*").setRows(1000); + QueryResponse response = collectionClient.query(solrQuery); + log.info("Response from target collection: {}", response); + assertEquals( + "DocCount on target collection does not match", + splitKeyCount, + response.getResults().getNumFound()); + + waitForState( + "Expected to find routing rule for split key " + splitKey, + sourceCollection, + c -> { + if (c == null) return false; + Slice shard = c.getSlice("shard2"); + if (shard == null) return false; + if (shard.getRoutingRules() == null || shard.getRoutingRules().isEmpty()) return false; + if (shard.getRoutingRules().get(splitKey + "!") == null) return false; + return true; + }); + + boolean ruleRemoved = waitForRuleToExpire(sourceCollection, "shard2", splitKey, finishTime); + assertTrue("Routing rule was not expired", ruleRemoved); } static class Indexer extends Thread { diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java index a78eb5c39566..a7405273e265 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java @@ -37,7 +37,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -230,21 +229,10 @@ long getNumDocs(CloudSolrClient client, String collectionName) throws Exception if (!slice.getState().equals(Slice.State.ACTIVE)) continue; long lastReplicaCount = -1; for (Replica replica : slice.getReplicas()) { - SolrClient replicaClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build(); - long numFound; - try { - numFound = - replicaClient - .query(params("q", "*:*", "distrib", "false")) - .getResults() - .getNumFound(); - log.info("Replica count={} for {}", numFound, replica); - } finally { - replicaClient.close(); - } + SolrClient replicaClient = cluster.getSolrClient(replica); + long numFound = + replicaClient.query(params("q", "*:*", "distrib", "false")).getResults().getNumFound(); + log.info("Replica count={} for {}", numFound, replica); if (lastReplicaCount >= 0) { assertEquals("Replica doc count for " + replica, lastReplicaCount, numFound); } 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 859c2f823a4f..d3e4c120b13f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -299,12 +299,9 @@ public void testAddDocs() throws Exception { Slice s = docCollection.getSlices().iterator().next(); Replica sliceLeader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) - .withDefaultCollection(sliceLeader.getCoreName()) - .build()) { - assertEquals(numDocs, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - } + SolrClient leaderClient = cluster.getSolrClient(sliceLeader); + assertEquals(numDocs, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); + log.info( "Found {} docs in leader, verifying updates make it to {} pull replicas", numDocs, @@ -537,42 +534,32 @@ public void testRealTimeGet() Slice slice = docCollection.getSlice("shard1"); List ids = new ArrayList<>(slice.getReplicas().size()); for (Replica rAdd : slice.getReplicas()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(rAdd.getBaseUrl()) - .withDefaultCollection(rAdd.getCoreName()) - .build()) { - client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar")); - } + SolrClient client = cluster.getSolrClient(rAdd); + client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar")); + SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id)); assertEquals("bar", docCloudClient.getFieldValue("foo_s")); for (Replica rGet : slice.getReplicas()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(rGet.getBaseUrl()) - .withDefaultCollection(rGet.getCoreName()) - .build()) { - SolrDocument doc = client.getById(String.valueOf(id)); - assertEquals("bar", doc.getFieldValue("foo_s")); - } + SolrClient getClient = cluster.getSolrClient(rGet); + SolrDocument doc = getClient.getById(String.valueOf(id)); + assertEquals("bar", doc.getFieldValue("foo_s")); } ids.add(String.valueOf(id)); id++; } SolrDocumentList previousAllIdsResult = null; for (Replica rAdd : slice.getReplicas()) { - try (SolrClient client = - new HttpJettySolrClient.Builder(rAdd.getBaseUrl()) - .withDefaultCollection(rAdd.getCoreName()) - .build()) { - SolrDocumentList allIdsResult = client.getById(ids); - if (previousAllIdsResult != null) { - assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult)); - } else { - // set the first response here - previousAllIdsResult = allIdsResult; - assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound()); - } + SolrClient client = cluster.getSolrClient(rAdd); + SolrDocumentList allIdsResult = client.getById(ids); + if (previousAllIdsResult != null) { + assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult)); + } else { + // set the first response here + previousAllIdsResult = allIdsResult; + assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound()); } + id++; } } @@ -595,12 +582,8 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); Replica sliceLeader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) - .withDefaultCollection(sliceLeader.getCoreName()) - .build()) { - assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - } + SolrClient leaderClient = cluster.getSolrClient(sliceLeader); + assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); waitForNumDocsInAllReplicas(1, getReplicas(docCollection, EnumSet.of(Replica.Type.PULL))); @@ -708,13 +691,10 @@ private void doTestNoLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "zoo")); s = docCollection.getSlices().iterator().next(); sliceLeader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) - .withDefaultCollection(sliceLeader.getCoreName()) - .build()) { - leaderClient.commit(); - assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - } + leaderClient = cluster.getSolrClient(sliceLeader); + leaderClient.commit(); + assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); + waitForNumDocsInAllReplicas( 1, getReplicas(docCollection, EnumSet.of(Replica.Type.PULL)), "id:2", null, null); waitForNumDocsInAllReplicas(1, getReplicas(docCollection, EnumSet.of(Replica.Type.PULL))); @@ -915,35 +895,31 @@ static void waitForNumDocsInAllReplicas( TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS, TimeSource.NANO_TIME); for (Replica r : replicas) { String replicaUrl = r.getCoreUrl(); - try (SolrClient replicaClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build()) { - while (true) { - QueryRequest req = new QueryRequest(new SolrQuery(query)); - if (user != null && pass != null) { - req.setBasicAuthCredentials(user, pass); - } - try { - long numFound = req.process(replicaClient).getResults().getNumFound(); - assertEquals( - "Replica " - + r.getName() - + " (" - + replicaUrl - + ") not up to date after " - + REPLICATION_TIMEOUT_SECS - + " seconds", - numDocs, - numFound); - log.info("Replica {} ({}) has all {} docs", r.name, replicaUrl, numDocs); - break; - } catch (AssertionError e) { - if (t.hasTimedOut()) { - throw e; - } else { - Thread.sleep(200); - } + SolrClient replicaClient = cluster.getSolrClient(r); + while (true) { + QueryRequest req = new QueryRequest(new SolrQuery(query)); + if (user != null && pass != null) { + req.setBasicAuthCredentials(user, pass); + } + try { + long numFound = req.process(replicaClient).getResults().getNumFound(); + assertEquals( + "Replica " + + r.getName() + + " (" + + replicaUrl + + ") not up to date after " + + REPLICATION_TIMEOUT_SECS + + " seconds", + numDocs, + numFound); + log.info("Replica {} ({}) has all {} docs", r.name, replicaUrl, numDocs); + break; + } catch (AssertionError e) { + if (t.hasTimedOut()) { + throw e; + } else { + Thread.sleep(200); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java index a014091a689b..28f84c6a138b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java @@ -142,6 +142,8 @@ public void testCantConnectToPullReplica() throws Exception { for (int i = 1; i <= 10; i++) { addDocs(10 + i); Replica leader = s.getLeader(); + // proxied ports: the replica's registered URL is the proxy's, not the jetty's, + // so the cluster can't resolve a jetty-owned client here try (SolrClient leaderClient = new HttpJettySolrClient.Builder(leader.getBaseUrl()) .withDefaultCollection(leader.getCoreName()) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java index d9079ceefb1e..8d3fea023d36 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java @@ -29,7 +29,6 @@ import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -95,14 +94,10 @@ public void testPKIAuthWorksForPullReplication() throws Exception { Slice s = docCollection.getSlices().iterator().next(); Replica leader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - assertEquals( - numDocs, - queryWithBasicAuth(leaderClient, new SolrQuery("*:*")).getResults().getNumFound()); - } + SolrClient leaderClient = cluster.getSolrClient(leader); + assertEquals( + numDocs, + queryWithBasicAuth(leaderClient, new SolrQuery("*:*")).getResults().getNumFound()); List pullReplicas = s.getReplicas(EnumSet.of(Replica.Type.PULL)); waitForNumDocsInAllReplicas( 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 d621fed809b9..9a1e9f7524c5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -41,7 +41,6 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -259,56 +258,48 @@ public void testAddDocs() throws Exception { Slice s = docCollection.getSlices().iterator().next(); Replica sliceLeader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) - .withDefaultCollection(sliceLeader.getCoreName()) - .build()) { - assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - } + SolrClient leaderClient = cluster.getSolrClient(sliceLeader); + assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS, TimeSource.NANO_TIME); for (Replica r : s.getReplicas(EnumSet.of(Replica.Type.TLOG))) { // TODO: assert replication < REPLICATION_TIMEOUT_SECS - try (SolrClient tlogReplicaClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build()) { - while (true) { - try { + SolrClient tlogReplicaClient = cluster.getSolrClient(r); + while (true) { + try { + assertEquals( + "Replica " + r.getName() + " not up to date after 10 seconds", + 1, + tlogReplicaClient.query(new SolrQuery("*:*")).getResults().getNumFound()); + JettySolrRunner jetty = + cluster.getJettySolrRunners().stream() + .filter(j -> j.getBaseUrl().toString().equals(r.getBaseUrl())) + .findFirst() + .orElse(null); + assertNotNull("Could not find jetty for replica " + r, jetty); + + try (SolrCore core = jetty.getCoreContainer().getCore(r.getCoreName())) { + var cumulativeAddsDatapoint = + SolrMetricTestUtils.getGaugeDatapoint( + core, + "solr_core_update_cumulative_ops", + SolrMetricTestUtils.newCloudLabelsBuilder(core) + .label("category", "UPDATE") + .label("ops", "adds") + .build()); + assertNotNull("Could not find cumulative adds metric", cumulativeAddsDatapoint); assertEquals( - "Replica " + r.getName() + " not up to date after 10 seconds", - 1, - tlogReplicaClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - JettySolrRunner jetty = - cluster.getJettySolrRunners().stream() - .filter(j -> j.getBaseUrl().toString().equals(r.getBaseUrl())) - .findFirst() - .orElse(null); - assertNotNull("Could not find jetty for replica " + r, jetty); - - try (SolrCore core = jetty.getCoreContainer().getCore(r.getCoreName())) { - var cumulativeAddsDatapoint = - SolrMetricTestUtils.getGaugeDatapoint( - core, - "solr_core_update_cumulative_ops", - SolrMetricTestUtils.newCloudLabelsBuilder(core) - .label("category", "UPDATE") - .label("ops", "adds") - .build()); - assertNotNull("Could not find cumulative adds metric", cumulativeAddsDatapoint); - assertEquals( - "Append replicas should receive all updates. Replica: " + r, - 1.0, - cumulativeAddsDatapoint.getValue(), - 0.0); - } - break; - } catch (AssertionError e) { - if (t.hasTimedOut()) { - throw e; - } else { - Thread.sleep(100); - } + "Append replicas should receive all updates. Replica: " + r, + 1.0, + cumulativeAddsDatapoint.getValue(), + 0.0); + } + break; + } catch (AssertionError e) { + if (t.hasTimedOut()) { + throw e; + } else { + Thread.sleep(100); } } } @@ -452,12 +443,8 @@ private void doReplaceLeader(boolean removeReplica) throws Exception { cluster.getSolrClient().commit(collectionName); Slice s = docCollection.getSlices().iterator().next(); Replica sliceLeader = s.getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(sliceLeader.getBaseUrl()) - .withDefaultCollection(sliceLeader.getCoreName()) - .build()) { - assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); - } + SolrClient leaderClient = cluster.getSolrClient(sliceLeader); + assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound()); waitForNumDocsInAllReplicas( 1, getReplicas(docCollection, EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS); @@ -1011,23 +998,19 @@ private void waitForNumDocsInAllReplicas( if (!r.isActive(cluster.getSolrClient().getClusterState().getLiveNodes())) { continue; } - try (SolrClient replicaClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build()) { - while (true) { - try { - assertEquals( - "Replica " + r.getName() + " not up to date after " + timeout + " seconds", - numDocs, - replicaClient.query(new SolrQuery(query)).getResults().getNumFound()); - break; - } catch (AssertionError e) { - if (t.hasTimedOut()) { - throw e; - } else { - Thread.sleep(100); - } + SolrClient replicaClient = cluster.getSolrClient(r); + while (true) { + try { + assertEquals( + "Replica " + r.getName() + " not up to date after " + timeout + " seconds", + numDocs, + replicaClient.query(new SolrQuery(query)).getResults().getNumFound()); + break; + } catch (AssertionError e) { + if (t.hasTimedOut()) { + throw e; + } else { + Thread.sleep(100); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java index 6c4769d3b297..cc0f5ca7e6c7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsRecoveryTest.java @@ -27,7 +27,6 @@ import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -191,15 +190,11 @@ private void waitForNumDocsInAllReplicas(int numDocs, Collection replic if (!r.isActive(cluster.getSolrClient().getClusterState().getLiveNodes())) { continue; } - try (SolrClient replicaClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build()) { - assertEquals( - "Replica " + r.getName() + " not up to date", - numDocs, - replicaClient.query(new SolrQuery(query)).getResults().getNumFound()); - } + SolrClient replicaClient = cluster.getSolrClient(r); + assertEquals( + "Replica " + r.getName() + " not up to date", + numDocs, + replicaClient.query(new SolrQuery(query)).getResults().getNumFound()); } } diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java index 269e3ee65f8a..b251c5b3dcd1 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java @@ -33,7 +33,6 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.CreateSnapshot; import org.apache.solr.client.solrj.request.CoreAdminRequest.DeleteSnapshot; @@ -99,77 +98,72 @@ public void testBackupRestore() throws Exception { String duplicateName = commitName.concat("_duplicate"); SolrClient adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - - SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); - // Create another snapshot referring to the same index commit to verify the - // reference counting implementation during snapshot deletion. - SnapshotMetaData duplicateCommit = createSnapshot(adminClient, coreName, duplicateName); - - assertEquals(metaData.getIndexDirPath(), duplicateCommit.getIndexDirPath()); - assertEquals(metaData.getGenerationNumber(), duplicateCommit.getGenerationNumber()); - - // Delete all documents - leaderClient.deleteByQuery("*:*"); - leaderClient.commit(); - BackupRestoreUtils.verifyDocs(0, cluster.getSolrClient(), collectionName); - - // Verify that the index directory contains at least 2 index commits - one referred by the - // snapshots and the other containing document deletions. - { - List commits = listCommits(metaData.getIndexDirPath()); - assertTrue(commits.size() >= 2); - } + SolrClient leaderClient = cluster.getSolrClient(replica); + SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); + // Create another snapshot referring to the same index commit to verify the + // reference counting implementation during snapshot deletion. + SnapshotMetaData duplicateCommit = createSnapshot(adminClient, coreName, duplicateName); + + assertEquals(metaData.getIndexDirPath(), duplicateCommit.getIndexDirPath()); + assertEquals(metaData.getGenerationNumber(), duplicateCommit.getGenerationNumber()); + + // Delete all documents + leaderClient.deleteByQuery("*:*"); + leaderClient.commit(); + BackupRestoreUtils.verifyDocs(0, cluster.getSolrClient(), collectionName); + + // Verify that the index directory contains at least 2 index commits - one referred by the + // snapshots and the other containing document deletions. + { + List commits = listCommits(metaData.getIndexDirPath()); + assertTrue(commits.size() >= 2); + } - // Backup the earlier created snapshot. - { - Map params = new HashMap<>(); - params.put("name", backupName); - params.put("commitName", commitName); - params.put("location", location); - params.put("incremental", "false"); - BackupRestoreUtils.runCoreAdminCommand( - replicaBaseUrl, coreName, CoreAdminAction.BACKUPCORE.toString(), params); - } + // Backup the earlier created snapshot. + { + Map params = new HashMap<>(); + params.put("name", backupName); + params.put("commitName", commitName); + params.put("location", location); + params.put("incremental", "false"); + BackupRestoreUtils.runCoreAdminCommand( + replicaBaseUrl, coreName, CoreAdminAction.BACKUPCORE.toString(), params); + } - // Restore the backup - { - Map params = new HashMap<>(); - params.put("name", "snapshot." + backupName); - params.put("location", location); - BackupRestoreUtils.runCoreAdminCommand( - replicaBaseUrl, coreName, CoreAdminAction.RESTORECORE.toString(), params); - BackupRestoreUtils.verifyDocs(nDocs, cluster.getSolrClient(), collectionName); - } + // Restore the backup + { + Map params = new HashMap<>(); + params.put("name", "snapshot." + backupName); + params.put("location", location); + BackupRestoreUtils.runCoreAdminCommand( + replicaBaseUrl, coreName, CoreAdminAction.RESTORECORE.toString(), params); + BackupRestoreUtils.verifyDocs(nDocs, cluster.getSolrClient(), collectionName); + } - // Verify that the old index directory (before restore) contains only those index commits - // referred by snapshots. The IndexWriter (used to clean up index files) creates an additional - // commit during closing. Hence, we expect 2 commits (instead of 1). - { - List commits = listCommits(metaData.getIndexDirPath()); - assertEquals(2, commits.size()); - assertEquals(metaData.getGenerationNumber(), commits.get(0).getGeneration()); - } + // Verify that the old index directory (before restore) contains only those index commits + // referred by snapshots. The IndexWriter (used to clean up index files) creates an additional + // commit during closing. Hence, we expect 2 commits (instead of 1). + { + List commits = listCommits(metaData.getIndexDirPath()); + assertEquals(2, commits.size()); + assertEquals(metaData.getGenerationNumber(), commits.get(0).getGeneration()); + } - // Delete first snapshot - deleteSnapshot(adminClient, coreName, commitName); + // Delete first snapshot + deleteSnapshot(adminClient, coreName, commitName); - // Verify that corresponding index files have NOT been deleted (due to reference counting). - assertFalse(listCommits(metaData.getIndexDirPath()).isEmpty()); + // Verify that corresponding index files have NOT been deleted (due to reference counting). + assertFalse(listCommits(metaData.getIndexDirPath()).isEmpty()); - // Delete second snapshot - deleteSnapshot(adminClient, coreName, duplicateCommit.getName()); + // Delete second snapshot + deleteSnapshot(adminClient, coreName, duplicateCommit.getName()); - // Verify that corresponding index files have been deleted. Ideally this directory should - // be removed immediately. But the current DirectoryFactory impl waits until the - // closing the core (or the directoryFactory) for actual removal. Since the IndexWriter - // (used to clean up index files) creates an additional commit during closing, we expect a - // single commit (instead of 0). - assertEquals(1, listCommits(duplicateCommit.getIndexDirPath()).size()); - } + // Verify that corresponding index files have been deleted. Ideally this directory should + // be removed immediately. But the current DirectoryFactory impl waits until the + // closing the core (or the directoryFactory) for actual removal. Since the IndexWriter + // (used to clean up index files) creates an additional commit during closing, we expect a + // single commit (instead of 0). + assertEquals(1, listCommits(duplicateCommit.getIndexDirPath()).size()); } @Test @@ -192,70 +186,19 @@ public void testIndexOptimization() throws Exception { String commitName = TestUtil.randomSimpleString(random(), 1, 5); SolrClient adminClient = cluster.getJettySolrRunners().get(0).getSolrClient(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - - SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); - - int numTests = nDocs > 0 ? TestUtil.nextInt(random(), 1, 5) : 1; - for (int attempt = 0; attempt < numTests; attempt++) { - // Modify existing index before we call optimize. - if (nDocs > 0) { - // Delete a few docs - int numDeletes = TestUtil.nextInt(random(), 1, nDocs); - for (int i = 0; i < numDeletes; i++) { - leaderClient.deleteByQuery("id:" + i); - } - // Add a few more - int moreAdds = TestUtil.nextInt(random(), 1, 100); - for (int i = 0; i < moreAdds; i++) { - SolrInputDocument doc = new SolrInputDocument(); - doc.addField("id", i + nDocs); - doc.addField("name", "name = " + (i + nDocs)); - leaderClient.add(doc); - } - leaderClient.commit(); + SolrClient leaderClient = cluster.getSolrClient(replica); + SnapshotMetaData metaData = createSnapshot(adminClient, coreName, commitName); + + int numTests = nDocs > 0 ? TestUtil.nextInt(random(), 1, 5) : 1; + for (int attempt = 0; attempt < numTests; attempt++) { + // Modify existing index before we call optimize. + if (nDocs > 0) { + // Delete a few docs + int numDeletes = TestUtil.nextInt(random(), 1, nDocs); + for (int i = 0; i < numDeletes; i++) { + leaderClient.deleteByQuery("id:" + i); } - } - - // Before invoking optimize command, verify that the index directory contains multiple commits - // (including the one we snapshotted earlier). - { - Collection commits = listCommits(metaData.getIndexDirPath()); - // Verify that multiple index commits are stored in this directory. - assertTrue(commits.size() > 0); - // Verify that the snapshot commit is present in this directory. - assertTrue( - commits.stream() - .filter(x -> x.getGeneration() == metaData.getGenerationNumber()) - .findFirst() - .isPresent()); - } - - // Optimize the index. - leaderClient.optimize(true, true, 1); - - // After invoking optimize command, verify that the index directory contains multiple commits - // (including the one we snapshotted earlier). - { - List commits = listCommits(metaData.getIndexDirPath()); - // Verify that multiple index commits are stored in this directory. - assertTrue(commits.size() > 1); - // Verify that the snapshot commit is present in this directory. - assertTrue( - commits.stream() - .filter(x -> x.getGeneration() == metaData.getGenerationNumber()) - .findFirst() - .isPresent()); - } - - // Delete the snapshot - deleteSnapshot(adminClient, coreName, metaData.getName()); - - // Add few documents. Without this the optimize command below does not take effect. - { + // Add a few more int moreAdds = TestUtil.nextInt(random(), 1, 100); for (int i = 0; i < moreAdds; i++) { SolrInputDocument doc = new SolrInputDocument(); @@ -265,20 +208,66 @@ public void testIndexOptimization() throws Exception { } leaderClient.commit(); } + } - // Optimize the index. - leaderClient.optimize(true, true, 1); - - // Verify that the index directory contains only 1 index commit (which is not the same as the - // snapshotted commit). + // Before invoking optimize command, verify that the index directory contains multiple commits + // (including the one we snapshotted earlier). + { Collection commits = listCommits(metaData.getIndexDirPath()); - assertEquals(1, commits.size()); - assertFalse( + // Verify that multiple index commits are stored in this directory. + assertTrue(commits.size() > 0); + // Verify that the snapshot commit is present in this directory. + assertTrue( + commits.stream() + .filter(x -> x.getGeneration() == metaData.getGenerationNumber()) + .findFirst() + .isPresent()); + } + + // Optimize the index. + leaderClient.optimize(true, true, 1); + + // After invoking optimize command, verify that the index directory contains multiple commits + // (including the one we snapshotted earlier). + { + List commits = listCommits(metaData.getIndexDirPath()); + // Verify that multiple index commits are stored in this directory. + assertTrue(commits.size() > 1); + // Verify that the snapshot commit is present in this directory. + assertTrue( commits.stream() .filter(x -> x.getGeneration() == metaData.getGenerationNumber()) .findFirst() .isPresent()); } + + // Delete the snapshot + deleteSnapshot(adminClient, coreName, metaData.getName()); + + // Add few documents. Without this the optimize command below does not take effect. + { + int moreAdds = TestUtil.nextInt(random(), 1, 100); + for (int i = 0; i < moreAdds; i++) { + SolrInputDocument doc = new SolrInputDocument(); + doc.addField("id", i + nDocs); + doc.addField("name", "name = " + (i + nDocs)); + leaderClient.add(doc); + } + leaderClient.commit(); + } + + // Optimize the index. + leaderClient.optimize(true, true, 1); + + // Verify that the index directory contains only 1 index commit (which is not the same as the + // snapshotted commit). + Collection commits = listCommits(metaData.getIndexDirPath()); + assertEquals(1, commits.size()); + assertFalse( + commits.stream() + .filter(x -> x.getGeneration() == metaData.getGenerationNumber()) + .findFirst() + .isPresent()); } private SnapshotMetaData createSnapshot( 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 0bfbe1f2b019..548563131955 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressIncrementalBackup.java @@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -81,20 +80,13 @@ private void initCoreNameAndSolrCoreClient() { .iterator() .next(); coreName = r.getCoreName(); - coreClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build(); + coreClient = cluster.getSolrClient(r); } @After public void afterTest() throws Exception { // we use a clean cluster instance for every test, so we need to clean it up shutdownCluster(); - - if (null != coreClient) { - coreClient.close(); - } } @SuppressWarnings("AssertionFailureIgnored") // failure happens inside a thread 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 acb4bd15701d..ea4d54c5c224 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestStressThreadBackup.java @@ -41,7 +41,6 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -105,10 +104,6 @@ public void beforeTest() throws Exception { public void afterTest() throws Exception { // we use a clean cluster instance for every test, so we need to clean it up shutdownCluster(); - - if (null != coreClient) { - coreClient.close(); - } } @Test @@ -369,10 +364,7 @@ private void initCoreNameAndSolrCoreClient() { .iterator() .next(); coreName = r.getCoreName(); - coreClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()) - .withDefaultCollection(r.getCoreName()) - .build(); + coreClient = cluster.getSolrClient(r); } /** diff --git a/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java b/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java index 2c270eef2b93..ed418d1621e5 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/LukeHandlerCloudTest.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.LukeRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -138,16 +137,12 @@ public void testInconsistentIndexFlagsAcrossShards() throws Exception { String targetSliceName = null; for (Slice slice : docColl.getSlices()) { Replica leader = slice.getLeader(); - try (SolrClient client = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - SolrQuery q = new SolrQuery("id:target"); - q.set(DISTRIB, "false"); - QueryResponse qr = client.query(q); - if (qr.getResults().getNumFound() > 0) { - targetSliceName = slice.getName(); - } + SolrClient client = cluster.getSolrClient(leader); + SolrQuery q = new SolrQuery("id:target"); + q.set(DISTRIB, "false"); + QueryResponse qr = client.query(q); + if (qr.getResults().getNumFound() > 0) { + targetSliceName = slice.getName(); } } assertNotNull("target doc should exist on a shard", targetSliceName); @@ -157,17 +152,14 @@ public void testInconsistentIndexFlagsAcrossShards() throws Exception { for (Slice slice : docColl.getSlices()) { if (!slice.getName().equals(targetSliceName)) { Replica leader = slice.getLeader(); - try (SolrClient client = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - SolrQuery q = new SolrQuery("*:*"); - q.setRows(1); - q.set(DISTRIB, "false"); - QueryResponse qr = client.query(q); - assertTrue("other shard should have seed docs", qr.getResults().getNumFound() > 0); - otherDocId = (String) qr.getResults().getFirst().getFieldValue("id"); - } + SolrClient client = cluster.getSolrClient(leader); + SolrQuery q = new SolrQuery("*:*"); + q.setRows(1); + q.set(DISTRIB, "false"); + QueryResponse qr = client.query(q); + assertTrue("other shard should have seed docs", qr.getResults().getNumFound() > 0); + otherDocId = (String) qr.getResults().getFirst().getFieldValue("id"); + break; } } 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 4fe310024e63..0d5e86ffd54f 100644 --- a/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java +++ b/solr/core/src/test/org/apache/solr/update/DeleteByIdWithRouterFieldTest.java @@ -27,7 +27,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.impl.LBSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.cloud.CloudInspectUtil; @@ -118,27 +117,19 @@ private void checkShardsConsistentNumFound() throws Exception { final String shardName = entry.getKey(); final Slice slice = entry.getValue(); final Replica leader = entry.getValue().getLeader(); - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - final SolrDocumentList leaderResults = leaderClient.query(params).getResults(); - for (Replica replica : slice) { - try (SolrClient replicaClient = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - final SolrDocumentList replicaResults = replicaClient.query(params).getResults(); - assertEquals( - "inconsistency w/leader: shard=" + shardName + "core=" + replica.getCoreName(), - Set.of(), - CloudInspectUtil.showDiff( - leaderResults, - replicaResults, - shardName + " leader: " + leader.getCoreUrl(), - shardName + ": " + replica.getCoreUrl())); - } - } + SolrClient leaderClient = cluster.getSolrClient(leader); + final SolrDocumentList leaderResults = leaderClient.query(params).getResults(); + for (Replica replica : slice) { + SolrClient replicaClient = cluster.getSolrClient(replica); + final SolrDocumentList replicaResults = replicaClient.query(params).getResults(); + assertEquals( + "inconsistency w/leader: shard=" + shardName + "core=" + replica.getCoreName(), + Set.of(), + CloudInspectUtil.showDiff( + leaderResults, + replicaResults, + shardName + " leader: " + leader.getCoreUrl(), + shardName + ": " + replica.getCoreUrl())); } } } From 761dde62cbc5ff0235a14695fc78851dfc9132af Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 09:11:24 +0300 Subject: [PATCH 12/24] SOLR-18390: make the replica-client helper reach the remaining call sites getReplicaJetty now also matches a jetty's proxy URL, so it resolves in tests that front a node with a SocketProxy. The same lookup is shared with AbstractFullDistribZkTestBase, which gains its own getSolrClient(Replica) since it has jettys but no MiniSolrCloudCluster. --- .../solr/cloud/BasicDistributedZkTest.java | 27 ++++++------- .../solr/cloud/HttpPartitionOnCommitTest.java | 39 ++++++++----------- .../cloud/NestedShardedAtomicUpdateTest.java | 15 +------ .../cloud/TestPullReplicaErrorHandling.java | 9 +---- .../cloud/api/collections/ShardSplitTest.java | 27 +++++-------- .../cloud/AbstractFullDistribZkTestBase.java | 11 ++++++ .../solr/cloud/MiniSolrCloudCluster.java | 9 ++++- 7 files changed, 58 insertions(+), 79 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 9b67d37502a0..f392491ca4d9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -46,7 +46,6 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload; @@ -911,21 +910,17 @@ private long checkSlicesSameCounts(DocCollection dColl) throws SolrServerExcepti for (Slice slice : dColl.getActiveSlices()) { long sliceDocCount = -1; for (Replica rep : slice.getReplicas()) { - try (SolrClient one = - new HttpJettySolrClient.Builder(rep.getBaseUrl()) - .withDefaultCollection(rep.getCoreName()) - .build()) { - SolrQuery query = new SolrQuery("*:*"); - query.setDistrib(false); - QueryResponse resp = one.query(query); - long hits = resp.getResults().getNumFound(); - if (sliceDocCount == -1) { - sliceDocCount = hits; - docTotal += hits; - } else { - if (hits != sliceDocCount) { - return -1; - } + SolrClient one = getSolrClient(rep); + SolrQuery query = new SolrQuery("*:*"); + query.setDistrib(false); + QueryResponse resp = one.query(query); + long hits = resp.getResults().getNumFound(); + if (sliceDocCount == -1) { + sliceDocCount = hits; + docTotal += hits; + } else { + if (hits != sliceDocCount) { + return -1; } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java index 0543f72cf7b6..a41b5e2b0614 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionOnCommitTest.java @@ -21,7 +21,6 @@ import java.nio.file.Path; import java.util.List; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.ZkStateReader; @@ -191,28 +190,24 @@ protected void sendCommitWithRetry(Replica replica) throws Exception { String replicaCoreUrl = replica.getCoreUrl(); log.info("Sending commit request to: {}", replicaCoreUrl); final RTimer timer = new RTimer(); - try (SolrClient client = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - try { - client.commit(); + SolrClient client = getSolrClient(replica); + try { + client.commit(); - if (log.isInfoEnabled()) { - log.info("Sent commit request to {} OK, took {}ms", replicaCoreUrl, timer.getTime()); - } - } catch (Exception exc) { - Throwable rootCause = SolrException.getRootCause(exc); - if (rootCause instanceof IOException) { - log.warn( - "No HTTP response from sending commit request to {}; will re-try after waiting 3 seconds", - replicaCoreUrl); - Thread.sleep(3000); - client.commit(); - log.info("Second attempt at sending commit to {} succeeded", replicaCoreUrl); - } else { - throw exc; - } + if (log.isInfoEnabled()) { + log.info("Sent commit request to {} OK, took {}ms", replicaCoreUrl, timer.getTime()); + } + } catch (Exception exc) { + Throwable rootCause = SolrException.getRootCause(exc); + if (rootCause instanceof IOException) { + log.warn( + "No HTTP response from sending commit request to {}; will re-try after waiting 3 seconds", + replicaCoreUrl); + Thread.sleep(3000); + client.commit(); + log.info("Second attempt at sending commit to {} succeeded", replicaCoreUrl); + } else { + throw exc; } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java index a74cab548122..c3569fc78651 100644 --- a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java @@ -22,11 +22,9 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import org.apache.lucene.util.IOUtils; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -37,7 +35,6 @@ import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.util.RandomNoReverseMergePolicyFactory; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -74,17 +71,7 @@ public static void beforeClass() throws Exception { clusterState .getCollection(DEFAULT_COLLECTION) .replicaStream() - .forEach( - replica -> - clients.add( - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build())); - } - - @AfterClass - public static void afterClass() throws Exception { - IOUtils.close(clients); + .forEach(replica -> clients.add(cluster.getSolrClient(replica))); } @Test diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java index 28f84c6a138b..20d281c86463 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaErrorHandling.java @@ -142,14 +142,7 @@ public void testCantConnectToPullReplica() throws Exception { for (int i = 1; i <= 10; i++) { addDocs(10 + i); Replica leader = s.getLeader(); - // proxied ports: the replica's registered URL is the proxy's, not the jetty's, - // so the cluster can't resolve a jetty-owned client here - try (SolrClient leaderClient = - new HttpJettySolrClient.Builder(leader.getBaseUrl()) - .withDefaultCollection(leader.getCoreName()) - .build()) { - assertNumDocs(10 + i, leaderClient); - } + assertNumDocs(10 + i, cluster.getSolrClient(leader)); } SolrServerException e = 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 8800411ba670..4c0ca599e31d 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 @@ -1193,22 +1193,16 @@ protected void checkDocCountsAndShardStates( Replica shard1_0 = getLeaderFromZk(AbstractFullDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0); QueryResponse response; - try (SolrClient shard1_0Client = - new HttpJettySolrClient.Builder(shard1_0.getBaseUrl()) - .withDefaultCollection(shard1_0.getCoreName()) - .build()) { - response = shard1_0Client.query(query); - } + SolrClient shard1_0Client = getSolrClient(shard1_0); + response = shard1_0Client.query(query); + long shard10Count = response.getResults().getNumFound(); Replica shard1_1 = getLeaderFromZk(AbstractFullDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1); QueryResponse response2; - try (SolrClient shard1_1Client = - new HttpJettySolrClient.Builder(shard1_1.getBaseUrl()) - .withDefaultCollection(shard1_1.getCoreName()) - .build()) { - response2 = shard1_1Client.query(query); - } + SolrClient shard1_1Client = getSolrClient(shard1_1); + response2 = shard1_1Client.query(query); + long shard11Count = response2.getResults().getNumFound(); logDebugHelp(docCounts, response, shard10Count, response2, shard11Count, documentIds); @@ -1231,12 +1225,9 @@ protected void checkSubShardConsistency(String shard) throws SolrServerException for (Replica replica : slice.getReplicas()) { String coreUrl = replica.getCoreUrl(); QueryResponse response; - try (SolrClient client = - new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(replica.getCoreName()) - .build()) { - response = client.query(query); - } + SolrClient client = getSolrClient(replica); + response = client.query(query); + numFound[c++] = response.getResults().getNumFound(); if (log.isInfoEnabled()) { log.info( diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 8e7b09890840..d976d9fabe40 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -59,6 +59,7 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; @@ -2556,6 +2557,16 @@ protected CloudSolrClient getCommonCloudSolrClient() { return commonCloudSolrClient; } + /** + * Returns the jetty-owned client for the node hosting {@code replica}, scoped to that replica's + * core. The caller must not close it -- the jetty owns it. + */ + protected SolrClient getSolrClient(Replica replica) { + return new CollectionScopedSolrClient( + MiniSolrCloudCluster.findReplicaJetty(jettys, replica).getSolrClient(), + replica.getCoreName()); + } + protected CloudSolrClient getSolrClient(String collectionName) { return solrClientByCollection.computeIfAbsent( collectionName, diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java index 3db27c9acd64..378689787e15 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java @@ -740,9 +740,16 @@ private Exception checkForExceptions(String message, Collection runners, Replica replica) { + for (JettySolrRunner jetty : runners) { if (jetty.isStopped()) continue; if (replica.getCoreUrl().startsWith(jetty.getBaseUrl().toString())) return jetty; + // a proxied jetty registers its replicas under the proxy's port + if (replica.getCoreUrl().startsWith(jetty.getProxyBaseUrl().toString())) return jetty; } throw new IllegalArgumentException( "Cannot find Jetty for a replica with core url " + replica.getCoreUrl()); From 3a1897bf52621b1664616569af366e463580e11b Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:19:57 +0300 Subject: [PATCH 13/24] SOLR-18390: reuse existing clients in six more cases Each needed a different route: node-level CoreAdmin calls take the jetty's own client, a core-scoped query takes getSolrClient(Replica), a node named by nodeName takes getJetty(name), and the two _stateVer_ cases wrap the node's client in CollectionScopedSolrClient to keep addressing by collection. --- .../org/apache/solr/TestCpuTimeSearch.java | 6 +- .../cloud/DistributedVersionInfoTest.java | 46 ++++++------ .../apache/solr/cloud/ReplaceNodeTest.java | 14 ++-- .../solrj/impl/CloudHttp2SolrClientTest.java | 75 +++++++++---------- ...ctCollectionsAPIDistributedZkTestBase.java | 16 ++-- 5 files changed, 73 insertions(+), 84 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java b/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java index 7bea9335dcb9..fec884f0afa2 100644 --- a/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java +++ b/solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java @@ -18,9 +18,7 @@ import java.io.IOException; import java.util.List; -import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -101,9 +99,7 @@ public void testWithoutDistrib() throws SolrServerException, IOException { coll.getSlices().stream() .flatMap(s -> s.getReplicas().stream()) .toArray(Replica[]::new)); - try (SolrClient client = new HttpJettySolrClient.Builder(randomReplica.getCoreUrl()).build()) { - response = client.query(query); - } + response = cluster.getSolrClient(randomReplica).query(query); SolrDocumentList results = response.getResults(); int size = results.size(); diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java index 859f551dfab0..5ddd464c70bb 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java @@ -34,7 +34,6 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; @@ -367,30 +366,31 @@ protected Long assertDocExists(SolrClient solr, String docId, Long expVers) thro protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { String coreName = replica.getCoreName(); boolean reloadedOk = false; - try (SolrClient client = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) { - CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); - long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); - - Thread.sleep(1000); - - // send reload command for the collection - log.info("Sending RELOAD command for {}", testCollectionName); - CollectionAdminRequest.reloadCollection(testCollectionName).process(client); - Thread.sleep(2000); // reload can take a short while - - // verify reload is done, waiting up to 30 seconds for slow test environments - long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS); - while (System.nanoTime() < timeout) { - statusResp = CoreAdminRequest.getStatus(coreName, client); - long startTimeAfterReload = statusResp.getStartTime(coreName).getTime(); - if (startTimeAfterReload > leaderCoreStartTime) { - reloadedOk = true; - break; - } - // else ... still waiting to see the reloaded core report a later start time - Thread.sleep(1000); + // CoreAdmin is a node-level API, so the node's own client is what we want here + SolrClient client = cluster.getReplicaJetty(replica).getSolrClient(); + CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); + long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); + + Thread.sleep(1000); + + // send reload command for the collection + log.info("Sending RELOAD command for {}", testCollectionName); + CollectionAdminRequest.reloadCollection(testCollectionName).process(client); + Thread.sleep(2000); // reload can take a short while + + // verify reload is done, waiting up to 30 seconds for slow test environments + long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS); + while (System.nanoTime() < timeout) { + statusResp = CoreAdminRequest.getStatus(coreName, client); + long startTimeAfterReload = statusResp.getStartTime(coreName).getTime(); + if (startTimeAfterReload > leaderCoreStartTime) { + reloadedOk = true; + break; } + // else ... still waiting to see the reloaded core report a later start time + Thread.sleep(1000); } + return reloadedOk; } } diff --git a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java index 7b77f91fc988..0058e4a432f0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java @@ -138,14 +138,12 @@ public void test() throws Exception { replaceNodeRequest.setWaitForFinalState(true); replaceNodeRequest.processAndWait("001", cloudClient, 10); - try (SolrClient coreClient = - new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(emptyNode)).build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); - assertEquals( - "Expecting no cores but found some: " + status.getCoreStatus(), - 0, - status.getCoreStatus().size()); - } + SolrClient coreClient = cluster.getJetty(emptyNode).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); + assertEquals( + "Expecting no cores but found some: " + status.getCoreStatus(), + 0, + status.getCoreStatus().size()); collection = cluster.getSolrClient().getClusterState().getCollection(coll); assertEquals(create.getNumShards().intValue(), collection.getSlices().size()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java index 63aca849dab3..1bf9e162e1bb 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java @@ -834,34 +834,33 @@ public void stateVersionParamTest() throws Exception { SolrQuery q = new SolrQuery().setQuery("*:*"); RemoteSolrException sse = null; - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(r.getBaseUrl()).withDefaultCollection(COLLECTION).build()) { + // addressed by collection (not core) on purpose: that is what exercises _stateVer_ + SolrClient solrClient = + new CollectionScopedSolrClient(cluster.getReplicaJetty(r).getSolrClient(), COLLECTION); - if (log.isInfoEnabled()) { - log.info("should work query, result {}", solrClient.query(q)); - } - // no problem - q.setParam(CloudSolrClient.STATE_VERSION, COLLECTION + ":" + coll.getZNodeVersion()); - if (log.isInfoEnabled()) { - log.info("2nd query , result {}", solrClient.query(q)); - } - // no error yet good - - q.setParam( - CloudSolrClient.STATE_VERSION, - COLLECTION + ":" + (coll.getZNodeVersion() - 1)); // an older version expect error - - QueryResponse rsp = solrClient.query(q); - final NamedList response = rsp.getResponse(); - final int stateVersionIdx = - response.indexOf(CloudSolrClient.STATE_VERSION, response.size() - 1); - @SuppressWarnings({"rawtypes"}) - Map m = stateVersionIdx == -1 ? null : (Map) response.getVal(stateVersionIdx); - assertNotNull( - "Expected an extra information from server with the list of invalid collection states", - m); - assertNotNull(m.get(COLLECTION)); + if (log.isInfoEnabled()) { + log.info("should work query, result {}", solrClient.query(q)); } + // no problem + q.setParam(CloudSolrClient.STATE_VERSION, COLLECTION + ":" + coll.getZNodeVersion()); + if (log.isInfoEnabled()) { + log.info("2nd query , result {}", solrClient.query(q)); + } + // no error yet good + + q.setParam( + CloudSolrClient.STATE_VERSION, + COLLECTION + ":" + (coll.getZNodeVersion() - 1)); // an older version expect error + + QueryResponse rsp = solrClient.query(q); + final NamedList response = rsp.getResponse(); + final int stateVersionIdx = + response.indexOf(CloudSolrClient.STATE_VERSION, response.size() - 1); + @SuppressWarnings({"rawtypes"}) + Map m = stateVersionIdx == -1 ? null : (Map) response.getVal(stateVersionIdx); + assertNotNull( + "Expected an extra information from server with the list of invalid collection states", m); + assertNotNull(m.get(COLLECTION)); // now send the request to another node that does not serve the collection @@ -883,20 +882,20 @@ public void stateVersionParamTest() throws Exception { log.info("the node which does not serve this collection{} ", theNode); assertNotNull(theNode); - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(theNode).withDefaultCollection(COLLECTION).build()) { + // this node has no replica of the collection, so it is addressed by node rather than replica + SolrClient otherNodeClient = + new CollectionScopedSolrClient(cluster.getJetty(theNode).getSolrClient(), COLLECTION); - q.setParam(CloudSolrClient.STATE_VERSION, COLLECTION + ":" + (coll.getZNodeVersion() - 1)); - try { - QueryResponse rsp = solrClient.query(q); - log.info("error was expected"); - } catch (RemoteSolrException e) { - sse = e; - } - assertNotNull(sse); - assertEquals( - " Error code should be 510", SolrException.ErrorCode.INVALID_STATE.code, sse.code()); + q.setParam(CloudSolrClient.STATE_VERSION, COLLECTION + ":" + (coll.getZNodeVersion() - 1)); + try { + otherNodeClient.query(q); + log.info("error was expected"); + } catch (RemoteSolrException e) { + sse = e; } + assertNotNull(sse); + assertEquals( + " Error code should be 510", SolrException.ErrorCode.INVALID_STATE.code, sse.code()); } @Test diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java index 9aabb9d0d361..362a5fd69c6c 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java @@ -39,7 +39,6 @@ import org.apache.solr.client.solrj.SolrRequest.METHOD; import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; @@ -561,9 +560,8 @@ private void collectStartTimes(String collectionName, Map urlToTim for (Slice shard : collectionState) { for (Replica replica : shard) { CoreStatusResponse.SingleCoreData coreStatus; - try (SolrClient server = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) { - coreStatus = CoreAdminRequest.getCoreStatus(replica.getCoreName(), false, server); - } + SolrClient server = cluster.getReplicaJetty(replica).getSolrClient(); + coreStatus = CoreAdminRequest.getCoreStatus(replica.getCoreName(), false, server); long before = coreStatus.startTime.getTime(); urlToTime.put(replica.getCoreUrl(), before); } @@ -641,12 +639,10 @@ public void addReplicaTest() throws Exception { assertNotNull(newReplica); cluster.waitForActiveCollection(collectionName, 2, 6); - try (SolrClient coreclient = new HttpJettySolrClient.Builder(newReplica.getBaseUrl()).build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); - final var coreStatus = status.getCoreStatus(newReplica.getStr("core")); - String instanceDirStr = coreStatus.instanceDir; - assertEquals(instanceDirStr, instancePath.toString()); - } + SolrClient coreclient = cluster.getReplicaJetty(newReplica).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); + final var coreStatus = status.getCoreStatus(newReplica.getStr("core")); + assertEquals(coreStatus.instanceDir, instancePath.toString()); // Test to make sure we can't create another replica with an existing core_name of that // collection From c45ad533f02c69b89ab20b6dc523a1fdb86b2edb Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:34:50 +0300 Subject: [PATCH 14/24] SOLR-18390: reuse node clients for the per-node test client sets MigrateReplicasTest/ReplaceNodeTest/TestCoordinatorRole address a node by name or URL, so they take getJetty(...).getSolrClient(). The two tests that keep a set of per-node collection-scoped clients now wrap the nodes' own clients, so their @AfterClass no longer closes them. --- .../solr/cloud/MigrateReplicasTest.java | 32 +++++------- .../apache/solr/cloud/ReplaceNodeTest.java | 20 +++---- .../solr/cloud/TestCloudDeleteByQuery.java | 52 ++++++------------- .../TestTolerantUpdateProcessorCloud.java | 32 ++++-------- .../solr/search/TestCoordinatorRole.java | 45 ++++++++-------- 5 files changed, 68 insertions(+), 113 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java b/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java index b05e198daa5b..a72e991690fc 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateReplicasTest.java @@ -29,14 +29,12 @@ import org.apache.solr.client.api.model.MigrateReplicasRequestBody; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.util.StrUtils; import org.apache.solr.common.util.Utils; import org.apache.solr.core.CoreContainer; @@ -123,16 +121,12 @@ public void test() throws Exception { "MigrateReplicas request was unsuccessful", 0L, ((Map) response.get("responseHeader")).get("status")); - ZkStateReader zkStateReader = ZkStateReader.from(cloudClient); - try (SolrClient coreClient = - new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned)) - .build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); - assertEquals( - "There should not be any cores left on decommissioned node", - 0, - status.getCoreStatus().size()); - } + SolrClient coreClient = cluster.getJetty(nodeToBeDecommissioned).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); + assertEquals( + "There should not be any cores left on decommissioned node", + 0, + status.getCoreStatus().size()); Thread.sleep(5000); collection = cloudClient.getClusterState().getCollectionOrNull(coll, false); @@ -152,14 +146,12 @@ public void test() throws Exception { 0L, ((Map) response.get("responseHeader")).get("status")); - try (SolrClient coreClient = - new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(emptyNode)).build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); - assertEquals( - "Expecting no cores but found some: " + status.getCoreStatus(), - 0, - status.getCoreStatus().size()); - } + SolrClient emptyNodeClient = cluster.getJetty(emptyNode).getSolrClient(); + CoreAdminResponse emptyNodeStatus = CoreAdminRequest.getStatus(null, emptyNodeClient); + assertEquals( + "Expecting no cores but found some: " + emptyNodeStatus.getCoreStatus(), + 0, + emptyNodeStatus.getCoreStatus().size()); collection = cluster.getSolrClient().getClusterState().getCollection(coll); assertEquals(create.getNumShards().intValue(), collection.getSlices().size()); diff --git a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java index 0058e4a432f0..fac7fe5928e6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ReplaceNodeTest.java @@ -29,7 +29,6 @@ import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.response.CoreAdminResponse; @@ -37,7 +36,6 @@ import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.params.CollectionParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.SolrParams; @@ -117,13 +115,9 @@ public void test() throws Exception { log.info("excluded_node : {} ", emptyNode); createReplaceNodeRequest(nodeToBeDecommissioned, emptyNode, null) .processAndWait("000", cloudClient, 15); - ZkStateReader zkStateReader = ZkStateReader.from(cloudClient); - try (SolrClient coreClient = - new HttpJettySolrClient.Builder(zkStateReader.getBaseUrlForNodeName(nodeToBeDecommissioned)) - .build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); - assertEquals(0, status.getCoreStatus().size()); - } + SolrClient coreClient = cluster.getJetty(nodeToBeDecommissioned).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); + assertEquals(0, status.getCoreStatus().size()); Thread.sleep(5000); collection = cloudClient.getClusterState().getCollection(coll); @@ -138,12 +132,12 @@ public void test() throws Exception { replaceNodeRequest.setWaitForFinalState(true); replaceNodeRequest.processAndWait("001", cloudClient, 10); - SolrClient coreClient = cluster.getJetty(emptyNode).getSolrClient(); - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreClient); + SolrClient emptyNodeClient = cluster.getJetty(emptyNode).getSolrClient(); + CoreAdminResponse emptyNodeStatus = CoreAdminRequest.getStatus(null, emptyNodeClient); assertEquals( - "Expecting no cores but found some: " + status.getCoreStatus(), + "Expecting no cores but found some: " + emptyNodeStatus.getCoreStatus(), 0, - status.getCoreStatus().size()); + emptyNodeStatus.getCoreStatus().size()); collection = cluster.getSolrClient().getClusterState().getCollection(coll); assertEquals(create.getNumShards().intValue(), collection.getSlices().size()); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java index 7fe47d4af206..c5fe0b43e987 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java @@ -27,7 +27,7 @@ import java.util.UUID; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.common.SolrDocument; @@ -89,26 +89,11 @@ public static void afterClass() throws Exception { COLLECTION_CLIENT.close(); COLLECTION_CLIENT = null; } - if (null != S_ONE_LEADER_CLIENT) { - S_ONE_LEADER_CLIENT.close(); - S_ONE_LEADER_CLIENT = null; - } - if (null != S_TWO_LEADER_CLIENT) { - S_TWO_LEADER_CLIENT.close(); - S_TWO_LEADER_CLIENT = null; - } - if (null != S_ONE_NON_LEADER_CLIENT) { - S_ONE_NON_LEADER_CLIENT.close(); - S_ONE_NON_LEADER_CLIENT = null; - } - if (null != S_TWO_NON_LEADER_CLIENT) { - S_TWO_NON_LEADER_CLIENT.close(); - S_TWO_NON_LEADER_CLIENT = null; - } - if (null != NO_COLLECTION_CLIENT) { - NO_COLLECTION_CLIENT.close(); - NO_COLLECTION_CLIENT = null; - } + S_ONE_LEADER_CLIENT = null; + S_TWO_LEADER_CLIENT = null; + S_ONE_NON_LEADER_CLIENT = null; + S_TWO_NON_LEADER_CLIENT = null; + NO_COLLECTION_CLIENT = null; } @BeforeClass @@ -168,31 +153,26 @@ public static void createMiniSolrCloudCluster() throws Exception { if (shardName.equals("shard1")) { S_ONE_LEADER_CLIENT = - new HttpJettySolrClient.Builder(leaderUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(leaderUrl).getSolrClient(), COLLECTION_NAME); S_ONE_NON_LEADER_CLIENT = - new HttpJettySolrClient.Builder(passiveUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(passiveUrl).getSolrClient(), COLLECTION_NAME); } else if (shardName.equals("shard2")) { S_TWO_LEADER_CLIENT = - new HttpJettySolrClient.Builder(leaderUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(leaderUrl).getSolrClient(), COLLECTION_NAME); S_TWO_NON_LEADER_CLIENT = - new HttpJettySolrClient.Builder(passiveUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(passiveUrl).getSolrClient(), COLLECTION_NAME); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (not hosting either shard)", 1, urlMap.size()); NO_COLLECTION_CLIENT = - new HttpJettySolrClient.Builder(urlMap.values().iterator().next()) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(urlMap.values().iterator().next()).getSolrClient(), COLLECTION_NAME); assertNotNull(S_ONE_LEADER_CLIENT); assertNotNull(S_TWO_LEADER_CLIENT); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java index bbbcafc1a3b8..107f7b273b3d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java @@ -27,7 +27,7 @@ import java.util.Set; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.UpdateResponse; @@ -147,31 +147,26 @@ public static void createMiniSolrCloudCluster() throws Exception { if (shardName.equals("shard1")) { S_ONE_LEADER_CLIENT = - new HttpJettySolrClient.Builder(leaderUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(leaderUrl).getSolrClient(), COLLECTION_NAME); S_ONE_NON_LEADER_CLIENT = - new HttpJettySolrClient.Builder(passiveUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(passiveUrl).getSolrClient(), COLLECTION_NAME); } else if (shardName.equals("shard2")) { S_TWO_LEADER_CLIENT = - new HttpJettySolrClient.Builder(leaderUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(leaderUrl).getSolrClient(), COLLECTION_NAME); S_TWO_NON_LEADER_CLIENT = - new HttpJettySolrClient.Builder(passiveUrl) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(passiveUrl).getSolrClient(), COLLECTION_NAME); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (not hosting either shard)", 1, urlMap.size()); NO_COLLECTION_CLIENT = - new HttpJettySolrClient.Builder(urlMap.values().iterator().next()) - .withDefaultCollection(COLLECTION_NAME) - .build(); + new CollectionScopedSolrClient( + cluster.getJetty(urlMap.values().iterator().next()).getSolrClient(), COLLECTION_NAME); assertNotNull(S_ONE_LEADER_CLIENT); assertNotNull(S_TWO_LEADER_CLIENT); @@ -220,15 +215,10 @@ public static void createMiniSolrCloudCluster() throws Exception { @AfterClass public static void afterClass() throws IOException { - close(S_ONE_LEADER_CLIENT); S_ONE_LEADER_CLIENT = null; - close(S_TWO_LEADER_CLIENT); S_TWO_LEADER_CLIENT = null; - close(S_ONE_NON_LEADER_CLIENT); S_ONE_NON_LEADER_CLIENT = null; - close(S_TWO_NON_LEADER_CLIENT); S_TWO_NON_LEADER_CLIENT = null; - close(NO_COLLECTION_CLIENT); NO_COLLECTION_CLIENT = null; close(COLLECTION_CLIENT); COLLECTION_CLIENT = null; diff --git a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java index bf19ded6ad7e..3019cf48fd60 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java +++ b/solr/core/src/test/org/apache/solr/search/TestCoordinatorRole.java @@ -35,7 +35,6 @@ import java.util.stream.Collectors; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -462,31 +461,31 @@ private String getHostCoreName(String COLL, String qaNode, Consumer p CommonParams.JAVABIN); p.accept(q); SolrDocumentList docs = null; - try (SolrClient solrClient = new HttpJettySolrClient.Builder(qaNode).build()) { - for (int i = 0; i < 100; i++) { - try { - QueryResponse queryResponse = solrClient.query(COLL, q); - docs = queryResponse.getResults(); - assertNotNull("Docs should not be null. Query response was: " + queryResponse, docs); - if (docs.size() > 0) { - found = true; - break; - } - } catch (SolrException ex) { - // we know we're doing tricky things that might cause transient errors - // TODO: all these query requests go to the QA node -- should QA propagate internal - // request errors to the external client (and the external client retry?) or should QA - // attempt to failover transparently in the event of an error? - if (i < 5) { - log.info("swallowing transient error", ex); - } else { - log.error("only expect actual _errors_ within a small window (e.g. 500ms)", ex); - fail("initial error time threshold exceeded"); - } + SolrClient solrClient = cluster.getJetty(qaNode).getSolrClient(); + for (int i = 0; i < 100; i++) { + try { + QueryResponse queryResponse = solrClient.query(COLL, q); + docs = queryResponse.getResults(); + assertNotNull("Docs should not be null. Query response was: " + queryResponse, docs); + if (docs.size() > 0) { + found = true; + break; + } + } catch (SolrException ex) { + // we know we're doing tricky things that might cause transient errors + // TODO: all these query requests go to the QA node -- should QA propagate internal + // request errors to the external client (and the external client retry?) or should QA + // attempt to failover transparently in the event of an error? + if (i < 5) { + log.info("swallowing transient error", ex); + } else { + log.error("only expect actual _errors_ within a small window (e.g. 500ms)", ex); + fail("initial error time threshold exceeded"); } - Thread.sleep(100); } + Thread.sleep(100); } + assertTrue(found); return (String) docs.get(0).getFieldValue("_core_"); } From 95d6d392b2d6abc2b3dfd964f9bea099eb438a0e Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:36:44 +0300 Subject: [PATCH 15/24] SOLR-18390: node client for the core-snapshot admin calls --- .../snapshots/TestSolrCloudSnapshots.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java index c3110bff329c..2c417d6226e2 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java @@ -29,7 +29,6 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots; import org.apache.solr.client.solrj.response.CollectionAdminResponse; @@ -152,20 +151,19 @@ public void testSnapshots() throws Exception { continue; // We know that the snapshot is not created for this replica. } - String replicaBaseUrl = replica.getBaseUrl(); String coreName = replica.getCoreName(); assertTrue(snapshotByCoreName.containsKey(coreName)); CoreSnapshotMetaData coreSnapshot = snapshotByCoreName.get(coreName); - try (SolrClient adminClient = new HttpJettySolrClient.Builder(replicaBaseUrl).build()) { - Collection snapshots = listCoreSnapshots(adminClient, coreName); - Optional metaData = - snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); - assertTrue("Snapshot not created for core " + coreName, metaData.isPresent()); - assertEquals(coreSnapshot.getIndexDirPath(), metaData.get().getIndexDirPath()); - assertEquals(coreSnapshot.getGenerationNumber(), metaData.get().getGenerationNumber()); - } + // listing core snapshots is a node-level admin call + SolrClient adminClient = cluster.getReplicaJetty(replica).getSolrClient(); + Collection snapshots = listCoreSnapshots(adminClient, coreName); + Optional metaData = + snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); + assertTrue("Snapshot not created for core " + coreName, metaData.isPresent()); + assertEquals(coreSnapshot.getIndexDirPath(), metaData.get().getIndexDirPath()); + assertEquals(coreSnapshot.getGenerationNumber(), metaData.get().getGenerationNumber()); } } @@ -274,17 +272,15 @@ public void testSnapshots() throws Exception { continue; // We know that the snapshot was not created for this replica. } - String replicaBaseUrl = replica.getBaseUrl(); String coreName = replica.getCoreName(); - try (SolrClient adminClient = new HttpJettySolrClient.Builder(replicaBaseUrl).build()) { - Collection snapshots = listCoreSnapshots(adminClient, coreName); - Optional metaData = - snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); - assertFalse("Snapshot not deleted for core " + coreName, metaData.isPresent()); - // Remove the entry for core if the snapshot is deleted successfully. - snapshotByCoreName.remove(coreName); - } + SolrClient adminClient = cluster.getReplicaJetty(replica).getSolrClient(); + Collection snapshots = listCoreSnapshots(adminClient, coreName); + Optional metaData = + snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); + assertFalse("Snapshot not deleted for core " + coreName, metaData.isPresent()); + // Remove the entry for core if the snapshot is deleted successfully. + snapshotByCoreName.remove(coreName); } } From 096dab014f0cbdac59ce8bb9096eeebbea6d82bf Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:44:26 +0300 Subject: [PATCH 16/24] SOLR-18390: take clients from SolrClientTestRule where it already has one TestPrometheusResponseWriter's six metrics calls and one of the bad-input cases are node-level, so they use getAdminClient(); the collection-scoped bad-input case uses getSolrClient(collection). --- .../TestPrometheusResponseWriter.java | 161 ++++++++---------- .../impl/HttpSolrClientBadInputTest.java | 106 ++++++------ 2 files changed, 124 insertions(+), 143 deletions(-) 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 88bf8a94f40f..3c6032df1290 100644 --- a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java @@ -28,7 +28,6 @@ import java.util.Set; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.MetricsRequest; import org.apache.solr.client.solrj.response.InputStreamResponseParser; import org.apache.solr.common.params.ModifiableSolrParams; @@ -69,48 +68,46 @@ public void testPrometheusStructureOutput() throws Exception { params.set("wt", "prometheus"); var req = new MetricsRequest(params); // response parser set in MetricsRequest constructor - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); - String output = InputStreamResponseParser.consumeResponseToString(res); - - Set seenTypeInfo = new HashSet<>(); - - List filteredResponse = - output - .lines() - .filter( - line -> { - if (!line.startsWith("#")) { - return true; - } - assertTrue( - "Prometheus exposition format cannot have duplicate TYPE information", - seenTypeInfo.add(line)); - return false; - }) - .toList(); - filteredResponse.forEach( - (actualMetric) -> { - String actualValue; - if (actualMetric.contains("}")) { - actualValue = actualMetric.substring(actualMetric.lastIndexOf("} ") + 1); - } else { - actualValue = actualMetric.split(" ")[1]; - } - if (actualMetric.startsWith("target_info")) { - // Skip standard OTEL metric - return; - } - assertTrue("All metrics should start with 'solr_'", actualMetric.startsWith("solr_")); - try { - Float.parseFloat(actualValue); - } catch (NumberFormatException e) { - log.warn("Prometheus value not a parsable float"); - assertTrue(VALID_PROMETHEUS_VALUES.contains(actualValue)); - } - }); - } + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); + String output = InputStreamResponseParser.consumeResponseToString(res); + + Set seenTypeInfo = new HashSet<>(); + + List filteredResponse = + output + .lines() + .filter( + line -> { + if (!line.startsWith("#")) { + return true; + } + assertTrue( + "Prometheus exposition format cannot have duplicate TYPE information", + seenTypeInfo.add(line)); + return false; + }) + .toList(); + filteredResponse.forEach( + (actualMetric) -> { + String actualValue; + if (actualMetric.contains("}")) { + actualValue = actualMetric.substring(actualMetric.lastIndexOf("} ") + 1); + } else { + actualValue = actualMetric.split(" ")[1]; + } + if (actualMetric.startsWith("target_info")) { + // Skip standard OTEL metric + return; + } + assertTrue("All metrics should start with 'solr_'", actualMetric.startsWith("solr_")); + try { + Float.parseFloat(actualValue); + } catch (NumberFormatException e) { + log.warn("Prometheus value not a parsable float"); + assertTrue(VALID_PROMETHEUS_VALUES.contains(actualValue)); + } + }); } @Test @@ -121,16 +118,14 @@ public void testAcceptHeaderOpenMetricsFormat() throws Exception { req.addHeader("Accept", "application/openmetrics-text;version=1.0.0"); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); - try (InputStream in = (InputStream) res.get(STREAM_KEY)) { - String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); - assertTrue( - "Should use OpenMetrics format when Accept header is set", - output.trim().endsWith("# EOF")); - } + try (InputStream in = (InputStream) res.get(STREAM_KEY)) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + assertTrue( + "Should use OpenMetrics format when Accept header is set", + output.trim().endsWith("# EOF")); } } @@ -140,16 +135,14 @@ public void testWtParameterOpenMetricsFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("openmetrics")); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); - try (InputStream in = (InputStream) res.get(STREAM_KEY)) { - String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); - assertTrue( - "Should use OpenMetrics format when wt=openmetrics is set", - output.trim().endsWith("# EOF")); - } + try (InputStream in = (InputStream) res.get(STREAM_KEY)) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + assertTrue( + "Should use OpenMetrics format when wt=openmetrics is set", + output.trim().endsWith("# EOF")); } } @@ -159,16 +152,14 @@ public void testDefaultPrometheusFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("prometheus")); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); - try (InputStream in = (InputStream) res.get(STREAM_KEY)) { - String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); - assertFalse( - "Should use Prometheus format when wt=prometheus is set", - output.trim().endsWith("# EOF")); - } + try (InputStream in = (InputStream) res.get(STREAM_KEY)) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + assertFalse( + "Should use Prometheus format when wt=prometheus is set", + output.trim().endsWith("# EOF")); } } @@ -178,16 +169,14 @@ public void testDefaultPrometheusFormatNoWtParam() throws Exception { req.setResponseParser(new InputStreamResponseParser(null)); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); - try (InputStream in = (InputStream) res.get(STREAM_KEY)) { - String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); - assertFalse( - "Should default to Prometheus format when no wt parameter is set", - output.trim().endsWith("# EOF")); - } + try (InputStream in = (InputStream) res.get(STREAM_KEY)) { + String output = new String(in.readAllBytes(), StandardCharsets.UTF_8); + assertFalse( + "Should default to Prometheus format when no wt parameter is set", + output.trim().endsWith("# EOF")); } } @@ -197,13 +186,11 @@ public void testUnsupportedMetricsFormat() throws Exception { req.setResponseParser(new InputStreamResponseParser("unknownFormat")); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - NamedList res = adminClient.request(req); - InputStream stream = (InputStream) res.get("stream"); - if (stream != null) stream.close(); - // Unknown wt parameter should return a 400 error - assertEquals(400, res.get("responseStatus")); - } + SolrClient adminClient = solrTestRule.getAdminClient(); + NamedList res = adminClient.request(req); + InputStream stream = (InputStream) res.get("stream"); + if (stream != null) stream.close(); + // Unknown wt parameter should return a 400 error + assertEquals(400, res.get("responseStatus")); } } 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 0a1c81363e9a..edd136d35c62 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 @@ -23,7 +23,6 @@ import java.util.List; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.common.util.EnvUtils; import org.apache.solr.util.ExternalPaths; import org.apache.solr.util.SolrJettyTestRule; @@ -51,61 +50,56 @@ public static void beforeTest() throws Exception { @Test public void testDeleteByIdReportsInvalidIdLists() throws Exception { - try (SolrClient client = - new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()) - .withDefaultCollection(ANY_COLLECTION) - .build()) { - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "null"), - () -> { - client.deleteById(NULL_STR_LIST); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "empty"), - () -> { - client.deleteById(EMPTY_STR_LIST); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "null"), - () -> { - client.deleteById(NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "empty"), - () -> { - client.deleteById(EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME); - }); - } + SolrClient client = solrTestRule.getSolrClient(ANY_COLLECTION); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "null"), + () -> { + client.deleteById(NULL_STR_LIST); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "empty"), + () -> { + client.deleteById(EMPTY_STR_LIST); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "null"), + () -> { + client.deleteById(NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "empty"), + () -> { + client.deleteById(EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME); + }); - try (SolrClient client = new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl()).build()) { - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "null"), - () -> { - client.deleteById(ANY_COLLECTION, NULL_STR_LIST); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "empty"), - () -> { - client.deleteById(ANY_COLLECTION, EMPTY_STR_LIST); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "null"), - () -> { - client.deleteById(ANY_COLLECTION, NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME); - }); - assertExceptionThrownWithMessageContaining( - IllegalArgumentException.class, - List.of("ids", "empty"), - () -> { - client.deleteById(ANY_COLLECTION, EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME); - }); - } + SolrClient adminClient = solrTestRule.getAdminClient(); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "null"), + () -> { + adminClient.deleteById(ANY_COLLECTION, NULL_STR_LIST); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "empty"), + () -> { + adminClient.deleteById(ANY_COLLECTION, EMPTY_STR_LIST); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "null"), + () -> { + adminClient.deleteById(ANY_COLLECTION, NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME); + }); + assertExceptionThrownWithMessageContaining( + IllegalArgumentException.class, + List.of("ids", "empty"), + () -> { + adminClient.deleteById(ANY_COLLECTION, EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME); + }); } } From a568933a6d5b6de9484bfb10e2ef9c515d1cfe12 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:53:57 +0300 Subject: [PATCH 17/24] SOLR-18390: reuse jetty clients for the per-node client lists Two tests that build one client per runner now wrap the runner's own client, so their @AfterClass no longer closes them. UpdateLogCloudTest keeps its own because it restarts a node, which the cached client does not survive. --- .../TestStressCloudBlindAtomicUpdates.java | 17 +++-------------- .../TestTolerantUpdateProcessorRandomCloud.java | 15 +++------------ .../handler/component/UpdateLogCloudTest.java | 2 ++ .../solrj/impl/CloudHttp2SolrClientTest.java | 11 +++++------ 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java b/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java index 79dd2341cce1..d9297f2d2068 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestStressCloudBlindAtomicUpdates.java @@ -17,7 +17,6 @@ package org.apache.solr.cloud; import java.lang.invoke.MethodHandles; -import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -33,7 +32,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest.Field; @@ -140,12 +139,7 @@ public static void createMiniSolrCloudCluster() throws Exception { CLIENTS.clear(); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { assertNotNull("Cluster contains null jetty?", jetty); - final URL baseUrl = jetty.getBaseUrl(); - assertNotNull("Jetty has null baseUrl: " + jetty, baseUrl); - CLIENTS.add( - new HttpJettySolrClient.Builder(baseUrl.toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + CLIENTS.add(new CollectionScopedSolrClient(jetty.getSolrClient(), COLLECTION_NAME)); } // sanity check no one broke the assumptions we make about our schema @@ -170,12 +164,7 @@ public static void afterClass() { IOUtils.closeQuietly(COLLECTION_CLIENT); COLLECTION_CLIENT = null; } - for (SolrClient client : CLIENTS) { - if (null == client) { - log.error("CLIENTS contains a null SolrClient???"); - } - IOUtils.closeQuietly(client); - } + // the jettys own these clients CLIENTS.clear(); } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java index 253a90206f60..c96a633577b5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.lang.invoke.MethodHandles; -import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; import java.util.BitSet; @@ -39,7 +38,7 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -115,11 +114,7 @@ public static void createMiniSolrCloudCluster() throws Exception { NODE_CLIENTS = new ArrayList(numServers); for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { - URL jettyURL = jetty.getBaseUrl(); - NODE_CLIENTS.add( - new HttpJettySolrClient.Builder(jettyURL.toString()) - .withDefaultCollection(COLLECTION_NAME) - .build()); + NODE_CLIENTS.add(new CollectionScopedSolrClient(jetty.getSolrClient(), COLLECTION_NAME)); } assertEquals(numServers, NODE_CLIENTS.size()); } @@ -137,11 +132,7 @@ public void deleteAllDocs() throws Exception { @AfterClass public static void afterClass() throws IOException { - if (NODE_CLIENTS != null) { - for (SolrClient client : NODE_CLIENTS) { - client.close(); - } - } + // the jettys own these clients NODE_CLIENTS = null; if (COLLECTION_CLIENT != null) { COLLECTION_CLIENT.close(); diff --git a/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java b/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java index 4077b78cbd5a..cf44fc093008 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/UpdateLogCloudTest.java @@ -91,6 +91,8 @@ public void test() throws Exception { .equals(getCollectionState(COLLECTION).getLeader("shard1").getBaseUrl())) { specialIdx = solrClients.size(); } + // own clients on purpose: this test stops and restarts a node, which the runner's + // cached client does not survive solrClients.add( new HttpJettySolrClient.Builder(jettySolrRunner.getBaseUrl().toString()).build()); } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java index 1bf9e162e1bb..5e4a4e59a8f0 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java @@ -395,12 +395,11 @@ public void testRouting() throws Exception { params.add("distrib", "false"); QueryRequest queryRequest = new QueryRequest(params); - try (SolrClient solrClient = - new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(coreName).build()) { - QueryResponse queryResponse = queryRequest.process(solrClient); - SolrDocumentList docList = queryResponse.getResults(); - assertEquals(1, docList.getNumFound()); - } + SolrClient solrClient = + new CollectionScopedSolrClient(cluster.getJetty(baseUrl).getSolrClient(), coreName); + QueryResponse queryResponse = queryRequest.process(solrClient); + SolrDocumentList docList = queryResponse.getResults(); + assertEquals(1, docList.getNumFound()); } // Test the deleteById routing for UpdateRequest From f170655190359369b22045c2cd4adcc7474979bd Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 10:58:07 +0300 Subject: [PATCH 18/24] SOLR-18390: UnloadDistributedZkTest takes the runner's admin client --- .../solr/cloud/UnloadDistributedZkTest.java | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java index 9a176b1cb8cd..c79fa27b77a5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -32,7 +32,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload; import org.apache.solr.common.SolrInputDocument; @@ -156,30 +155,22 @@ private void testUnloadShardAndCollection() throws Exception { final String unloadCmdCoreName1 = (unloadInOrder ? coreName1 : coreName2); final String unloadCmdCoreName2 = (unloadInOrder ? coreName2 : coreName1); - try (SolrClient adminClient = - new HttpJettySolrClient.Builder(buildUrl(jettys.get(0).getLocalPort())).build()) { - // now unload one of the two - Unload unloadCmd = new Unload(false); - unloadCmd.setCoreName(unloadCmdCoreName1); - adminClient.request(unloadCmd); - - // there should still be two shards (as of SOLR-5209) - checkCoreNamePresenceAndSliceCount( - collection, - unloadCmdCoreName1, - false /* shouldBePresent */, - numShards /* expectedSliceCount */); - - // now unload one of the other - unloadCmd = new Unload(false); - unloadCmd.setCoreName(unloadCmdCoreName2); - adminClient.request(unloadCmd); - checkCoreNamePresenceAndSliceCount( - collection, - unloadCmdCoreName2, - false /* shouldBePresent */, - numShards /* expectedSliceCount */); - } + SolrClient adminClient = jettys.get(0).getSolrClient(); + // now unload one of the two + Unload unloadCmd = new Unload(false); + unloadCmd.setCoreName(unloadCmdCoreName1); + adminClient.request(unloadCmd); + + // there should still be two shards (as of SOLR-5209) + checkCoreNamePresenceAndSliceCount( + collection, unloadCmdCoreName1, false /* shouldBePresent */, numShards); + + // now unload one of the other + unloadCmd = new Unload(false); + unloadCmd.setCoreName(unloadCmdCoreName2); + adminClient.request(unloadCmd); + checkCoreNamePresenceAndSliceCount( + collection, unloadCmdCoreName2, false /* shouldBePresent */, numShards); // printLayout(); // the collection should still be present (as of SOLR-5209 replica removal does not cascade to From d3ec77eb298955233182190c05203215441c5be2 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:15:27 +0300 Subject: [PATCH 19/24] SOLR-18390: ShardSplitTest takes the node's client; include controlJetty in lookups AbstractFullDistribZkTestBase keeps controlJetty outside jettys, so a replica hosted there was unresolvable -- ShardSplitTest only surfaced it under -Ptests.nightly=true. Both lookups now search every runner. --- .../cloud/api/collections/ShardSplitTest.java | 244 +++++++++--------- .../cloud/AbstractFullDistribZkTestBase.java | 17 +- .../solr/cloud/MiniSolrCloudCluster.java | 7 +- 3 files changed, 143 insertions(+), 125 deletions(-) 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 4c0ca599e31d..6603558432c4 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 @@ -43,7 +43,7 @@ import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.impl.CollectionScopedSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -966,52 +966,51 @@ public void splitByRouteFieldTest() throws Exception { getCommonCloudSolrClient(); String baseUrl = getBaseUrlFromZk(cloudClient.getClusterState(), collectionName); - try (SolrClient collectionClient = - new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(collectionName).build()) { - - ClusterState clusterState = cloudClient.getClusterState(); - final DocRouter router = clusterState.getCollection(collectionName).getRouter(); - Slice shard1 = clusterState.getCollection(collectionName).getSlice(SHARD1); - DocRouter.Range shard1Range = - shard1.getRange() != null ? shard1.getRange() : router.fullRange(); - final List ranges = router.partitionRange(2, shard1Range); - final int[] docCounts = new int[ranges.size()]; - - for (int i = 100; i <= 200; i++) { - // See comment in ShardRoutingTest for hash distribution - String shardKey = "" + (char) ('a' + (i % 26)); - - collectionClient.add(getDoc(id, i, "n_ti", i, shard_fld, shardKey)); - int idx = getHashRangeIdx(router, ranges, shardKey); - if (idx != -1) { - docCounts[idx]++; - } - } + SolrClient collectionClient = + new CollectionScopedSolrClient(getJetty(baseUrl).getSolrClient(), collectionName); + + ClusterState clusterState = cloudClient.getClusterState(); + final DocRouter router = clusterState.getCollection(collectionName).getRouter(); + Slice shard1 = clusterState.getCollection(collectionName).getSlice(SHARD1); + DocRouter.Range shard1Range = + shard1.getRange() != null ? shard1.getRange() : router.fullRange(); + final List ranges = router.partitionRange(2, shard1Range); + final int[] docCounts = new int[ranges.size()]; + + for (int i = 100; i <= 200; i++) { + // See comment in ShardRoutingTest for hash distribution + String shardKey = "" + (char) ('a' + (i % 26)); - for (int i = 0; i < docCounts.length; i++) { - int docCount = docCounts[i]; - log.info("Shard shard1_{} docCount = {}", i, docCount); + collectionClient.add(getDoc(id, i, "n_ti", i, shard_fld, shardKey)); + int idx = getHashRangeIdx(router, ranges, shardKey); + if (idx != -1) { + docCounts[idx]++; } + } - collectionClient.commit(); + for (int i = 0; i < docCounts.length; i++) { + int docCount = docCounts[i]; + log.info("Shard shard1_{} docCount = {}", i, docCount); + } - trySplit(collectionName, null, SHARD1, 3); + collectionClient.commit(); - waitForRecoveriesToFinish(collectionName, false); + trySplit(collectionName, null, SHARD1, 3); - assertEquals( - docCounts[0], - collectionClient - .query(new SolrQuery("*:*").setParam("shards", "shard1_0")) - .getResults() - .getNumFound()); - assertEquals( - docCounts[1], - collectionClient - .query(new SolrQuery("*:*").setParam("shards", "shard1_1")) - .getResults() - .getNumFound()); - } + waitForRecoveriesToFinish(collectionName, false); + + assertEquals( + docCounts[0], + collectionClient + .query(new SolrQuery("*:*").setParam("shards", "shard1_0")) + .getResults() + .getNumFound()); + assertEquals( + docCounts[1], + collectionClient + .query(new SolrQuery("*:*").setParam("shards", "shard1_1")) + .getResults() + .getNumFound()); } private void splitByRouteKeyTest() throws Exception { @@ -1038,93 +1037,92 @@ private void splitByRouteKeyTest() throws Exception { getCommonCloudSolrClient(); String baseUrl = getBaseUrlFromZk(cloudClient.getClusterState(), collectionName); - try (SolrClient collectionClient = - new HttpJettySolrClient.Builder(baseUrl).withDefaultCollection(collectionName).build()) { - - String splitKey = "b!"; - - ClusterState clusterState = cloudClient.getClusterState(); - final DocRouter router = clusterState.getCollection(collectionName).getRouter(); - Slice shard1 = clusterState.getCollection(collectionName).getSlice(SHARD1); - DocRouter.Range shard1Range = - shard1.getRange() != null ? shard1.getRange() : router.fullRange(); - final List ranges = - ((CompositeIdRouter) router).partitionRangeByKey(splitKey, shard1Range); - final int[] docCounts = new int[ranges.size()]; - - int uniqIdentifier = (1 << 12); - int splitKeyDocCount = 0; - for (int i = 100; i <= 200; i++) { - // See comment in ShardRoutingTest for hash distribution - String shardKey = "" + (char) ('a' + (i % 26)); - - String idStr = shardKey + "!" + i; - collectionClient.add( - getDoc(id, idStr, "n_ti", (shardKey + "!").equals(splitKey) ? uniqIdentifier : i)); - int idx = getHashRangeIdx(router, ranges, idStr); - if (idx != -1) { - docCounts[idx]++; - } - if (splitKey.equals(shardKey + "!")) splitKeyDocCount++; - } + SolrClient collectionClient = + new CollectionScopedSolrClient(getJetty(baseUrl).getSolrClient(), collectionName); - for (int i = 0; i < docCounts.length; i++) { - int docCount = docCounts[i]; - log.info("Shard shard1_{} docCount = {}", i, docCount); - } - log.info("Route key doc count = {}", splitKeyDocCount); + String splitKey = "b!"; - collectionClient.commit(); + ClusterState clusterState = cloudClient.getClusterState(); + final DocRouter router = clusterState.getCollection(collectionName).getRouter(); + Slice shard1 = clusterState.getCollection(collectionName).getSlice(SHARD1); + DocRouter.Range shard1Range = + shard1.getRange() != null ? shard1.getRange() : router.fullRange(); + final List ranges = + ((CompositeIdRouter) router).partitionRangeByKey(splitKey, shard1Range); + final int[] docCounts = new int[ranges.size()]; - trySplit(collectionName, splitKey, null, 3); + int uniqIdentifier = (1 << 12); + int splitKeyDocCount = 0; + for (int i = 100; i <= 200; i++) { + // See comment in ShardRoutingTest for hash distribution + String shardKey = "" + (char) ('a' + (i % 26)); + + String idStr = shardKey + "!" + i; + collectionClient.add( + getDoc(id, idStr, "n_ti", (shardKey + "!").equals(splitKey) ? uniqIdentifier : i)); + int idx = getHashRangeIdx(router, ranges, idStr); + if (idx != -1) { + docCounts[idx]++; + } + if (splitKey.equals(shardKey + "!")) splitKeyDocCount++; + } - waitForRecoveriesToFinish(collectionName, false); - SolrQuery solrQuery = new SolrQuery("*:*"); - assertEquals( - "DocCount on shard1_0 does not match", - docCounts[0], - collectionClient - .query(solrQuery.setParam("shards", "shard1_0")) - .getResults() - .getNumFound()); - assertEquals( - "DocCount on shard1_1 does not match", - docCounts[1], - collectionClient - .query(solrQuery.setParam("shards", "shard1_1")) - .getResults() - .getNumFound()); - assertEquals( - "DocCount on shard1_2 does not match", - docCounts[2], - collectionClient - .query(solrQuery.setParam("shards", "shard1_2")) - .getResults() - .getNumFound()); - - solrQuery = new SolrQuery("n_ti:" + uniqIdentifier); - assertEquals( - "shard1_0 must have 0 docs for route key: " + splitKey, - 0, - collectionClient - .query(solrQuery.setParam("shards", "shard1_0")) - .getResults() - .getNumFound()); - assertEquals( - "Wrong number of docs on shard1_1 for route key: " + splitKey, - splitKeyDocCount, - collectionClient - .query(solrQuery.setParam("shards", "shard1_1")) - .getResults() - .getNumFound()); - assertEquals( - "shard1_2 must have 0 docs for route key: " + splitKey, - 0, - collectionClient - .query(solrQuery.setParam("shards", "shard1_2")) - .getResults() - .getNumFound()); + for (int i = 0; i < docCounts.length; i++) { + int docCount = docCounts[i]; + log.info("Shard shard1_{} docCount = {}", i, docCount); } + log.info("Route key doc count = {}", splitKeyDocCount); + + collectionClient.commit(); + + trySplit(collectionName, splitKey, null, 3); + + waitForRecoveriesToFinish(collectionName, false); + SolrQuery solrQuery = new SolrQuery("*:*"); + assertEquals( + "DocCount on shard1_0 does not match", + docCounts[0], + collectionClient + .query(solrQuery.setParam("shards", "shard1_0")) + .getResults() + .getNumFound()); + assertEquals( + "DocCount on shard1_1 does not match", + docCounts[1], + collectionClient + .query(solrQuery.setParam("shards", "shard1_1")) + .getResults() + .getNumFound()); + assertEquals( + "DocCount on shard1_2 does not match", + docCounts[2], + collectionClient + .query(solrQuery.setParam("shards", "shard1_2")) + .getResults() + .getNumFound()); + + solrQuery = new SolrQuery("n_ti:" + uniqIdentifier); + assertEquals( + "shard1_0 must have 0 docs for route key: " + splitKey, + 0, + collectionClient + .query(solrQuery.setParam("shards", "shard1_0")) + .getResults() + .getNumFound()); + assertEquals( + "Wrong number of docs on shard1_1 for route key: " + splitKey, + splitKeyDocCount, + collectionClient + .query(solrQuery.setParam("shards", "shard1_1")) + .getResults() + .getNumFound()); + assertEquals( + "shard1_2 must have 0 docs for route key: " + splitKey, + 0, + collectionClient + .query(solrQuery.setParam("shards", "shard1_2")) + .getResults() + .getNumFound()); } private void trySplit(String collectionName, String splitKey, String shardId, int maxTries) diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index d976d9fabe40..0b8e194abc7c 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -2557,16 +2557,31 @@ protected CloudSolrClient getCommonCloudSolrClient() { return commonCloudSolrClient; } + /** Returns the jetty identified by node name or base URL. */ + protected JettySolrRunner getJetty(String nodeNameOrUrl) { + return MiniSolrCloudCluster.findJetty(allRunners(), nodeNameOrUrl); + } + /** * Returns the jetty-owned client for the node hosting {@code replica}, scoped to that replica's * core. The caller must not close it -- the jetty owns it. */ protected SolrClient getSolrClient(Replica replica) { return new CollectionScopedSolrClient( - MiniSolrCloudCluster.findReplicaJetty(jettys, replica).getSolrClient(), + MiniSolrCloudCluster.findReplicaJetty(allRunners(), replica).getSolrClient(), replica.getCoreName()); } + /** All runners of this cluster; the control jetty is kept outside {@link #jettys}. */ + private List allRunners() { + if (controlJetty == null) { + return jettys; + } + List all = new ArrayList<>(jettys); + all.add(controlJetty); + return all; + } + protected CloudSolrClient getSolrClient(String collectionName) { return solrClientByCollection.computeIfAbsent( collectionName, diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java index 378689787e15..7aba36a9188b 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java @@ -757,7 +757,12 @@ static JettySolrRunner findReplicaJetty(Collection runners, Rep /** Return the jetty for a node, identified by either its node name or its base URL. */ public JettySolrRunner getJetty(String nodeNameOrUrl) { - for (JettySolrRunner jetty : jettys) { + return findJetty(jettys, nodeNameOrUrl); + } + + /** Returns the runner among {@code runners} identified by node name or base URL. */ + static JettySolrRunner findJetty(Collection runners, String nodeNameOrUrl) { + for (JettySolrRunner jetty : runners) { if (jetty.isStopped()) continue; if (nodeNameOrUrl.equals(jetty.getNodeName()) || nodeNameOrUrl.equals(jetty.getBaseUrl().toString())) { From 2fff919c929a2c748f7d6492f1042876ef8dc2a9 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:18:25 +0300 Subject: [PATCH 20/24] SOLR-18390: two tests that start their own runner take its client --- .../apache/solr/handler/V2StandaloneTest.java | 17 +++++++---------- .../solr/embedded/TestJettySolrRunner.java | 13 +++++-------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java b/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java index 0283d770284d..5d6184ce0f01 100644 --- a/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java +++ b/solr/core/src/test/org/apache/solr/handler/V2StandaloneTest.java @@ -21,7 +21,6 @@ import org.apache.commons.io.file.PathUtils; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.V2Request; import org.apache.solr.common.util.NamedList; import org.apache.solr.embedded.JettyConfig; @@ -40,16 +39,14 @@ public void testWelcomeMessage() throws Exception { new JettySolrRunner(solrHomeTmp.toString(), JettyConfig.builder().build()); jetty.start(); - try (SolrClient client = - new HttpJettySolrClient.Builder(buildUrl(jetty.getLocalPort())).build()) { - NamedList res = client.request(new V2Request.Builder("/").build()); - NamedList header = (NamedList) res.get("responseHeader"); - assertEquals(0, header.get("status")); + SolrClient client = jetty.getSolrClient(); + NamedList res = client.request(new V2Request.Builder("/").build()); + NamedList header = (NamedList) res.get("responseHeader"); + assertEquals(0, header.get("status")); - res = client.request(new V2Request.Builder("/_introspect").build()); - header = (NamedList) res.get("responseHeader"); - assertEquals(0, header.get("status")); - } + res = client.request(new V2Request.Builder("/_introspect").build()); + header = (NamedList) res.get("responseHeader"); + assertEquals(0, header.get("status")); jetty.stop(); } diff --git a/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java b/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java index a941574e7acf..a874787c0ead 100644 --- a/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java +++ b/solr/test-framework/src/test/org/apache/solr/embedded/TestJettySolrRunner.java @@ -25,7 +25,6 @@ import java.util.Properties; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.cloud.MiniSolrCloudCluster; import org.junit.Test; @@ -56,14 +55,12 @@ public void testPassSolrHomeToRunner() throws Exception { try { runner.start(); - try (SolrClient client = - new HttpJettySolrClient.Builder(runner.getBaseUrl().toString()).build()) { - CoreAdminRequest.Create createReq = new CoreAdminRequest.Create(); - createReq.setCoreName("newcore"); - createReq.setConfigSet("minimal"); + SolrClient client = runner.getSolrClient(); + CoreAdminRequest.Create createReq = new CoreAdminRequest.Create(); + createReq.setCoreName("newcore"); + createReq.setConfigSet("minimal"); - client.request(createReq); - } + client.request(createReq); assertTrue(Files.exists(coresDir.resolve("newcore").resolve("core.properties"))); From 7d7a039adea000a348423d1d47fa4827a0111afd Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:23:15 +0300 Subject: [PATCH 21/24] SOLR-18390: MoveReplicaTest takes the node's client for its CoreAdmin call --- .../apache/solr/cloud/MoveReplicaTest.java | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java index e82ff3c3ac79..7e9706f9410f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MoveReplicaTest.java @@ -29,7 +29,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.SolrQuery; @@ -39,7 +38,6 @@ import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.util.NamedList; import org.apache.solr.embedded.JettySolrRunner; import org.apache.solr.util.IdUtils; @@ -365,37 +363,33 @@ private int getNumOfCores(CloudSolrClient cloudClient, String nodeName, String c private int getNumOfCores( CloudSolrClient cloudClient, String nodeName, String collectionName, String replicaType) throws IOException, SolrServerException { - try (SolrClient coreclient = - new HttpJettySolrClient.Builder( - ZkStateReader.from(cloudClient).getBaseUrlForNodeName(nodeName)) - .build()) { - CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient); - if (status.getCoreStatus().size() == 0) { - return 0; - } - if (collectionName == null && replicaType == null) { - return status.getCoreStatus().size(); - } - // filter size by collection name - int size = 0; - for (Map.Entry coreStatusEntry : - status.getCoreStatus().entrySet()) { - if (collectionName != null) { - String coll = coreStatusEntry.getValue().cloud.collection; - if (!collectionName.equals(coll)) { - continue; - } + SolrClient coreclient = cluster.getJetty(nodeName).getSolrClient(); + CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient); + if (status.getCoreStatus().size() == 0) { + return 0; + } + if (collectionName == null && replicaType == null) { + return status.getCoreStatus().size(); + } + // filter size by collection name + int size = 0; + for (Map.Entry coreStatusEntry : + status.getCoreStatus().entrySet()) { + if (collectionName != null) { + String coll = coreStatusEntry.getValue().cloud.collection; + if (!collectionName.equals(coll)) { + continue; } - if (replicaType != null) { - String type = coreStatusEntry.getValue().cloud.replicaType; - if (!replicaType.equals(type)) { - continue; - } + } + if (replicaType != null) { + String type = coreStatusEntry.getValue().cloud.replicaType; + if (!replicaType.equals(type)) { + continue; } - size++; } - return size; + size++; } + return size; } protected void addDocs(String collection, int numDocs) throws Exception { From 5bf29c74859dcda0bc842b0f91601a3c2d603ff7 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:36:59 +0300 Subject: [PATCH 22/24] SOLR-18390: use getSolrClient(Replica) for the node-level calls too The wrapper's default collection is unused by CoreAdmin requests, so the method David asked for works there as well and keeps one route instead of two. --- .../org/apache/solr/cloud/DistributedVersionInfoTest.java | 3 +-- .../apache/solr/core/snapshots/TestSolrCloudSnapshots.java | 5 ++--- .../AbstractCollectionsAPIDistributedZkTestBase.java | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java index 5ddd464c70bb..7c557eb51661 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java @@ -366,8 +366,7 @@ protected Long assertDocExists(SolrClient solr, String docId, Long expVers) thro protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { String coreName = replica.getCoreName(); boolean reloadedOk = false; - // CoreAdmin is a node-level API, so the node's own client is what we want here - SolrClient client = cluster.getReplicaJetty(replica).getSolrClient(); + SolrClient client = cluster.getSolrClient(replica); CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java index 2c417d6226e2..6ead68205f9a 100644 --- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java +++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java @@ -156,8 +156,7 @@ public void testSnapshots() throws Exception { assertTrue(snapshotByCoreName.containsKey(coreName)); CoreSnapshotMetaData coreSnapshot = snapshotByCoreName.get(coreName); - // listing core snapshots is a node-level admin call - SolrClient adminClient = cluster.getReplicaJetty(replica).getSolrClient(); + SolrClient adminClient = cluster.getSolrClient(replica); Collection snapshots = listCoreSnapshots(adminClient, coreName); Optional metaData = snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); @@ -274,7 +273,7 @@ public void testSnapshots() throws Exception { String coreName = replica.getCoreName(); - SolrClient adminClient = cluster.getReplicaJetty(replica).getSolrClient(); + SolrClient adminClient = cluster.getSolrClient(replica); Collection snapshots = listCoreSnapshots(adminClient, coreName); Optional metaData = snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst(); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java index 362a5fd69c6c..febda3ee2659 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java @@ -560,7 +560,7 @@ private void collectStartTimes(String collectionName, Map urlToTim for (Slice shard : collectionState) { for (Replica replica : shard) { CoreStatusResponse.SingleCoreData coreStatus; - SolrClient server = cluster.getReplicaJetty(replica).getSolrClient(); + SolrClient server = cluster.getSolrClient(replica); coreStatus = CoreAdminRequest.getCoreStatus(replica.getCoreName(), false, server); long before = coreStatus.startTime.getTime(); urlToTime.put(replica.getCoreUrl(), before); @@ -639,7 +639,7 @@ public void addReplicaTest() throws Exception { assertNotNull(newReplica); cluster.waitForActiveCollection(collectionName, 2, 6); - SolrClient coreclient = cluster.getReplicaJetty(newReplica).getSolrClient(); + SolrClient coreclient = cluster.getSolrClient(newReplica); CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); final var coreStatus = status.getCoreStatus(newReplica.getStr("core")); assertEquals(coreStatus.instanceDir, instancePath.toString()); From 4995cb5fe0a4782a7cb33d02ffe250384cda6f89 Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:41:22 +0300 Subject: [PATCH 23/24] SOLR-18390: name the composite success-map key instead of explaining it --- .../org/apache/solr/cloud/CollectionsAPISolrJTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java index 24328d527b66..077d4a6f557c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java @@ -296,12 +296,11 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException cluster.waitForActiveCollection(collectionName, 2, 4); - String nodeName = response._getStr("success[0]/key"); - String corename = response._getStr(asList("success", nodeName, "core"), null); + String successKey = response._getStr("success[0]/key"); // "nodeName/coreNodeName" + String corename = response._getStr(asList("success", successKey, "core"), null); + String nodeName = successKey.substring(0, successKey.indexOf('/')); - // nodeName is actually "nodeName/coreNodeName" (see CollectionHandlingUtils.requestKey) - SolrClient coreClient = - cluster.getJetty(nodeName.substring(0, nodeName.indexOf('/'))).getSolrClient(); + SolrClient coreClient = cluster.getJetty(nodeName).getSolrClient(); CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient); assertEquals( collectionName, status._get(asList("status", corename, "cloud", "collection"), null)); From 2325dfc281d0c139d159c338307856108b7a11aa Mon Sep 17 00:00:00 2001 From: Serhiy Bzhezytskyy Date: Sat, 29 Aug 2026 11:51:44 +0300 Subject: [PATCH 24/24] SOLR-18390: HttpPartitionTest and its subclass use getSolrClient(Replica) The earlier attempt failed only because controlJetty sat outside the lookup; with that fixed the conversion works. Every converted site runs with the proxies reopened, or in the ZK-expiry test where no proxy is involved, so nothing loses the partition it was exercising. --- .../apache/solr/cloud/HttpPartitionTest.java | 42 +++++-------------- .../LeaderFailoverAfterPartitionTest.java | 10 +---- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java index 56fe4f5f53d7..b3008764c214 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java @@ -36,7 +36,6 @@ import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.common.SolrException; @@ -431,21 +430,15 @@ protected void testLeaderZkSessionLoss() throws Exception { if (log.isInfoEnabled()) { log.info("Sending doc 2 to old leader {}", leader.getName()); } - try (SolrClient leaderSolr = getHttpSolrClient(leader, testCollectionName)) { - - leaderSolr.add(doc); - leaderSolr.close(); + try { + getSolrClient(leader).add(doc); // if the add worked, then the doc must exist on the new leader - try (SolrClient newLeaderSolr = getHttpSolrClient(currentLeader, testCollectionName)) { - assertDocExists(newLeaderSolr, "2"); - } + assertDocExists(getSolrClient(currentLeader), "2"); } catch (SolrException exc) { // this is ok provided the doc doesn't exist on the current leader - try (SolrClient client = getHttpSolrClient(currentLeader, testCollectionName)) { - client.add(doc); // this should work - } + getSolrClient(currentLeader).add(doc); // this should work } List participatingReplicas = @@ -492,36 +485,21 @@ protected void assertDocsExistInAllReplicas( throws Exception { Replica leader = ZkStateReader.from(cloudClient).getLeaderRetry(testCollectionName, "shard1", 10000); - SolrClient leaderSolr = getHttpSolrClient(leader, testCollectionName); + SolrClient leaderSolr = getSolrClient(leader); List replicas = new ArrayList(notLeaders.size()); for (Replica r : notLeaders) { - replicas.add(getHttpSolrClient(r, testCollectionName)); + replicas.add(getSolrClient(r)); } - try { - for (int d = firstDocId; d <= lastDocId; d++) { - String docId = String.valueOf(d); - assertDocExists(leaderSolr, docId); - for (SolrClient replicaSolr : replicas) { - assertDocExists(replicaSolr, docId); - } - } - } finally { - if (leaderSolr != null) { - leaderSolr.close(); - } + for (int d = firstDocId; d <= lastDocId; d++) { + String docId = String.valueOf(d); + assertDocExists(leaderSolr, docId); for (SolrClient replicaSolr : replicas) { - replicaSolr.close(); + assertDocExists(replicaSolr, docId); } } } - protected SolrClient getHttpSolrClient(Replica replica, String collection) { - return new HttpJettySolrClient.Builder(replica.getBaseUrl()) - .withDefaultCollection(collection) - .build(); - } - // Send doc directly to a server (without going through proxy) protected int sendDoc(String collectionName, int docId, JettySolrRunner leaderJetty) throws IOException, SolrServerException { diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java index 18e3d792cbe5..9a8ff0fef952 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderFailoverAfterPartitionTest.java @@ -22,7 +22,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.solr.SolrTestCaseJ4.SuppressSSL; -import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.ZkStateReader; @@ -124,13 +123,8 @@ protected void testRf3WithLeaderFailover() throws Exception { // doc should be on leader and 1 replica sendDoc(testCollectionName, 5); - try (SolrClient server = getHttpSolrClient(leader, testCollectionName)) { - assertDocExists(server, "5"); - } - - try (SolrClient server = getHttpSolrClient(notLeaders.get(1), testCollectionName)) { - assertDocExists(server, "5"); - } + assertDocExists(getSolrClient(leader), "5"); + assertDocExists(getSolrClient(notLeaders.get(1)), "5"); Thread.sleep(sleepMsBeforeHealPartition);