From f479f16d3a8b57126560c19c57885a103360f1c3 Mon Sep 17 00:00:00 2001 From: Anshum Gupta Date: Thu, 7 Apr 2016 15:43:24 -0700 Subject: [PATCH] SOLR-8097: Implement builder pattern design for constructing SolrJ clients and deprecate direct construction of clients --- solr/CHANGES.txt | 3 + .../dataimport/SolrEntityProcessor.java | 10 +- .../TestContentStreamDataSource.java | 4 +- .../TestSolrEntityProcessorEndToEnd.java | 2 +- .../java/org/apache/solr/hadoop/GoLive.java | 6 +- .../hadoop/MorphlineGoLiveMiniMRTest.java | 4 +- .../solr/SafeConcurrentUpdateSolrClient.java | 2 +- .../solr/morphlines/solr/SolrLocator.java | 5 +- .../solr/AbstractSolrMorphlineTestBase.java | 34 +-- .../cloud/LeaderInitiatedRecoveryThread.java | 2 +- .../OverseerAutoReplicaFailoverThread.java | 32 ++- .../OverseerCollectionMessageHandler.java | 2 +- .../apache/solr/cloud/RecoveryStrategy.java | 5 +- .../org/apache/solr/cloud/SyncStrategy.java | 2 +- .../org/apache/solr/cloud/ZkController.java | 3 +- .../apache/solr/cloud/rule/SnitchContext.java | 3 +- .../solr/handler/CdcrReplicatorManager.java | 18 +- .../solr/handler/CdcrRequestHandler.java | 2 +- .../handler/CdcrUpdateLogSynchronizer.java | 2 +- .../org/apache/solr/handler/IndexFetcher.java | 12 +- .../solr/handler/SolrConfigHandler.java | 3 +- .../handler/admin/CollectionsHandler.java | 3 +- .../handler/component/HttpShardHandler.java | 5 +- .../component/HttpShardHandlerFactory.java | 6 +- .../component/IterativeMergeStrategy.java | 7 +- .../solr/schema/ManagedIndexSchema.java | 2 +- .../solr/update/SolrCmdDistributor.java | 3 +- .../solr/update/StreamingSolrClients.java | 66 ++--- .../java/org/apache/solr/util/SolrCLI.java | 21 +- .../org/apache/solr/TestTolerantSearch.java | 6 +- .../client/solrj/ConnectionReuseTest.java | 6 +- .../solrj/embedded/TestJettySolrRunner.java | 3 +- .../solr/cloud/AliasIntegrationTest.java | 28 +-- .../solr/cloud/AsyncMigrateRouteKeyTest.java | 6 +- .../solr/cloud/BaseCdcrDistributedZkTest.java | 5 +- .../solr/cloud/BasicDistributedZk2Test.java | 6 +- .../solr/cloud/BasicDistributedZkTest.java | 15 +- .../cloud/ChaosMonkeyNothingIsSafeTest.java | 49 ++-- .../solr/cloud/CollectionReloadTest.java | 2 +- .../CollectionsAPIDistributedZkTest.java | 12 +- .../solr/cloud/CollectionsAPISolrJTest.java | 2 +- ...ncurrentDeleteAndCreateCollectionTest.java | 6 +- .../solr/cloud/CustomCollectionTest.java | 12 +- .../solr/cloud/DeleteInactiveReplicaTest.java | 2 +- .../apache/solr/cloud/DeleteReplicaTest.java | 4 +- .../apache/solr/cloud/DeleteShardTest.java | 6 +- .../cloud/DistributedVersionInfoTest.java | 8 +- .../apache/solr/cloud/ForceLeaderTest.java | 2 +- .../cloud/FullSolrCloudDistribCmdsTest.java | 2 +- .../apache/solr/cloud/HttpPartitionTest.java | 2 +- .../LeaderInitiatedRecoveryOnCommitTest.java | 2 +- ...erInitiatedRecoveryOnShardRestartTest.java | 2 +- .../solr/cloud/MigrateRouteKeyTest.java | 4 +- .../solr/cloud/ReplicationFactorTest.java | 2 +- .../apache/solr/cloud/SSLMigrationTest.java | 2 +- .../org/apache/solr/cloud/ShardSplitTest.java | 32 +-- .../org/apache/solr/cloud/SyncSliceTest.java | 2 +- .../solr/cloud/TestCloudDeleteByQuery.java | 10 +- .../apache/solr/cloud/TestConfigSetsAPI.java | 20 +- .../cloud/TestConfigSetsAPIExclusivity.java | 4 +- .../cloud/TestConfigSetsAPIZkFailure.java | 4 +- .../org/apache/solr/cloud/TestCryptoKeys.java | 2 +- .../cloud/TestMiniSolrCloudClusterSSL.java | 2 +- .../cloud/TestRandomRequestDistribution.java | 4 +- .../cloud/TestRequestStatusCollectionAPI.java | 2 +- .../TestTolerantUpdateProcessorCloud.java | 10 +- ...estTolerantUpdateProcessorRandomCloud.java | 2 +- .../solr/cloud/UnloadDistributedZkTest.java | 30 +-- .../HdfsWriteToMultipleCollectionsTest.java | 2 +- .../solr/cloud/hdfs/StressHdfsTest.java | 2 +- .../solr/core/OpenCloseCoreStressTest.java | 4 +- .../apache/solr/core/TestDynamicLoading.java | 2 +- .../solr/handler/TestReplicationHandler.java | 5 +- .../handler/TestReplicationHandlerBackup.java | 3 +- .../apache/solr/handler/TestRestoreCore.java | 3 +- .../handler/admin/CoreAdminHandlerTest.java | 4 +- .../DistributedDebugComponentTest.java | 6 +- ...istributedQueryElevationComponentTest.java | 3 +- .../org/apache/solr/search/TestSolrJ.java | 4 +- .../solr/search/stats/TestDistribIDF.java | 8 +- .../security/BasicAuthIntegrationTest.java | 3 +- .../processor/TestNamedUpdateProcessors.java | 3 +- .../solr/util/TestSolrCLIRunExample.java | 4 +- .../client/solrj/impl/CloudSolrClient.java | 229 +++++++++++++++--- .../impl/ConcurrentUpdateSolrClient.java | 146 +++++++++-- .../client/solrj/impl/HttpSolrClient.java | 112 +++++++-- .../client/solrj/impl/LBHttpSolrClient.java | 130 ++++++++-- .../solr/client/solrj/io/SolrClientCache.java | 9 +- .../solrj/io/sql/DatabaseMetaDataImpl.java | 4 +- .../solrj/io/stream/CloudSolrStream.java | 7 +- .../client/solrj/io/stream/FacetStream.java | 8 +- .../client/solrj/io/stream/SolrStream.java | 4 +- .../client/solrj/io/stream/StatsStream.java | 7 +- .../client/solrj/io/stream/TopicStream.java | 8 +- .../client/solrj/io/stream/UpdateStream.java | 5 +- .../client/solrj/SolrExampleBinaryTest.java | 2 +- .../solr/client/solrj/SolrExampleTests.java | 2 +- .../solr/client/solrj/SolrExampleXMLTest.java | 2 +- .../solr/client/solrj/SolrExceptionTest.java | 4 +- .../solrj/SolrSchemalessExampleTest.java | 2 +- .../client/solrj/TestLBHttpSolrClient.java | 30 +-- .../solrj/embedded/SolrExampleJettyTest.java | 2 +- .../embedded/SolrExampleStreamingTest.java | 23 +- .../solrj/impl/BasicHttpSolrClientTest.java | 37 +-- .../impl/CloudSolrClientBuilderTest.java | 90 +++++++ .../solrj/impl/CloudSolrClientTest.java | 21 +- ...ConcurrentUpdateSolrClientBuilderTest.java | 33 +++ .../impl/ConcurrentUpdateSolrClientTest.java | 37 ++- .../solrj/impl/HttpSolrClientBuilderTest.java | 76 ++++++ .../impl/LBHttpSolrClientBuilderTest.java | 65 +++++ .../solr/BaseDistributedSearchTestCase.java | 2 +- .../org/apache/solr/SolrJettyTestBase.java | 2 +- .../java/org/apache/solr/SolrTestCaseHS.java | 54 ++--- .../java/org/apache/solr/SolrTestCaseJ4.java | 142 +++++++++++ .../cloud/AbstractFullDistribZkTestBase.java | 18 +- .../solr/cloud/MiniSolrCloudCluster.java | 5 +- 116 files changed, 1451 insertions(+), 512 deletions(-) create mode 100644 solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java create mode 100644 solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java create mode 100644 solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java create mode 100644 solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBuilderTest.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b2f9a84f656..a1a1fe0f84f 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -106,6 +106,9 @@ Other Changes * SOLR-8892: Allow SolrInfoMBeans to return different statistics for /jmx vs web ui calls. (Gregory Chanan, Mark Miller) +* SOLR-8097: Implement builder pattern design for constructing SolrJ clients and also deprecate direct construction + of client objects. (Jason Gerlowski, Shawn Heisey, Anshum Gupta) + ================== 6.0.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrEntityProcessor.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrEntityProcessor.java index cece0cc9a4c..5e62731879e 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrEntityProcessor.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SolrEntityProcessor.java @@ -22,6 +22,7 @@ import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.impl.XMLResponseParser; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; @@ -111,11 +112,16 @@ public class SolrEntityProcessor extends EntityProcessorBase { // (wt="javabin|xml") default is javabin if ("xml".equals(context.getResolvedEntityAttribute(CommonParams.WT))) { // TODO: it doesn't matter for this impl when passing a client currently, but we should close this! - solrClient = new HttpSolrClient(url.toExternalForm(), client, new XMLResponseParser()); + solrClient = new Builder(url.toExternalForm()) + .withHttpClient(client) + .withResponseParser(new XMLResponseParser()) + .build(); LOG.info("using XMLResponseParser"); } else { // TODO: it doesn't matter for this impl when passing a client currently, but we should close this! - solrClient = new HttpSolrClient(url.toExternalForm(), client); + solrClient = new Builder(url.toExternalForm()) + .withHttpClient(client) + .build(); LOG.info("using BinaryResponseParser"); } } catch (MalformedURLException e) { diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java index 453f5713709..95af5f9494b 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java @@ -69,7 +69,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa params.set("command", "full-import"); params.set("clean", "false"); req.setParams(params); - try (HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) { + try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) { solrClient.request(req); ModifiableSolrParams qparams = new ModifiableSolrParams(); qparams.add("q", "*:*"); @@ -89,7 +89,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa "clean", "false", UpdateParams.COMMIT, "false", UpdateParams.COMMIT_WITHIN, "1000"); req.setParams(params); - try (HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) { + try (HttpSolrClient solrServer = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) { solrServer.request(req); Thread.sleep(100); ModifiableSolrParams queryAll = params("q", "*"); diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java index abefc493f6b..8ef94c02c76 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java @@ -282,7 +282,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe sidl.add(sd); } - try (HttpSolrClient solrServer = new HttpSolrClient(getSourceUrl())) { + try (HttpSolrClient solrServer = getHttpSolrClient(getSourceUrl())) { solrServer.setConnectionTimeout(15000); solrServer.setSoTimeout(30000); solrServer.add(sidl); diff --git a/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/GoLive.java b/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/GoLive.java index bd48c643623..5b1c343ed68 100644 --- a/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/GoLive.java +++ b/solr/contrib/map-reduce/src/java/org/apache/solr/hadoop/GoLive.java @@ -90,7 +90,7 @@ class GoLive { Callable task = () -> { Request req = new Request(); LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl); - try (final HttpSolrClient client = new HttpSolrClient(mergeUrl)) { + try (final HttpSolrClient client = new HttpSolrClient.Builder(mergeUrl).build()) { CoreAdminRequest.MergeIndexes mergeRequest = new CoreAdminRequest.MergeIndexes(); mergeRequest.setCoreName(name); mergeRequest.setIndexDirs(Arrays.asList(dir.getPath().toString() + "/data/index")); @@ -138,7 +138,7 @@ class GoLive { try { LOG.info("Committing live merge..."); if (options.zkHost != null) { - try (CloudSolrClient server = new CloudSolrClient(options.zkHost)) { + try (CloudSolrClient server = new CloudSolrClient.Builder().withZkHost(options.zkHost).build()) { server.setDefaultCollection(options.collection); server.commit(); } @@ -146,7 +146,7 @@ class GoLive { for (List urls : options.shardUrls) { for (String url : urls) { // TODO: we should do these concurrently - try (HttpSolrClient server = new HttpSolrClient(url)) { + try (HttpSolrClient server = new HttpSolrClient.Builder(url).build()) { server.commit(); } } diff --git a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java index 95ed9b2b17d..ce3d8c48d07 100644 --- a/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java +++ b/solr/contrib/map-reduce/src/test/org/apache/solr/hadoop/MorphlineGoLiveMiniMRTest.java @@ -380,7 +380,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase { String[] args = new String[]{}; List argList = new ArrayList<>(); - try (HttpSolrClient server = new HttpSolrClient(cloudJettys.get(0).url)) { + try (HttpSolrClient server = getHttpSolrClient(cloudJettys.get(0).url)) { args = new String[]{ "--solr-home-dir=" + MINIMR_CONF_DIR.getAbsolutePath(), @@ -706,7 +706,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase { Collection replicas = slice.getReplicas(); long found = -1; for (Replica replica : replicas) { - try (HttpSolrClient client = new HttpSolrClient(new ZkCoreNodeProps(replica).getCoreUrl())) { + try (HttpSolrClient client = getHttpSolrClient(new ZkCoreNodeProps(replica).getCoreUrl())) { SolrQuery query = new SolrQuery("*:*"); query.set("distrib", false); QueryResponse replicaResults = client.query(query); diff --git a/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SafeConcurrentUpdateSolrClient.java b/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SafeConcurrentUpdateSolrClient.java index 1d632f1dc16..a5fb929c92d 100644 --- a/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SafeConcurrentUpdateSolrClient.java +++ b/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SafeConcurrentUpdateSolrClient.java @@ -39,7 +39,7 @@ final class SafeConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient { } public SafeConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount) { - super(solrServerUrl, client, queueSize, threadCount); + super(solrServerUrl, client, queueSize, threadCount, null, false); } @Override diff --git a/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SolrLocator.java b/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SolrLocator.java index 4acb9ac5c48..39cee54e69a 100644 --- a/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SolrLocator.java +++ b/solr/contrib/morphlines-core/src/java/org/apache/solr/morphlines/solr/SolrLocator.java @@ -30,6 +30,7 @@ import com.typesafe.config.ConfigRenderOptions; import com.typesafe.config.ConfigUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrResourceLoader; @@ -92,7 +93,9 @@ public class SolrLocator { if (collectionName == null || collectionName.length() == 0) { throw new MorphlineCompilationException("Parameter 'zkHost' requires that you also pass parameter 'collection'", config); } - CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost); + CloudSolrClient cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); cloudSolrClient.setDefaultCollection(collectionName); cloudSolrClient.connect(); return new SolrClientDocumentLoader(cloudSolrClient, batchSize); diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java index 9c79c07d269..9e65c68a1f9 100644 --- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java +++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineTestBase.java @@ -16,6 +16,22 @@ */ package org.apache.solr.morphlines.solr; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; +import java.util.concurrent.atomic.AtomicInteger; + import com.codahale.metrics.MetricRegistry; import com.google.common.base.Joiner; import com.google.common.io.Files; @@ -46,22 +62,6 @@ import org.kitesdk.morphline.stdlib.PipeBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TimeZone; -import java.util.concurrent.atomic.AtomicInteger; - public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 { private static Locale savedLocale; protected Collector collector; @@ -123,7 +123,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 { if (EXTERNAL_SOLR_SERVER_URL != null) { //solrServer = new ConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2); //solrServer = new SafeConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2); - solrClient = new HttpSolrClient(EXTERNAL_SOLR_SERVER_URL); + solrClient = getHttpSolrClient(EXTERNAL_SOLR_SERVER_URL); ((HttpSolrClient) solrClient).setParser(new XMLResponseParser()); } else { if (TEST_WITH_EMBEDDED_SOLR_SERVER) { diff --git a/solr/core/src/java/org/apache/solr/cloud/LeaderInitiatedRecoveryThread.java b/solr/core/src/java/org/apache/solr/cloud/LeaderInitiatedRecoveryThread.java index 589ed83e833..4389d9e2d73 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderInitiatedRecoveryThread.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderInitiatedRecoveryThread.java @@ -201,7 +201,7 @@ public class LeaderInitiatedRecoveryThread extends Thread { log.info("Asking core={} coreNodeName={} on " + recoveryUrl + " to recover", coreNeedingRecovery, replicaCoreNodeName); } - try (HttpSolrClient client = new HttpSolrClient(recoveryUrl)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(recoveryUrl).build()) { client.setSoTimeout(60000); client.setConnectionTimeout(15000); try { diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java b/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java index a9f8bdd0997..f94ffcc73ba 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java @@ -16,9 +16,22 @@ */ package org.apache.solr.cloud; +import java.io.Closeable; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; - import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest.Create; import org.apache.solr.common.SolrException; @@ -34,21 +47,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; -import java.io.Closeable; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; - // TODO: how to tmp exclude nodes? @@ -434,7 +432,7 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable { final String createUrl, final String dataDir, final String ulogDir, final String coreNodeName, final String coreName) { - try (HttpSolrClient client = new HttpSolrClient(createUrl)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(createUrl).build()) { log.debug("create url={}", createUrl); client.setConnectionTimeout(30000); client.setSoTimeout(60000); diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java index 78db47332f0..503ff291653 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java @@ -1315,7 +1315,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler static UpdateResponse softCommit(String url) throws SolrServerException, IOException { - try (HttpSolrClient client = new HttpSolrClient(url)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(url).build()) { client.setConnectionTimeout(30000); client.setSoTimeout(120000); UpdateRequest ureq = new UpdateRequest(); diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index 5daa6af2225..61b3f90b839 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -17,7 +17,6 @@ package org.apache.solr.cloud; import java.io.Closeable; - import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.ArrayList; @@ -195,7 +194,7 @@ public class RecoveryStrategy extends Thread implements Closeable { private void commitOnLeader(String leaderUrl) throws SolrServerException, IOException { - try (HttpSolrClient client = new HttpSolrClient(leaderUrl)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(leaderUrl).build()) { client.setConnectionTimeout(30000); UpdateRequest ureq = new UpdateRequest(); ureq.setParams(new ModifiableSolrParams()); @@ -575,7 +574,7 @@ public class RecoveryStrategy extends Thread implements Closeable { private void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreName, Slice slice) throws SolrServerException, IOException, InterruptedException, ExecutionException { - try (HttpSolrClient client = new HttpSolrClient(leaderBaseUrl)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(leaderBaseUrl).build()) { client.setConnectionTimeout(30000); WaitForState prepCmd = new WaitForState(); prepCmd.setCoreName(leaderCoreName); diff --git a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java index cedcff9ece7..b1d69be9702 100644 --- a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java @@ -292,7 +292,7 @@ public class SyncStrategy { recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY); recoverRequestCmd.setCoreName(coreName); - try (HttpSolrClient client = new HttpSolrClient(baseUrl, SyncStrategy.this.client)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl).withHttpClient(SyncStrategy.this.client).build()) { client.setConnectionTimeout(30000); client.setSoTimeout(120000); client.request(recoverRequestCmd); diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index 81897b717e9..e288f5e926d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -35,6 +35,7 @@ import java.util.concurrent.TimeoutException; import com.google.common.base.Strings; import org.apache.commons.lang.StringUtils; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState; import org.apache.solr.cloud.overseer.OverseerAction; import org.apache.solr.cloud.overseer.SliceMutator; @@ -1574,7 +1575,7 @@ public final class ZkController { log.info("Replica " + myCoreNodeName + " NOT in leader-initiated recovery, need to wait for leader to see down state."); - try (HttpSolrClient client = new HttpSolrClient(leaderBaseUrl)) { + try (HttpSolrClient client = new Builder(leaderBaseUrl).build()) { client.setConnectionTimeout(15000); client.setSoTimeout(120000); WaitForState prepCmd = new WaitForState(); diff --git a/solr/core/src/java/org/apache/solr/cloud/rule/SnitchContext.java b/solr/core/src/java/org/apache/solr/cloud/rule/SnitchContext.java index b8993da5508..28089068d7e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/rule/SnitchContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/rule/SnitchContext.java @@ -105,7 +105,8 @@ public class SnitchContext implements RemoteCallback { public SimpleSolrResponse invoke(UpdateShardHandler shardHandler, final String url, String path, SolrParams params) throws IOException, SolrServerException { GenericSolrRequest request = new GenericSolrRequest(SolrRequest.METHOD.GET, path, params); - try (HttpSolrClient client = new HttpSolrClient(url, shardHandler.getHttpClient(), new BinaryResponseParser())) { + try (HttpSolrClient client = new HttpSolrClient.Builder(url).withHttpClient(shardHandler.getHttpClient()) + .withResponseParser(new BinaryResponseParser()).build()) { NamedList rsp = client.request(request); request.response.nl = rsp; return request.response; diff --git a/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorManager.java b/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorManager.java index 2822e609ae2..af0161ed3c5 100644 --- a/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorManager.java +++ b/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorManager.java @@ -16,9 +16,16 @@ */ package org.apache.solr.handler; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + 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.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; @@ -30,12 +37,6 @@ import org.apache.solr.update.CdcrUpdateLog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - class CdcrReplicatorManager implements CdcrStateManager.CdcrStateObserver { private List replicatorStates; @@ -64,7 +65,10 @@ class CdcrReplicatorManager implements CdcrStateManager.CdcrStateObserver { String zkHost = params.get(CdcrParams.ZK_HOST_PARAM); String targetCollection = params.get(CdcrParams.TARGET_COLLECTION_PARAM); - CloudSolrClient client = new CloudSolrClient(zkHost, true); + CloudSolrClient client = new Builder() + .withZkHost(zkHost) + .sendUpdatesOnlyToShardLeaders() + .build(); client.setDefaultCollection(targetCollection); replicatorStates.add(new CdcrReplicatorState(targetCollection, zkHost, client)); } diff --git a/solr/core/src/java/org/apache/solr/handler/CdcrRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/CdcrRequestHandler.java index 23e4abac304..f60e5621bfb 100644 --- a/solr/core/src/java/org/apache/solr/handler/CdcrRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/CdcrRequestHandler.java @@ -595,7 +595,7 @@ public class CdcrRequestHandler extends RequestHandlerBase implements SolrCoreAw @Override public Long call() throws Exception { - try (HttpSolrClient server = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient server = new HttpSolrClient.Builder(baseUrl).build()) { server.setConnectionTimeout(15000); server.setSoTimeout(60000); diff --git a/solr/core/src/java/org/apache/solr/handler/CdcrUpdateLogSynchronizer.java b/solr/core/src/java/org/apache/solr/handler/CdcrUpdateLogSynchronizer.java index 4955992a938..7071908e70f 100644 --- a/solr/core/src/java/org/apache/solr/handler/CdcrUpdateLogSynchronizer.java +++ b/solr/core/src/java/org/apache/solr/handler/CdcrUpdateLogSynchronizer.java @@ -129,7 +129,7 @@ class CdcrUpdateLogSynchronizer implements CdcrStateManager.CdcrStateObserver { return; } - HttpSolrClient server = new HttpSolrClient(leaderUrl); + HttpSolrClient server = new HttpSolrClient.Builder(leaderUrl).build(); server.setConnectionTimeout(15000); server.setSoTimeout(60000); diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 39c4158425d..0686f5ba696 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -218,7 +218,7 @@ public class IndexFetcher { QueryRequest req = new QueryRequest(params); // TODO modify to use shardhandler - try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) { client.setSoTimeout(60000); client.setConnectionTimeout(15000); @@ -240,7 +240,7 @@ public class IndexFetcher { QueryRequest req = new QueryRequest(params); // TODO modify to use shardhandler - try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) { client.setSoTimeout(60000); client.setConnectionTimeout(15000); NamedList response = client.request(req); @@ -1606,7 +1606,11 @@ public class IndexFetcher { InputStream is = null; // TODO use shardhandler - try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient, null)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl) + .withHttpClient(myHttpClient) + .withResponseParser(null) + .build() + ) { client.setSoTimeout(60000); client.setConnectionTimeout(15000); QueryRequest req = new QueryRequest(params); @@ -1715,7 +1719,7 @@ public class IndexFetcher { params.set(CommonParams.QT, "/replication"); // TODO use shardhandler - try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) { + try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) { client.setSoTimeout(60000); client.setConnectionTimeout(15000); QueryRequest request = new QueryRequest(params); diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java index eac9b11684e..972859705c9 100644 --- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java @@ -69,7 +69,6 @@ import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.schema.SchemaManager; import org.apache.solr.security.AuthorizationContext; import org.apache.solr.security.PermissionNameProvider; -import org.apache.solr.security.PermissionNameProvider.Name; import org.apache.solr.util.CommandOperation; import org.apache.solr.util.DefaultSolrThreadFactory; import org.apache.solr.util.RTimer; @@ -785,7 +784,7 @@ public class SolrConfigHandler extends RequestHandlerBase implements SolrCoreAwa public Boolean call() throws Exception { final RTimer timer = new RTimer(); int attempts = 0; - try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) { + try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) { // eventually, this loop will get killed by the ExecutorService's timeout while (true) { try { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java index f0a332ebbf4..64b10ab0c0f 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java @@ -35,6 +35,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestSyncShard; import org.apache.solr.client.solrj.response.RequestStatusState; @@ -427,7 +428,7 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission ZkNodeProps leaderProps = clusterState.getLeader(collection, shard); ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(leaderProps); - try (HttpSolrClient client = new HttpSolrClient(nodeProps.getBaseUrl())) { + try (HttpSolrClient client = new Builder(nodeProps.getBaseUrl()).build()) { client.setConnectionTimeout(15000); client.setSoTimeout(60000); RequestSyncShard reqSyncShard = new CoreAdminRequest.RequestSyncShard(); diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java index 4ae013c5681..609e4337667 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java @@ -35,7 +35,7 @@ import org.apache.http.client.HttpClient; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrResponse; -import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.impl.LBHttpSolrClient; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.util.ClientUtils; @@ -54,7 +54,6 @@ import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.StrUtils; import org.apache.solr.core.CoreDescriptor; -import org.apache.solr.core.SolrCore; import org.apache.solr.request.SolrQueryRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -192,7 +191,7 @@ public class HttpShardHandler extends ShardHandler { if (urls.size() <= 1) { String url = urls.get(0); srsp.setShardAddress(url); - try (SolrClient client = new HttpSolrClient(url, httpClient)) { + try (SolrClient client = new Builder(url).withHttpClient(httpClient).build()) { ssr.nl = client.request(req); } } else { diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java index d2800d75ce0..47e688c281b 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java +++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java @@ -23,6 +23,7 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpClientConfigurer; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.client.solrj.impl.LBHttpSolrClient; +import org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.ExecutorUtil; @@ -202,7 +203,10 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org. } protected LBHttpSolrClient createLoadbalancer(HttpClient httpClient){ - return new LBHttpSolrClient(httpClient); + LBHttpSolrClient client = new Builder() + .withHttpClient(httpClient) + .build(); + return client; } protected T getParameter(NamedList initArgs, String configKey, T defaultValue, StringBuilder sb) { diff --git a/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java b/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java index a8f6ca96e8f..34f6ed32bac 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java +++ b/solr/core/src/java/org/apache/solr/handler/component/IterativeMergeStrategy.java @@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.impl.HttpClientConfigurer; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocumentList; @@ -84,7 +85,9 @@ public abstract class IterativeMergeStrategy implements MergeStrategy { public CallBack(ShardResponse originalShardResponse, QueryRequest req) { - this.solrClient = new HttpSolrClient(originalShardResponse.getShardAddress(), getHttpClient()); + this.solrClient = new Builder(originalShardResponse.getShardAddress()) + .withHttpClient(getHttpClient()) + .build(); this.req = req; this.originalShardResponse = originalShardResponse; req.setMethod(SolrRequest.METHOD.POST); @@ -132,4 +135,4 @@ public abstract class IterativeMergeStrategy implements MergeStrategy { return httpClient; } } -} \ No newline at end of file +} diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java index 953a635297a..b22feabba2c 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -326,7 +326,7 @@ public final class ManagedIndexSchema extends IndexSchema { @Override public Integer call() throws Exception { int remoteVersion = -1; - try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) { + try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) { // eventually, this loop will get killed by the ExecutorService's timeout while (remoteVersion == -1 || remoteVersion < expectedZkVersion) { try { diff --git a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java index 9a196b7ca40..c161b82dd00 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java +++ b/solr/core/src/java/org/apache/solr/update/SolrCmdDistributor.java @@ -44,7 +44,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; @@ -260,7 +259,7 @@ public class SolrCmdDistributor { if (req.synchronous) { blockAndDoRetries(); - try (HttpSolrClient client = new HttpSolrClient(req.node.getUrl(), clients.getHttpClient())) { + try (HttpSolrClient client = new HttpSolrClient.Builder(req.node.getUrl()).withHttpClient(clients.getHttpClient()).build()) { client.request(req.uReq); } catch (Exception e) { throw new SolrException(ErrorCode.SERVER_ERROR, "Failed synchronous update on shard " + req.node + " update: " + req.uReq , e); diff --git a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java index ecc2a2bb29e..fc50be21c00 100644 --- a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java +++ b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java @@ -16,6 +16,16 @@ */ package org.apache.solr.update; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; + import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.solr.client.solrj.SolrClient; @@ -29,16 +39,6 @@ import org.apache.solr.update.processor.DistributingUpdateProcessorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; - public class StreamingSolrClients { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -72,24 +72,7 @@ public class StreamingSolrClients { // NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered // on a greater scale since the current behavior is to only increase the number of connections/Runners when // the queue is more than half full. - client = new ConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true) { - @Override - public void handleError(Throwable ex) { - req.trackRequestResult(null, false); - log.error("error", ex); - Error error = new Error(); - error.e = (Exception) ex; - if (ex instanceof SolrException) { - error.statusCode = ((SolrException) ex).code(); - } - error.req = req; - errors.add(error); - } - @Override - public void onSuccess(HttpResponse resp) { - req.trackRequestResult(resp, true); - } - }; + client = new ErrorReportingConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true, req); client.setParser(new BinaryResponseParser()); client.setRequestWriter(new BinaryRequestWriter()); client.setPollQueueTime(req.pollQueueTime); @@ -132,4 +115,31 @@ public class StreamingSolrClients { public ExecutorService getUpdateExecutor() { return updateExecutor; } + + class ErrorReportingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient { + private final SolrCmdDistributor.Req req; + + public ErrorReportingConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, + int threadCount, ExecutorService es, boolean streamDeletes, SolrCmdDistributor.Req req) { + super(solrServerUrl, client, queueSize, threadCount, es, streamDeletes); + this.req = req; + } + + @Override + public void handleError(Throwable ex) { + req.trackRequestResult(null, false); + log.error("error", ex); + Error error = new Error(); + error.e = (Exception) ex; + if (ex instanceof SolrException) { + error.statusCode = ((SolrException) ex).code(); + } + error.req = req; + errors.add(error); + } + @Override + public void onSuccess(HttpResponse resp) { + req.trackRequestResult(resp, true); + } + } } diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java index 19aa52ac184..75a39b2a27c 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java @@ -82,6 +82,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.HttpClientConfigurer; import org.apache.solr.client.solrj.impl.HttpClientUtil; import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrException; @@ -210,7 +211,7 @@ public class SolrCLI { String zkHost = cli.getOptionValue("zkHost", ZK_HOST); log.debug("Connecting to Solr cluster: " + zkHost); - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { String collection = cli.getOptionValue("collection"); if (collection != null) @@ -1163,7 +1164,7 @@ public class SolrCLI { q = new SolrQuery("*:*"); q.setRows(0); q.set("distrib", "false"); - try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) { + try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) { String solrUrl = solr.getBaseURL(); @@ -1286,7 +1287,7 @@ public class SolrCLI { if (zkHost == null) throw new IllegalStateException("Must provide either the '-solrUrl' or '-zkHost' parameters!"); - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { cloudSolrClient.connect(); Set liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes(); if (liveNodes.isEmpty()) @@ -1399,7 +1400,7 @@ public class SolrCLI { "create_collection can only be used when running in SolrCloud mode.\n"); } - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { echo("\nConnecting to ZooKeeper at " + zkHost+" ..."); cloudSolrClient.connect(); runCloudTool(cloudSolrClient, cli); @@ -1708,7 +1709,7 @@ public class SolrCLI { " is running in standalone server mode, upconfig can only be used when running in SolrCloud mode.\n"); } - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); cloudSolrClient.connect(); upconfig(cloudSolrClient, cli, cli.getOptionValue("confname"), cli.getOptionValue("confdir")); @@ -1763,7 +1764,7 @@ public class SolrCLI { } - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { echo("\nConnecting to ZooKeeper at " + zkHost + " ..."); cloudSolrClient.connect(); downconfig(cloudSolrClient, cli.getOptionValue("confname"), cli.getOptionValue("confdir")); @@ -1854,7 +1855,7 @@ public class SolrCLI { protected void deleteCollection(CommandLine cli) throws Exception { String zkHost = getZkHost(cli); - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) { + try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { echo("Connecting to ZooKeeper at " + zkHost); cloudSolrClient.connect(); deleteCollection(cloudSolrClient, cli); @@ -2031,7 +2032,7 @@ public class SolrCLI { echo("\nPOSTing request to Config API: " + solrUrl + updatePath); echo(jsonBody); - try (SolrClient solrClient = new HttpSolrClient(solrUrl)) { + try (SolrClient solrClient = new Builder(solrUrl).build()) { NamedList result = postJsonToSolr(solrClient, updatePath, jsonBody); Integer statusCode = (Integer)((NamedList)result.get("responseHeader")).get("status"); if (statusCode == 0) { @@ -2426,7 +2427,9 @@ public class SolrCLI { protected void waitToSeeLiveNodes(int maxWaitSecs, String zkHost, int numNodes) { CloudSolrClient cloudClient = null; try { - cloudClient = new CloudSolrClient(zkHost); + cloudClient = new CloudSolrClient.Builder() + .withZkHost(zkHost) + .build(); cloudClient.connect(); Set liveNodes = cloudClient.getZkStateReader().getClusterState().getLiveNodes(); int numLiveNodes = (liveNodes != null) ? liveNodes.size() : 0; diff --git a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java index 1d7dd2be66c..cb485d0ca81 100644 --- a/solr/core/src/test/org/apache/solr/TestTolerantSearch.java +++ b/solr/core/src/test/org/apache/solr/TestTolerantSearch.java @@ -59,8 +59,8 @@ public class TestTolerantSearch extends SolrJettyTestBase { solrHome = createSolrHome(); createJetty(solrHome.getAbsolutePath()); String url = jetty.getBaseUrl().toString(); - collection1 = new HttpSolrClient(url + "/collection1"); - collection2 = new HttpSolrClient(url + "/collection2"); + collection1 = getHttpSolrClient(url + "/collection1"); + collection2 = getHttpSolrClient(url + "/collection2"); String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1"; String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2"; @@ -68,7 +68,7 @@ public class TestTolerantSearch extends SolrJettyTestBase { shard2 = urlCollection2.replaceAll("https?://", ""); //create second core - try (HttpSolrClient nodeClient = new HttpSolrClient(url)) { + try (HttpSolrClient nodeClient = getHttpSolrClient(url)) { CoreAdminRequest.Create req = new CoreAdminRequest.Create(); req.setCoreName("collection2"); req.setConfigSet("collection1"); diff --git a/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java b/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java index 0ec9876b61f..05f1157c524 100644 --- a/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java +++ b/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java @@ -80,11 +80,11 @@ public class ConnectionReuseTest extends AbstractFullDistribZkTestBase { HttpClient httpClient = HttpClientUtil.createClient(null); int rndClient = random().nextInt(3); if (rndClient == 0) { - client = new ConcurrentUpdateSolrClient(url.toString(), httpClient, 6, 1); // currently only testing with 1 thread + client = getConcurrentUpdateSolrClient(url.toString(), httpClient, 6, 1); // currently only testing with 1 thread } else if (rndClient == 1) { - client = new HttpSolrClient(url.toString(), httpClient); + client = getHttpSolrClient(url.toString(), httpClient); } else if (rndClient == 2) { - client = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), httpClient); + client = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), httpClient); ((CloudSolrClient) client).setParallelUpdates(random().nextBoolean()); ((CloudSolrClient) client).setDefaultCollection(DEFAULT_COLLECTION); ((CloudSolrClient) client).getLbClient().setConnectionTimeout(30000); diff --git a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java index 17facec7241..688996c23e9 100644 --- a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java +++ b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestJettySolrRunner.java @@ -19,7 +19,6 @@ package org.apache.solr.client.solrj.embedded; import com.google.common.base.Charsets; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.junit.Test; @@ -53,7 +52,7 @@ public class TestJettySolrRunner extends SolrTestCaseJ4 { try { runner.start(); - SolrClient client = new HttpSolrClient(runner.getBaseUrl().toString()); + SolrClient client = getHttpSolrClient(runner.getBaseUrl().toString()); CoreAdminRequest.Create createReq = new CoreAdminRequest.Create(); createReq.setCoreName("newcore"); 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 a270a108141..a2fcbd4bb7b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -16,6 +16,11 @@ */ package org.apache.solr.cloud; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.List; + import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; @@ -32,16 +37,9 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CollectionParams.CollectionAction; import org.apache.solr.common.params.ModifiableSolrParams; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.junit.Test; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.List; /** * Test sync phase that occurs when Leader goes down and a new Leader is @@ -119,7 +117,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { query.set("collection", "testalias"); JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size())); int port = jetty.getLocalPort(); - try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) { res = client.query(query); assertEquals(3, res.getResults().getNumFound()); } @@ -128,7 +126,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { query = new SolrQuery("*:*"); jetty = jettys.get(random().nextInt(jettys.size())); port = jetty.getLocalPort(); - try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) { res = client.query(query); assertEquals(3, res.getResults().getNumFound()); } @@ -136,7 +134,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { createAlias("testalias", "collection2,collection1"); // search with new cloud client - try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) { + try (CloudSolrClient cloudSolrClient = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) { cloudSolrClient.setParallelUpdates(random().nextBoolean()); query = new SolrQuery("*:*"); query.set("collection", "testalias"); @@ -155,7 +153,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { query.set("collection", "testalias"); jetty = jettys.get(random().nextInt(jettys.size())); port = jetty.getLocalPort(); - try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) { res = client.query(query); assertEquals(5, res.getResults().getNumFound()); } @@ -163,7 +161,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { query = new SolrQuery("*:*"); jetty = jettys.get(random().nextInt(jettys.size())); port = jetty.getLocalPort(); - try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) { res = client.query(query); assertEquals(5, res.getResults().getNumFound()); } @@ -190,7 +188,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { // try a std client // search 1 and 2, but have no collections param query = new SolrQuery("*:*"); - try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) { res = client.query(query); assertEquals(5, res.getResults().getNumFound()); } @@ -200,7 +198,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase { // a second alias createAlias("testalias2", "collection2"); - try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) { + try (HttpSolrClient client = getHttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) { SolrInputDocument doc8 = getDoc(id, 11, i1, -600, tlong, 600, t1, "humpty dumpy4 sat on a walls"); client.add(doc8); diff --git a/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java index b9e6d3a090d..f6e4b338c61 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java @@ -16,6 +16,8 @@ */ package org.apache.solr.cloud; +import java.io.IOException; + import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrClient; @@ -27,8 +29,6 @@ import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.NamedList; import org.junit.Test; -import java.io.IOException; - public class AsyncMigrateRouteKeyTest extends MigrateRouteKeyTest { public AsyncMigrateRouteKeyTest() { @@ -113,7 +113,7 @@ public class AsyncMigrateRouteKeyTest extends MigrateRouteKeyTest { String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) { baseServer.setConnectionTimeout(15000); return baseServer.request(request); } diff --git a/solr/core/src/test/org/apache/solr/cloud/BaseCdcrDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BaseCdcrDistributedZkTest.java index fe94309bba2..fcd9abb5237 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BaseCdcrDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BaseCdcrDistributedZkTest.java @@ -49,7 +49,6 @@ import org.apache.solr.common.cloud.ZkCoreNodeProps; import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.params.CollectionParams; import org.apache.solr.common.params.CommonParams; -import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.StrUtils; @@ -172,7 +171,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase { } protected CloudSolrClient createCloudClient(String defaultCollection) { - CloudSolrClient server = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean()); + CloudSolrClient server = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean()); server.setParallelUpdates(random().nextBoolean()); if (defaultCollection != null) server.setDefaultCollection(defaultCollection); server.getLbClient().getHttpClient().getParams() @@ -745,7 +744,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase { protected static SolrClient createNewSolrServer(String baseUrl) { try { // setup the server... - HttpSolrClient s = new HttpSolrClient(baseUrl); + HttpSolrClient s = getHttpSolrClient(baseUrl); s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); s.setDefaultMaxConnectionsPerHost(100); s.setMaxTotalConnections(100); 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 a0425014631..61b9901f946 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -147,7 +147,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase { private void testNodeWithoutCollectionForwarding() throws Exception { final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0)); - try (HttpSolrClient client = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl)) { client.setConnectionTimeout(30000); Create createCmd = new Create(); createCmd.setRoles("none"); @@ -180,7 +180,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase { SolrQuery query = new SolrQuery("*:*"); - try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core")) { + try (HttpSolrClient qclient = getHttpSolrClient(baseUrl + "/onenodecollection" + "core")) { // it might take a moment for the proxy node to see us in their cloud state waitForNon403or404or503(qclient); @@ -196,7 +196,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase { assertEquals(docs - 1, results.getResults().getNumFound()); } - try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection")) { + try (HttpSolrClient qclient = getHttpSolrClient(baseUrl + "/onenodecollection")) { QueryResponse results = qclient.query(query); assertEquals(docs - 1, results.getResults().getNumFound()); 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 4a6b2d7af6b..e9b8ff757ed 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -404,7 +404,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { for (Slice slice : dColl.getActiveSlices()) { long sliceDocCount = -1; for (Replica rep : slice.getReplicas()) { - HttpSolrClient one = new HttpSolrClient(rep.getCoreUrl()); + HttpSolrClient one = getHttpSolrClient(rep.getCoreUrl()); SolrQuery query = new SolrQuery("*:*"); query.setDistrib(false); QueryResponse resp = one.query(query); @@ -528,7 +528,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { private void testStopAndStartCoresInOneInstance() throws Exception { SolrClient client = clients.get(0); String url3 = getBaseUrl(client); - try (final HttpSolrClient httpSolrClient = new HttpSolrClient(url3)) { + try (final HttpSolrClient httpSolrClient = getHttpSolrClient(url3)) { httpSolrClient.setConnectionTimeout(15000); httpSolrClient.setSoTimeout(60000); ThreadPoolExecutor executor = null; @@ -749,7 +749,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { private Long getNumCommits(HttpSolrClient sourceClient) throws SolrServerException, IOException { - try (HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL())) { + try (HttpSolrClient client = getHttpSolrClient(sourceClient.getBaseURL())) { client.setConnectionTimeout(15000); client.setSoTimeout(60000); ModifiableSolrParams params = new ModifiableSolrParams(); @@ -840,7 +840,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { ZkCoreNodeProps props = new ZkCoreNodeProps(getCommonCloudSolrClient().getZkStateReader().getClusterState().getLeader(oneInstanceCollection2, "slice1")); // now test that unloading a core gets us a new leader - try (HttpSolrClient unloadClient = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient unloadClient = getHttpSolrClient(baseUrl)) { unloadClient.setConnectionTimeout(15000); unloadClient.setSoTimeout(60000); Unload unloadCmd = new Unload(true); @@ -960,7 +960,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { List collectionClients, final String baseUrl, final int num, final String shardId) { Callable call = () -> { - try (HttpSolrClient client = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl)) { client.setConnectionTimeout(15000); Create createCmd = new Create(); createCmd.setRoles("none"); @@ -1089,7 +1089,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { final int frozeUnique = unique; Callable call = () -> { - try (HttpSolrClient client1 = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client1 = getHttpSolrClient(baseUrl)) { client1.setConnectionTimeout(15000); client1.setSoTimeout(60000); Create createCmd = new Create(); @@ -1117,10 +1117,11 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase { protected SolrClient createNewSolrClient(String collection, String baseUrl) { try { // setup the server... - HttpSolrClient client = new HttpSolrClient(baseUrl + "/" + collection); + HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection); client.setSoTimeout(120000); client.setDefaultMaxConnectionsPerHost(100); client.setMaxTotalConnections(100); + return client; } catch (Exception ex) { diff --git a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java index 7dceada1668..09e3adcb267 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java @@ -16,7 +16,15 @@ */ package org.apache.solr.cloud; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; +import java.lang.invoke.MethodHandles; +import java.net.ConnectException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.http.client.HttpClient; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.SolrTestCaseJ4.SuppressObjectReleaseTracker; @@ -36,13 +44,7 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.invoke.MethodHandles; -import java.net.ConnectException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; @Slow @SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776") @@ -295,14 +297,10 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase this.clients = clients; HttpClientUtil.setConnectionTimeout(httpClient, clientConnectionTimeout); HttpClientUtil.setSoTimeout(httpClient, clientSoTimeout); - cusc = new ConcurrentUpdateSolrClient( - ((HttpSolrClient) clients.get(0)).getBaseURL(), httpClient, 8, - 2) { - @Override - public void handleError(Throwable ex) { - log.warn("cusc error", ex); - } - }; + + cusc = new ErrorLoggingConcurrentUpdateSolrClient(((HttpSolrClient) clients.get(0)).getBaseURL(), httpClient, 8, 2); + cusc.setConnectionTimeout(10000); + cusc.setSoTimeout(clientSoTimeout); } @Override @@ -359,14 +357,8 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase clientIndex = 0; } cusc.shutdownNow(); - cusc = new ConcurrentUpdateSolrClient( - ((HttpSolrClient) clients.get(clientIndex)).getBaseURL(), - httpClient, 30, 3) { - @Override - public void handleError(Throwable ex) { - log.warn("cusc error", ex); - } - }; + cusc = new ErrorLoggingConcurrentUpdateSolrClient(((HttpSolrClient) clients.get(clientIndex)).getBaseURL(), + httpClient, 30, 3); } } @@ -403,4 +395,13 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase indexDoc(doc); } + class ErrorLoggingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient { + public ErrorLoggingConcurrentUpdateSolrClient(String serverUrl, HttpClient httpClient, int queueSize, int threadCount) { + super(serverUrl, httpClient, queueSize, threadCount, null, false); + } + @Override + public void handleError(Throwable ex) { + log.warn("cusc error", ex); + } + } } diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionReloadTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionReloadTest.java index 65ff78bf06a..cf8a65013c2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionReloadTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionReloadTest.java @@ -131,7 +131,7 @@ public class CollectionReloadTest extends AbstractFullDistribZkTestBase { ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica); String coreName = coreProps.getCoreName(); boolean reloadedOk = false; - try (HttpSolrClient client = new HttpSolrClient(coreProps.getBaseUrl())) { + try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java index 641dadfc236..702dedb155a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java @@ -722,7 +722,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa String url = getUrlFromZk(collection); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } @@ -742,7 +742,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa String url = getUrlFromZk(collection); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } @@ -789,7 +789,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa String url = getUrlFromZk(collectionName); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // lets try and use the solrj client to index a couple documents SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1, @@ -886,7 +886,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa url = getUrlFromZk(collectionName); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } @@ -1061,7 +1061,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa Entry shardEntry = shardIt.next(); ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue()); CoreAdminResponse mcr; - try (HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl())) { + try (HttpSolrClient server = getHttpSolrClient(coreProps.getBaseUrl())) { mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server); } long before = mcr.getStartTime(coreProps.getCoreName()).getTime(); @@ -1196,7 +1196,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa null, client, props); assertNotNull(newReplica); - HttpSolrClient coreclient = new HttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP)); + HttpSolrClient coreclient = getHttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP)); CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); NamedList coreStatus = status.getCoreStatus(newReplica.getStr("core")); String instanceDirStr = (String) coreStatus.get("instanceDir"); 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 6b0db0f151f..52ae96f0487 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java @@ -257,7 +257,7 @@ public class CollectionsAPISolrJTest extends AbstractFullDistribZkTestBase { Replica replica1 = testCollection.getReplica("core_node1"); - try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) { + try (HttpSolrClient client = getHttpSolrClient(replica1.getStr("base_url"))) { CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client); NamedList coreStatus = status.getCoreStatus(replica1.getStr("core")); String dataDirStr = (String) coreStatus.get("dataDir"); diff --git a/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java index 82bf9d4a4aa..c8e30eb6917 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ConcurrentDeleteAndCreateCollectionTest.java @@ -60,7 +60,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 { for (int i = 0; i < threads.length; i++) { final String collectionName = "collection" + i; uploadConfig(configDir, collectionName); - final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); threads[i] = new CreateDeleteSearchCollectionThread("create-delete-search-" + i, collectionName, collectionName, timeToRunSec, solrClient, failure); } @@ -75,7 +76,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 { final String configName = "testconfig"; final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile(); uploadConfig(configDir, configName); // upload config once, to be used by all collections - final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); final AtomicReference failure = new AtomicReference<>(); final int timeToRunSec = 30; final Thread[] threads = new Thread[2]; diff --git a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java index 0951b5d6fc0..0873fa3b783 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CustomCollectionTest.java @@ -167,7 +167,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collection); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } @@ -195,7 +195,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName); String shard_fld = "shard_s"; - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // lets try and use the solrj client to index a couple documents @@ -292,12 +292,12 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase { url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName); } - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // lets try and use the solrj client to index a couple documents collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1, @@ -343,13 +343,13 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // poll for a second - it can take a moment before we are ready to serve waitForNon403or404or503(collectionClient); } - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { // lets try and use the solrj client to index a couple documents collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1, 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 959d3b21680..18a5f9cf6bb 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java @@ -128,7 +128,7 @@ public class DeleteInactiveReplicaTest extends AbstractFullDistribZkTestBase{ Map m = Utils.makeMap("qt", "/admin/cores", "action", "status"); - try (SolrClient queryClient = new HttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP))) { + try (SolrClient queryClient = getHttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP))) { NamedList resp = queryClient.request(new QueryRequest(new MapSolrParams(m))); assertNull("The core is up and running again", ((NamedList) resp.get("status")).get(replica1.getStr("core"))); diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java index f0d64840278..bb8d3beb155 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java @@ -97,7 +97,7 @@ public class DeleteReplicaTest extends AbstractFullDistribZkTestBase { if (replica1 == null) fail("no active replicas found"); String dataDir = null; - try (HttpSolrClient replica1Client = new HttpSolrClient(replica1.getStr("base_url"))) { + try (HttpSolrClient replica1Client = getHttpSolrClient(replica1.getStr("base_url"))) { CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), replica1Client); NamedList coreStatus = status.getCoreStatus(replica1.getStr("core")); dataDir = (String) coreStatus.get("dataDir"); @@ -186,7 +186,7 @@ public class DeleteReplicaTest extends AbstractFullDistribZkTestBase { String instanceDir; String dataDir; - try (HttpSolrClient client = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl)) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client); NamedList r = statusResp.getCoreStatus().get(core); instanceDir = (String) r.findRecursive("instanceDir"); diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java index 812fbe93218..90973636c2f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteShardTest.java @@ -121,7 +121,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase { .getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) { baseServer.setConnectionTimeout(15000); baseServer.setSoTimeout(60000); baseServer.request(request); @@ -173,7 +173,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase { String instanceDir; String dataDir; - try (HttpSolrClient client = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl)) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client); NamedList r = statusResp.getCoreStatus().get(core); instanceDir = (String) r.findRecursive("instanceDir"); @@ -199,7 +199,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase { baseUrl = (String) leader.get("base_url"); core = (String) leader.get("core"); - try (HttpSolrClient client = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl)) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client); NamedList r = statusResp.getCoreStatus().get(core); instanceDir = (String) r.findRecursive("instanceDir"); 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 898f38a1874..812815b0173 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java @@ -105,7 +105,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase { assertEquals("leader and replica should have same max version: " + maxOnLeader, maxOnLeader, maxOnReplica); // send the same doc but with a lower version than the max in the index - try (SolrClient client = new HttpSolrClient(replica.getCoreUrl())) { + try (SolrClient client = getHttpSolrClient(replica.getCoreUrl())) { String docId = String.valueOf(1); SolrInputDocument doc = new SolrInputDocument(); doc.setField(id, docId); @@ -276,7 +276,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase { query.addSort(new SolrQuery.SortClause("_version_", SolrQuery.ORDER.desc)); query.setParam("distrib", false); - try (SolrClient client = new HttpSolrClient(replica.getCoreUrl())) { + try (SolrClient client = getHttpSolrClient(replica.getCoreUrl())) { QueryResponse qr = client.query(query); SolrDocumentList hits = qr.getResults(); if (hits.isEmpty()) @@ -343,7 +343,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase { } protected HttpSolrClient getHttpSolrClient(Replica replica) throws Exception { - return new HttpSolrClient(replica.getCoreUrl()); + return getHttpSolrClient(replica.getCoreUrl()); } protected void sendDoc(int docId) throws Exception { @@ -378,7 +378,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase { ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica); String coreName = coreProps.getCoreName(); boolean reloadedOk = false; - try (HttpSolrClient client = new HttpSolrClient(coreProps.getBaseUrl())) { + try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); diff --git a/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java b/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java index a71c3e61413..e9e8907affa 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java @@ -301,7 +301,7 @@ public class ForceLeaderTest extends HttpPartitionTest { SolrRequest req = new GenericSolrRequest(METHOD.GET, "/admin/cores", params); NamedList resp = null; - try (HttpSolrClient hsc = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient hsc = getHttpSolrClient(baseUrl)) { resp = hsc.request(req); } 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 26099142d85..e15ab0d4cba 100644 --- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java @@ -698,7 +698,7 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase QueryResponse results = query(cloudClient); long beforeCount = results.getResults().getNumFound(); int cnt = TEST_NIGHTLY ? 2933 : 313; - try (ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient( + try (ConcurrentUpdateSolrClient concurrentClient = getConcurrentUpdateSolrClient( ((HttpSolrClient) clients.get(0)).getBaseURL(), 10, 2)) { concurrentClient.setConnectionTimeout(120000); for (int i = 0; i < cnt; i++) { 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 f1960aa952e..7e2c17d91a3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java @@ -588,7 +588,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase { protected HttpSolrClient getHttpSolrClient(Replica replica, String coll) throws Exception { ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica); String url = zkProps.getBaseUrl() + "/" + coll; - return new HttpSolrClient(url); + return getHttpSolrClient(url); } protected int sendDoc(int docId) throws Exception { diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java index 7d6c633f482..fd122ad6a08 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnCommitTest.java @@ -163,7 +163,7 @@ public class LeaderInitiatedRecoveryOnCommitTest extends BasicDistributedZkTest String replicaCoreUrl = replica.getCoreUrl(); log.info("Sending commit request to: "+replicaCoreUrl); final RTimer timer = new RTimer(); - try (HttpSolrClient client = new HttpSolrClient(replicaCoreUrl)) { + try (HttpSolrClient client = getHttpSolrClient(replicaCoreUrl)) { try { client.commit(); diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnShardRestartTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnShardRestartTest.java index d130f3bbcd7..928f4d61838 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnShardRestartTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderInitiatedRecoveryOnShardRestartTest.java @@ -80,7 +80,7 @@ public class LeaderInitiatedRecoveryOnShardRestartTest extends AbstractFullDistr QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); String baseUrl = ((HttpSolrClient) clients.get(0)).getBaseURL(); - HttpSolrClient delClient = new HttpSolrClient(baseUrl.substring(0, baseUrl.lastIndexOf("/"))); + HttpSolrClient delClient = getHttpSolrClient(baseUrl.substring(0, baseUrl.lastIndexOf("/"))); delClient.request(request); delClient.close(); 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 c09e0d1dc6a..fadb880b8b6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/MigrateRouteKeyTest.java @@ -106,7 +106,7 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest { .getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) { baseClient.setConnectionTimeout(15000); baseClient.setSoTimeout(60000 * 5); baseClient.request(request); @@ -161,7 +161,7 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), targetCollection); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { SolrQuery solrQuery = new SolrQuery("*:*"); assertEquals("DocCount on target collection does not match", 0, collectionClient.query(solrQuery).getResults().getNumFound()); 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 894f26d70f4..a4fbba186c3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ReplicationFactorTest.java @@ -179,7 +179,7 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase { ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica); String url = zkProps.getBaseUrl() + "/" + collection; - try (HttpSolrClient solrServer = new HttpSolrClient(url)) { + try (HttpSolrClient solrServer = getHttpSolrClient(url)) { 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/SSLMigrationTest.java b/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java index a0bb08f822a..8a72adb7eff 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java @@ -130,7 +130,7 @@ public class SSLMigrationTest extends AbstractFullDistribZkTestBase { urls.add(replica.getStr(ZkStateReader.BASE_URL_PROP)); } //Create new SolrServer to configure new HttpClient w/ SSL config - new LBHttpSolrClient(urls.toArray(new String[]{})).request(request); + getLBHttpSolrClient(urls.toArray(new String[]{})).request(request); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java index 6d4b9cc3b8f..21dc2577066 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ShardSplitTest.java @@ -16,6 +16,16 @@ */ package org.apache.solr.cloud; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; + import org.apache.http.params.CoreConnectionPNames; import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.client.solrj.SolrClient; @@ -44,16 +54,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; - import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES; import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE; import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR; @@ -274,7 +274,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { ClusterState clusterState = cloudClient.getZkStateReader().getClusterState(); final DocRouter router = clusterState.getCollection(collectionName).getRouter(); @@ -348,7 +348,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName); - try (HttpSolrClient collectionClient = new HttpSolrClient(url)) { + try (HttpSolrClient collectionClient = getHttpSolrClient(url)) { String splitKey = "b!"; @@ -445,7 +445,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { ZkCoreNodeProps shard1_0 = getLeaderUrlFromZk(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0); QueryResponse response; - try (HttpSolrClient shard1_0Client = new HttpSolrClient(shard1_0.getCoreUrl())) { + try (HttpSolrClient shard1_0Client = getHttpSolrClient(shard1_0.getCoreUrl())) { response = shard1_0Client.query(query); } long shard10Count = response.getResults().getNumFound(); @@ -453,7 +453,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { ZkCoreNodeProps shard1_1 = getLeaderUrlFromZk( AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1); QueryResponse response2; - try (HttpSolrClient shard1_1Client = new HttpSolrClient(shard1_1.getCoreUrl())) { + try (HttpSolrClient shard1_1Client = getHttpSolrClient(shard1_1.getCoreUrl())) { response2 = shard1_1Client.query(query); } long shard11Count = response2.getResults().getNumFound(); @@ -475,7 +475,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { for (Replica replica : slice.getReplicas()) { String coreUrl = new ZkCoreNodeProps(replica).getCoreUrl(); QueryResponse response; - try (HttpSolrClient client = new HttpSolrClient(coreUrl)) { + try (HttpSolrClient client = getHttpSolrClient(coreUrl)) { response = client.query(query); } numFound[c++] = response.getResults().getNumFound(); @@ -514,7 +514,7 @@ public class ShardSplitTest extends BasicDistributedZkTest { .getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) { baseServer.setConnectionTimeout(30000); baseServer.setSoTimeout(60000 * 5); baseServer.request(request); diff --git a/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java b/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java index 362009e684b..beda3e9157c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SyncSliceTest.java @@ -110,7 +110,7 @@ public class SyncSliceTest extends AbstractFullDistribZkTestBase { .getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) { // we only set the connect timeout, not so timeout baseClient.setConnectionTimeout(30000); baseClient.request(request); 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 27818966c03..987f2f1143c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudDeleteByQuery.java @@ -145,17 +145,17 @@ public class TestCloudDeleteByQuery extends SolrCloudTestCase { assertNotNull("could not find URL for " + shardName + " replica", passiveUrl); if (shardName.equals("shard1")) { - S_ONE_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); - S_ONE_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); + S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); + S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); } else if (shardName.equals("shard2")) { - S_TWO_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); - S_TWO_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); + S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); + S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (nost hosting either shard)", 1, urlMap.size()); - NO_COLLECTION_CLIENT = new HttpSolrClient(urlMap.values().iterator().next() + + NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next() + "/" + COLLECTION_NAME + "/"); assertNotNull(S_ONE_LEADER_CLIENT); 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 b505930afe8..c80432924c8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -79,8 +79,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 { @Test public void testCreateErrors() throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile(); solrCluster.uploadConfigDir(configDir, "configSet"); @@ -143,8 +143,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 { private void verifyCreate(String baseConfigSetName, String configSetName, Map oldProps, Map newProps) throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); setupBaseConfigSet(baseConfigSetName, oldProps); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), @@ -235,8 +235,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 { @Test public void testDeleteErrors() throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile(); final File tmpConfigDir = createTempDir().toFile(); tmpConfigDir.deleteOnExit(); @@ -274,8 +274,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 { @Test public void testDelete() throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile(); final String configSet = "configSet"; solrCluster.uploadConfigDir(configDir, configSet); @@ -300,8 +300,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 { @Test public void testList() throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null); 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 2d2aa58853d..c5a0bc574a0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -121,8 +121,8 @@ public class TestConfigSetsAPIExclusivity extends SolrTestCaseJ4 { public abstract ConfigSetAdminRequest createRequest(); public void run() { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); 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 9e5989adaf1..458d68a1fa9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -99,8 +99,8 @@ public class TestConfigSetsAPIZkFailure extends SolrTestCaseJ4 { @Test public void testCreateZkFailure() throws Exception { - final SolrClient solrClient = - new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString()); + final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString(); + final SolrClient solrClient = getHttpSolrClient(baseUrl); final Map oldProps = ImmutableMap.of("immutable", "true"); setupBaseConfigSet(BASE_CONFIGSET_NAME, oldProps); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCryptoKeys.java b/solr/core/src/test/org/apache/solr/cloud/TestCryptoKeys.java index cdbc170b8ed..a8e206376db 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCryptoKeys.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCryptoKeys.java @@ -119,7 +119,7 @@ public class TestCryptoKeys extends AbstractFullDistribZkTestBase { String baseURL = randomClient.getBaseURL(); baseURL = baseURL.substring(0, baseURL.lastIndexOf('/')); - TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL, randomClient.getHttpClient())); + TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient())); waitForRecoveriesToFinish(".system", true); ByteBuffer jar = TestDynamicLoading.getFileContent("runtimecode/runtimelibs.jar.bin"); 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 bc4352f731f..b82ba743e58 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java @@ -74,7 +74,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { private void sendRequestToEachServer() throws Exception { List jettys = miniCluster.getJettySolrRunners(); for (JettySolrRunner jetty : jettys) { - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString())) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) { CoreAdminRequest req = new CoreAdminRequest(); req.setAction( CoreAdminAction.STATUS ); client.request(req); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java b/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java index 256774d08c3..f13094418ee 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRandomRequestDistribution.java @@ -96,7 +96,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase assertEquals(1, replicas.size()); String baseUrl = replicas.iterator().next().getStr(ZkStateReader.BASE_URL_PROP); if (!baseUrl.endsWith("/")) baseUrl += "/"; - HttpSolrClient client = new HttpSolrClient(baseUrl + "a1x2"); + HttpSolrClient client = getHttpSolrClient(baseUrl + "a1x2"); client.setSoTimeout(5000); client.setConnectionTimeout(2000); @@ -173,7 +173,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase if (!baseUrl.endsWith("/")) baseUrl += "/"; String path = baseUrl + "football"; log.info("Firing queries against path=" + path); - HttpSolrClient client = new HttpSolrClient(path); + HttpSolrClient client = getHttpSolrClient(path); client.setSoTimeout(5000); client.setConnectionTimeout(2000); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java index 485558fff29..d8b66e9cd87 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRequestStatusCollectionAPI.java @@ -189,7 +189,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest { String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL(); baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length()); - try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) { + try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) { baseServer.setConnectionTimeout(15000); return baseServer.request(request); } 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 054c0745fd4..9e5e68b96cc 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java @@ -162,17 +162,17 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase { assertNotNull("could not find URL for " + shardName + " replica", passiveUrl); if (shardName.equals("shard1")) { - S_ONE_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); - S_ONE_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); + S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); + S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); } else if (shardName.equals("shard2")) { - S_TWO_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); - S_TWO_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); + S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/"); + S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/"); } else { fail("unexpected shard: " + shardName); } } assertEquals("Should be exactly one server left (nost hosting either shard)", 1, urlMap.size()); - NO_COLLECTION_CLIENT = new HttpSolrClient(urlMap.values().iterator().next() + + NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next() + "/" + COLLECTION_NAME + "/"); assertNotNull(S_ONE_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 b3f0423c999..08ab4c02044 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorRandomCloud.java @@ -127,7 +127,7 @@ public class TestTolerantUpdateProcessorRandomCloud extends SolrCloudTestCase { for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { URL jettyURL = jetty.getBaseUrl(); - NODE_CLIENTS.add(new HttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/")); + NODE_CLIENTS.add(getHttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/")); } 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 7d53feebf73..616cd374d63 100644 --- a/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java @@ -123,7 +123,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { SolrClient client = clients.get(0); String url1 = getBaseUrl(client); - try (HttpSolrClient adminClient = new HttpSolrClient(url1)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url1)) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(60000); adminClient.request(createCmd); @@ -174,7 +174,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // create a new collection collection SolrClient client = clients.get(0); String url1 = getBaseUrl(client); - try (HttpSolrClient adminClient = new HttpSolrClient(url1)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url1)) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(60000); @@ -194,7 +194,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { client = clients.get(1); String url2 = getBaseUrl(client); - try (HttpSolrClient adminClient = new HttpSolrClient(url2)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url2)) { Create createCmd = new Create(); createCmd.setCoreName("unloadcollection2"); @@ -213,7 +213,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { Random random = random(); if (random.nextBoolean()) { - try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getCoreUrl())) { + try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getCoreUrl())) { // lets try and use the solrj client to index and retrieve a couple // documents SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1, @@ -232,7 +232,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // create another replica for our collection client = clients.get(2); String url3 = getBaseUrl(client); - try (HttpSolrClient adminClient = new HttpSolrClient(url3)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url3)) { Create createCmd = new Create(); createCmd.setCoreName("unloadcollection3"); createCmd.setCollection("unloadcollection"); @@ -246,7 +246,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // so that we start with some versions when we reload... DirectUpdateHandler2.commitOnClose = false; - try (HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3")) { + try (HttpSolrClient addClient = getHttpSolrClient(url3 + "/unloadcollection3")) { addClient.setConnectionTimeout(30000); // add a few docs @@ -260,7 +260,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { //collectionClient.commit(); // unload the leader - try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) { + try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl())) { collectionClient.setConnectionTimeout(15000); collectionClient.setSoTimeout(30000); @@ -284,7 +284,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // ensure there is a leader zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000); - try (HttpSolrClient addClient = new HttpSolrClient(url2 + "/unloadcollection2")) { + try (HttpSolrClient addClient = getHttpSolrClient(url2 + "/unloadcollection2")) { addClient.setConnectionTimeout(30000); addClient.setSoTimeout(90000); @@ -299,7 +299,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // create another replica for our collection client = clients.get(3); String url4 = getBaseUrl(client); - try (HttpSolrClient adminClient = new HttpSolrClient(url4)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url4)) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(30000); @@ -314,7 +314,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { // unload the leader again leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1"); - try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) { + try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl())) { collectionClient.setConnectionTimeout(15000); collectionClient.setSoTimeout(30000); @@ -338,7 +338,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { DirectUpdateHandler2.commitOnClose = true; // bring the downed leader back as replica - try (HttpSolrClient adminClient = new HttpSolrClient(leaderProps.getBaseUrl())) { + try (HttpSolrClient adminClient = getHttpSolrClient(leaderProps.getBaseUrl())) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(30000); @@ -352,7 +352,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { long found1, found3; - try (HttpSolrClient adminClient = new HttpSolrClient(url2 + "/unloadcollection")) { + try (HttpSolrClient adminClient = getHttpSolrClient(url2 + "/unloadcollection")) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(30000); adminClient.commit(); @@ -360,7 +360,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { q.set("distrib", false); found1 = adminClient.query(q).getResults().getNumFound(); } - try (HttpSolrClient adminClient = new HttpSolrClient(url3 + "/unloadcollection")) { + try (HttpSolrClient adminClient = getHttpSolrClient(url3 + "/unloadcollection")) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(30000); adminClient.commit(); @@ -369,7 +369,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { found3 = adminClient.query(q).getResults().getNumFound(); } - try (HttpSolrClient adminClient = new HttpSolrClient(url4 + "/unloadcollection")) { + try (HttpSolrClient adminClient = getHttpSolrClient(url4 + "/unloadcollection")) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(30000); adminClient.commit(); @@ -387,7 +387,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest { private void testUnloadLotsOfCores() throws Exception { SolrClient client = clients.get(2); String url3 = getBaseUrl(client); - try (final HttpSolrClient adminClient = new HttpSolrClient(url3)) { + try (final HttpSolrClient adminClient = getHttpSolrClient(url3)) { adminClient.setConnectionTimeout(15000); adminClient.setSoTimeout(60000); int cnt = atLeast(3); diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java index 5faa065ae89..ddf6e51c224 100644 --- a/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java @@ -97,7 +97,7 @@ public class HdfsWriteToMultipleCollectionsTest extends BasicDistributedZkTest { List cloudClients = new ArrayList<>(); List threads = new ArrayList<>(); for (int i = 0; i < cnt; i++) { - CloudSolrClient client = new CloudSolrClient(zkServer.getZkAddress()); + CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress()); client.setDefaultCollection(ACOLLECTION + i); cloudClients.add(client); StoppableIndexingThread indexThread = new StoppableIndexingThread(null, client, "1", true, docCount, 1, true); diff --git a/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java b/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java index 601f4fe723a..aeb4cb7803c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java @@ -165,7 +165,7 @@ public class StressHdfsTest extends BasicDistributedZkTest { int i = 0; for (SolrClient client : clients) { - try (HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) { + try (HttpSolrClient c = getHttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) { int docCnt = random().nextInt(1000) + 1; for (int j = 0; j < docCnt; j++) { c.add(getDoc("id", i++, "txt_t", "just some random text for a doc")); diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java index 7875b7c6c13..1c9cbeedb26 100644 --- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java +++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java @@ -148,14 +148,14 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 { // Mostly to keep annoying logging messages from being sent out all the time. for (int idx = 0; idx < indexingThreads; ++idx) { - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); client.setDefaultMaxConnectionsPerHost(25); client.setConnectionTimeout(30000); client.setSoTimeout(60000); indexingClients.add(client); } for (int idx = 0; idx < queryThreads; ++idx) { - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); client.setDefaultMaxConnectionsPerHost(25); client.setConnectionTimeout(30000); client.setSoTimeout(30000); diff --git a/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java b/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java index c8b46306fc2..63afe6c6e7e 100644 --- a/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java +++ b/solr/core/src/test/org/apache/solr/core/TestDynamicLoading.java @@ -112,7 +112,7 @@ public class TestDynamicLoading extends AbstractFullDistribZkTestBase { assertEquals(TestBlobHandler.getAsString(map), ".system collection not available", map.get("msg")); - TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL, randomClient.getHttpClient())); + TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient())); waitForRecoveriesToFinish(".system", true); map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client); 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 eab3e87ec49..ec5280c73e7 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -156,7 +156,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { private static SolrClient createNewSolrClient(int port) { try { // setup the client... - HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME); + final String baseUrl = buildUrl(port) + "/" + DEFAULT_TEST_CORENAME; + HttpSolrClient client = getHttpSolrClient(baseUrl); client.setConnectionTimeout(15000); client.setSoTimeout(60000); client.setDefaultMaxConnectionsPerHost(100); @@ -277,7 +278,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { private HttpSolrClient adminClient(SolrClient client) { String adminUrl = ((HttpSolrClient)client).getBaseURL().replace("/collection1", ""); - return new HttpSolrClient(adminUrl); + return getHttpSolrClient(adminUrl); } @Test diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java index 29c0dd75239..3ef6259babe 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java @@ -79,7 +79,8 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase { private static SolrClient createNewSolrClient(int port) { try { // setup the client... - HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME); + final String baseUrl = buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME; + HttpSolrClient client = getHttpSolrClient(baseUrl); client.setConnectionTimeout(15000); client.setSoTimeout(60000); client.setDefaultMaxConnectionsPerHost(100); diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java index 1218783d7b2..a39a57e4be6 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java +++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java @@ -72,7 +72,8 @@ public class TestRestoreCore extends SolrJettyTestBase { private static SolrClient createNewSolrClient(int port) { try { // setup the client... - HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME); + final String baseUrl = buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME; + HttpSolrClient client = getHttpSolrClient(baseUrl); client.setConnectionTimeout(15000); client.setSoTimeout(60000); client.setDefaultMaxConnectionsPerHost(100); 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 89f4b2b2588..3d4a51d518f 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 @@ -254,7 +254,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 { JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr")); runner.start(); - try (HttpSolrClient client = new HttpSolrClient(runner.getBaseUrl() + "/corex")) { + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) { client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); SolrInputDocument doc = new SolrInputDocument(); @@ -263,7 +263,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 { client.commit(); } - try (HttpSolrClient client = new HttpSolrClient(runner.getBaseUrl().toString())) { + try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT); CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false); diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java index 16a3e875058..b44766898ba 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java @@ -67,8 +67,8 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase { createJetty(solrHome.getAbsolutePath()); String url = jetty.getBaseUrl().toString(); - collection1 = new HttpSolrClient(url + "/collection1"); - collection2 = new HttpSolrClient(url + "/collection2"); + collection1 = getHttpSolrClient(url + "/collection1"); + collection2 = getHttpSolrClient(url + "/collection2"); String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1"; String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2"; @@ -76,7 +76,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase { shard2 = urlCollection2.replaceAll("https?://", ""); //create second core - try (HttpSolrClient nodeClient = new HttpSolrClient(url)) { + try (HttpSolrClient nodeClient = getHttpSolrClient(url)) { CoreAdminRequest.Create req = new CoreAdminRequest.Create(); req.setCoreName("collection2"); req.setConfigSet("collection1"); diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java index 0c18b25fc24..960021eaadc 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java @@ -109,7 +109,8 @@ public class DistributedQueryElevationComponentTest extends BaseDistributedSearc assertEquals(true, document.getFieldValue("[elevated]")); // Force javabin format - HttpSolrClient client = new HttpSolrClient(((HttpSolrClient)clients.get(0)).getBaseURL()); + final String clientUrl = ((HttpSolrClient)clients.get(0)).getBaseURL(); + HttpSolrClient client = getHttpSolrClient(clientUrl); client.setParser(new BinaryResponseParser()); SolrQuery solrQuery = new SolrQuery("XXXX").setParam("qt", "/elevate").setParam("shards.qt", "/elevate").setRows(500).setFields("id,[elevated]") .setParam("enableElevation", "true").setParam("forceElevation", "true").setParam("elevateIds", "6", "wt", "javabin") diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrJ.java b/solr/core/src/test/org/apache/solr/search/TestSolrJ.java index b70205efd47..1fd485f9292 100644 --- a/solr/core/src/test/org/apache/solr/search/TestSolrJ.java +++ b/solr/core/src/test/org/apache/solr/search/TestSolrJ.java @@ -59,7 +59,7 @@ public class TestSolrJ extends SolrTestCaseJ4 { ConcurrentUpdateSolrClient concurrentClient = null; // server = concurrentClient = new ConcurrentUpdateSolrServer(addr,32,8); - client = concurrentClient = new ConcurrentUpdateSolrClient(addr,64,nConnections); + client = concurrentClient = getConcurrentUpdateSolrClient(addr,64,nConnections); client.deleteByQuery("*:*"); client.commit(); @@ -164,7 +164,7 @@ public class TestSolrJ extends SolrTestCaseJ4 { public void doCommitPerf() throws Exception { - try (HttpSolrClient client = new HttpSolrClient("http://127.0.0.1:8983/solr")) { + try (HttpSolrClient client = getHttpSolrClient("http://127.0.0.1:8983/solr")) { final RTimer timer = new RTimer(); 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 9bb4d21eec2..f1b64bc2cbd 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 @@ -117,8 +117,8 @@ public class TestDistribIDF extends SolrTestCaseJ4 { //Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - SolrClient solrClient = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString()); - SolrClient solrClient_local = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString()); + SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString()); + SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString()); SolrQuery query = new SolrQuery("cat:football"); query.setFields("*,score"); @@ -161,8 +161,8 @@ public class TestDistribIDF extends SolrTestCaseJ4 { //Test against all nodes for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) { - SolrClient solrClient = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString()); - SolrClient solrClient_local = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString()); + SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString()); + SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString()); SolrQuery query = new SolrQuery("cat:football"); query.setFields("*,score").add("collection", "collection1,collection2"); 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 96a8c146eb0..d24ef3e6014 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -59,6 +59,7 @@ import org.slf4j.LoggerFactory; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.singletonMap; +import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient; import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP; @@ -162,7 +163,7 @@ public class BasicAuthIntegrationTest extends TestMiniSolrCloudClusterBase { CollectionAdminRequest.Reload reload = new CollectionAdminRequest.Reload(); reload.setCollectionName(defaultCollName); - HttpSolrClient solrClient = new HttpSolrClient(baseUrl); + HttpSolrClient solrClient = getHttpSolrClient(baseUrl); try { rsp = solrClient.request(reload); fail("must have failed"); diff --git a/solr/core/src/test/org/apache/solr/update/processor/TestNamedUpdateProcessors.java b/solr/core/src/test/org/apache/solr/update/processor/TestNamedUpdateProcessors.java index 85f21905716..d3304f45074 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/TestNamedUpdateProcessors.java +++ b/solr/core/src/test/org/apache/solr/update/processor/TestNamedUpdateProcessors.java @@ -78,7 +78,8 @@ public class TestNamedUpdateProcessors extends AbstractFullDistribZkTestBase { HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size())); String baseURL = randomClient.getBaseURL(); - TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL.substring(0, baseURL.lastIndexOf('/')), randomClient.getHttpClient())); + final String solrClientUrl = baseURL.substring(0, baseURL.lastIndexOf('/')); + TestBlobHandler.createSystemCollection(getHttpSolrClient(solrClientUrl, randomClient.getHttpClient())); waitForRecoveriesToFinish(".system", true); TestBlobHandler.postAndCheck(cloudClient, baseURL.substring(0, baseURL.lastIndexOf('/')), blobName, TestDynamicLoading.generateZip(RuntimeUrp.class), 1); diff --git a/solr/core/src/test/org/apache/solr/util/TestSolrCLIRunExample.java b/solr/core/src/test/org/apache/solr/util/TestSolrCLIRunExample.java index 1a07d3124aa..28a58ff69e4 100644 --- a/solr/core/src/test/org/apache/solr/util/TestSolrCLIRunExample.java +++ b/solr/core/src/test/org/apache/solr/util/TestSolrCLIRunExample.java @@ -351,7 +351,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 { exampleSolrHomeDir.isDirectory()); if ("techproducts".equals(exampleName)) { - HttpSolrClient solrClient = new HttpSolrClient("http://localhost:" + bindPort + "/solr/" + exampleName); + HttpSolrClient solrClient = getHttpSolrClient("http://localhost:" + bindPort + "/solr/" + exampleName); SolrQuery query = new SolrQuery("*:*"); QueryResponse qr = solrClient.query(query); long numFound = qr.getResults().getNumFound(); @@ -439,7 +439,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 { CloudSolrClient cloudClient = null; try { - cloudClient = new CloudSolrClient(executor.solrCloudCluster.getZkServer().getZkAddress()); + cloudClient = getCloudSolrClient(executor.solrCloudCluster.getZkServer().getZkAddress()); cloudClient.connect(); cloudClient.setDefaultCollection(collectionName); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java index 4ad37260a94..bd1dd2ceeb8 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java @@ -32,7 +32,6 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -191,12 +190,17 @@ public class CloudSolrClient extends SolrClient { * "host1:2181,host2:2181,host3:2181/mysolrchroot" *

* "zoo1.example.com:2181,zoo2.example.com:2181,zoo3.example.com:2181" + * + * @deprecated use {@link Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost) { this.zkHost = zkHost; this.clientIsInternal = true; this.myClient = HttpClientUtil.createClient(null); - this.lbClient = new LBHttpSolrClient(myClient); + this.lbClient = new LBHttpSolrClient.Builder() + .withHttpClient(myClient) + .build(); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = true; @@ -226,14 +230,15 @@ public class CloudSolrClient extends SolrClient { * @param httpClient * the {@link HttpClient} instance to be used for all requests. The * provided httpClient should use a multi-threaded connection manager. + * + * @deprecated use {@link Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost, HttpClient httpClient) { this.zkHost = zkHost; this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; - this.lbClient = new LBHttpSolrClient(myClient); - this.lbClient.setRequestWriter(new BinaryRequestWriter()); - this.lbClient.setParser(new BinaryResponseParser()); + this.lbClient = createLBHttpSolrClient(myClient); this.updatesToLeaders = true; shutdownLBHttpSolrServer = true; lbClient.addQueryParams(STATE_VERSION); @@ -256,7 +261,9 @@ public class CloudSolrClient extends SolrClient { * @throws IllegalArgumentException * if the chroot value does not start with a forward slash. * @see #CloudSolrClient(String) + * @deprecated use {@link Builder} instead. */ + @Deprecated public CloudSolrClient(Collection zkHosts, String chroot) { this(zkHosts, chroot, null); } @@ -281,47 +288,64 @@ public class CloudSolrClient extends SolrClient { * @throws IllegalArgumentException * if the chroot value does not start with a forward slash. * @see #CloudSolrClient(String) + * @deprecated use {@link Builder} instead. */ + @Deprecated public CloudSolrClient(Collection zkHosts, String chroot, HttpClient httpClient) { - StringBuilder zkBuilder = new StringBuilder(); - int lastIndexValue = zkHosts.size() - 1; - int i = 0; - for (String zkHost : zkHosts) { - zkBuilder.append(zkHost); - if (i < lastIndexValue) { - zkBuilder.append(","); - } - i++; - } - if (chroot != null) { - if (chroot.startsWith("/")) { - zkBuilder.append(chroot); - } else { - throw new IllegalArgumentException( - "The chroot must start with a forward slash."); - } - } - - /* Log the constructed connection string and then initialize. */ - log.info("Final constructed zkHost string: " + zkBuilder.toString()); - - this.zkHost = zkBuilder.toString(); + this.zkHost = buildZkHostString(zkHosts, chroot); this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; - this.lbClient = new LBHttpSolrClient(myClient); - this.lbClient.setRequestWriter(new BinaryRequestWriter()); - this.lbClient.setParser(new BinaryResponseParser()); + this.lbClient = createLBHttpSolrClient(myClient); this.updatesToLeaders = true; shutdownLBHttpSolrServer = true; } + /** + * Create a new client object that connects to Zookeeper and is always aware + * of the SolrCloud state. If there is a fully redundant Zookeeper quorum and + * SolrCloud has enough replicas for every shard in a collection, there is no + * single point of failure. Updates will be sent to shard leaders by default. + * + * @param zkHosts + * A Java Collection (List, Set, etc) of HOST:PORT strings, one for + * each host in the zookeeper ensemble. Note that with certain + * Collection types like HashSet, the order of hosts in the final + * connect string may not be in the same order you added them. + * @param chroot + * A chroot value for zookeeper, starting with a forward slash. If no + * chroot is required, use null. + * @param httpClient + * the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a + * multi-threaded connection manager. If null, a default HttpClient will be used. + * @param lbSolrClient + * LBHttpSolrServer instance for requests. If null, a default HttpClient will be used. + * @param updatesToLeaders + * If true, sends updates to shard leaders. + * + * @deprecated use {@link Builder} instead. This will soon be a protected method, and will only + * be available for use in implementing subclasses. + */ + @Deprecated + public CloudSolrClient(Collection zkHosts, String chroot, HttpClient httpClient, LBHttpSolrClient lbSolrClient, boolean updatesToLeaders) { + this.zkHost = buildZkHostString(zkHosts, chroot); + this.updatesToLeaders = updatesToLeaders; + + this.clientIsInternal = httpClient == null; + this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; + + this.shutdownLBHttpSolrServer = lbSolrClient == null; + this.lbClient = lbSolrClient == null ? createLBHttpSolrClient(myClient) : lbSolrClient; + } + /** * @param zkHost * A zookeeper client endpoint. * @param updatesToLeaders * If true, sends updates only to shard leaders. * @see #CloudSolrClient(String) for full description and details on zkHost + * @deprecated use {@link CloudSolrClient.Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost, boolean updatesToLeaders) { this(zkHost, updatesToLeaders, null); } @@ -335,12 +359,16 @@ public class CloudSolrClient extends SolrClient { * the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a * multi-threaded connection manager. * @see #CloudSolrClient(String) for full description and details on zkHost + * @deprecated use {@link CloudSolrClient.Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost, boolean updatesToLeaders, HttpClient httpClient) { this.zkHost = zkHost; this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; - this.lbClient = new LBHttpSolrClient(myClient); + this.lbClient = new LBHttpSolrClient.Builder() + .withHttpClient(myClient) + .build(); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = updatesToLeaders; @@ -362,7 +390,9 @@ public class CloudSolrClient extends SolrClient { * @param lbClient * LBHttpSolrServer instance for requests. * @see #CloudSolrClient(String) for full description and details on zkHost + * @deprecated use {@link CloudSolrClient.Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient) { this(zkHost, lbClient, true); } @@ -375,7 +405,9 @@ public class CloudSolrClient extends SolrClient { * @param updatesToLeaders * If true, sends updates only to shard leaders. * @see #CloudSolrClient(String) for full description and details on zkHost + * @deprecated use {@link Builder} instead. */ + @Deprecated public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient, boolean updatesToLeaders) { this.zkHost = zkHost; this.lbClient = lbClient; @@ -1340,4 +1372,137 @@ public class CloudSolrClient extends SolrClient { } return results; } + + private static LBHttpSolrClient createLBHttpSolrClient(HttpClient httpClient) { + final LBHttpSolrClient lbClient = new LBHttpSolrClient.Builder() + .withHttpClient(httpClient) + .build(); + lbClient.setRequestWriter(new BinaryRequestWriter()); + lbClient.setParser(new BinaryResponseParser()); + + return lbClient; + } + + private static String buildZkHostString(Collection zkHosts, String chroot) { + if (zkHosts == null || zkHosts.isEmpty()) { + throw new IllegalArgumentException("Cannot create CloudSearchClient without valid ZooKeeper host; none specified!"); + } + + StringBuilder zkBuilder = new StringBuilder(); + int lastIndexValue = zkHosts.size() - 1; + int i = 0; + for (String zkHost : zkHosts) { + zkBuilder.append(zkHost); + if (i < lastIndexValue) { + zkBuilder.append(","); + } + i++; + } + if (chroot != null) { + if (chroot.startsWith("/")) { + zkBuilder.append(chroot); + } else { + throw new IllegalArgumentException( + "The chroot must start with a forward slash."); + } + } + + /* Log the constructed connection string and then initialize. */ + final String zkHostString = zkBuilder.toString(); + log.info("Final constructed zkHost string: " + zkHostString); + return zkHostString; + } + + /** + * Constructs {@link CloudSolrClient} instances from provided configuration. + */ + public static class Builder { + private Collection zkHosts; + private HttpClient httpClient; + private String zkChroot; + private LBHttpSolrClient loadBalancedSolrClient; + private boolean shardLeadersOnly; + + public Builder() { + this.zkHosts = new ArrayList(); + this.shardLeadersOnly = true; + } + + /** + * Provide a ZooKeeper client endpoint to be used when configuring {@link CloudSolrClient} instances. + * + * Method may be called multiple times. All provided values will be used. + * + * @param zkHost + * The client endpoint of the ZooKeeper quorum containing the cloud + * state. + */ + public Builder withZkHost(String zkHost) { + this.zkHosts.add(zkHost); + return this; + } + + /** + * Provides a {@link HttpClient} for the builder to use when creating clients. + */ + public Builder withHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * Provide a series of ZooKeeper client endpoints for the builder to use when creating clients. + * + * Method may be called multiple times. All provided values will be used. + * + * @param zkHosts + * A Java Collection (List, Set, etc) of HOST:PORT strings, one for + * each host in the ZooKeeper ensemble. Note that with certain + * Collection types like HashSet, the order of hosts in the final + * connect string may not be in the same order you added them. + */ + public Builder withZkHost(Collection zkHosts) { + this.zkHosts.addAll(zkHosts); + return this; + } + + /** + * Provides a ZooKeeper chroot for the builder to use when creating clients. + */ + public Builder withZkChroot(String zkChroot) { + this.zkChroot = zkChroot; + return this; + } + + /** + * Provides a {@link LBHttpSolrClient} for the builder to use when creating clients. + */ + public Builder withLBHttpSolrClient(LBHttpSolrClient loadBalancedSolrClient) { + this.loadBalancedSolrClient = loadBalancedSolrClient; + return this; + } + + /** + * Tells {@link Builder} that created clients should send updats only to shard leaders. + */ + public Builder sendUpdatesOnlyToShardLeaders() { + shardLeadersOnly = true; + return this; + } + + /** + * Tells {@link Builder} that created clients should send updates to all replicas for a shard. + */ + public Builder sendUpdatesToAllReplicasInShard() { + shardLeadersOnly = false; + return this; + } + + /** + * Create a {@link CloudSolrClient} based on the provided configuration. + */ + public CloudSolrClient build() { + return new CloudSolrClient(zkHosts, zkChroot, httpClient, loadBalancedSolrClient, shardLeadersOnly); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java index 5bec96a27f5..c58baadb070 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java @@ -16,6 +16,21 @@ */ package org.apache.solr.client.solrj.impl; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.invoke.MethodHandles; +import java.nio.charset.StandardCharsets; +import java.util.LinkedList; +import java.util.Locale; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; @@ -45,21 +60,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.invoke.MethodHandles; -import java.nio.charset.StandardCharsets; -import java.util.LinkedList; -import java.util.Locale; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - /** * ConcurrentUpdateSolrClient buffers all added documents and writes * them into open HTTP connections. This class is thread safe. @@ -96,7 +96,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient { * The buffer size before the documents are sent to the server * @param threadCount * The number of background threads used to empty the queue + * + * @deprecated use {@link Builder} instead. */ + @Deprecated public ConcurrentUpdateSolrClient(String solrServerUrl, int queueSize, int threadCount) { this(solrServerUrl, null, queueSize, threadCount); @@ -104,6 +107,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient { internalHttpClient = true; } + /** + * @deprecated use {@link Builder} instead. + */ + @Deprecated public ConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount) { this(solrServerUrl, client, queueSize, threadCount, ExecutorUtil.newMDCAwareCachedThreadPool( @@ -113,7 +120,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient { /** * Uses the supplied HttpClient to send documents to the Solr server. + * + * @deprecated use {@link Builder} instead. */ + @Deprecated public ConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount, ExecutorService es) { this(solrServerUrl, client, queueSize, threadCount, es, false); @@ -121,16 +131,30 @@ public class ConcurrentUpdateSolrClient extends SolrClient { /** * Uses the supplied HttpClient to send documents to the Solr server. + * + * @deprecated use {@link Builder} instead. This will soon be a + * protected method, and will only be available for use in implementing subclasses. */ + @Deprecated public ConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount, ExecutorService es, boolean streamDeletes) { - this.client = new HttpSolrClient(solrServerUrl, client); + this.internalHttpClient = (client == null); + this.client = new HttpSolrClient.Builder(solrServerUrl) + .withHttpClient(client) + .build(); this.client.setFollowRedirects(false); queue = new LinkedBlockingQueue<>(queueSize); this.threadCount = threadCount; runners = new LinkedList<>(); - scheduler = es; this.streamDeletes = streamDeletes; + + if (es != null) { + scheduler = es; + shutdownExecutor = false; + } else { + scheduler = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("concurrentUpdateScheduler")); + shutdownExecutor = true; + } } public Set getQueryParams() { @@ -274,6 +298,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient { method = new HttpPost(client.getBaseURL() + "/update" + requestParams.toQueryString()); + method.setEntity(template); method.addHeader("User-Agent", HttpSolrClient.AGENT); method.addHeader("Content-Type", contentType); @@ -530,4 +555,91 @@ public class ConcurrentUpdateSolrClient extends SolrClient { public void setRequestWriter(RequestWriter requestWriter) { client.setRequestWriter(requestWriter); } + + /** + * Constructs {@link ConcurrentUpdateSolrClient} instances from provided configuration. + */ + public static class Builder { + private String baseSolrUrl; + private HttpClient httpClient; + private int queueSize; + private int threadCount; + private ExecutorService executorService; + private boolean streamDeletes; + + /** + * Create a Builder object, based on the provided Solr URL. + * + * @param baseSolrUrl the base URL of the Solr server that will be targeted by any created clients. + */ + public Builder(String baseSolrUrl) { + this.baseSolrUrl = baseSolrUrl; + } + + /** + * Provides a {@link HttpClient} for the builder to use when creating clients. + */ + public Builder withHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * The number of documents to batch together before sending to Solr. + */ + public Builder withQueueSize(int queueSize) { + if (queueSize <= 0) { + throw new IllegalArgumentException("queueSize must be a positive integer."); + } + this.queueSize = queueSize; + return this; + } + + /** + * The number of threads used to empty {@link ConcurrentUpdateSolrClient}s queue. + */ + public Builder withThreadCount(int threadCount) { + if (threadCount <= 0) { + throw new IllegalArgumentException("threadCount must be a positive integer."); + } + + this.threadCount = threadCount; + return this; + } + + /** + * Provides the {@link ExecutorService} for clients to use when servicing requests. + */ + public Builder withExecutorService(ExecutorService executorService) { + this.executorService = executorService; + return this; + } + + /** + * Configures created clients to always stream delete requests. + */ + public Builder alwaysStreamDeletes() { + this.streamDeletes = true; + return this; + } + + /** + * Configures created clients to not stream delete requests. + */ + public Builder neverStreamDeletes() { + this.streamDeletes = false; + return this; + } + + /** + * Create a {@link ConcurrentUpdateSolrClient} based on the provided configuration options. + */ + public ConcurrentUpdateSolrClient build() { + if (baseSolrUrl == null) { + throw new IllegalArgumentException("Cannot create HttpSolrClient without a valid baseSolrUrl!"); + } + + return new ConcurrentUpdateSolrClient(baseSolrUrl, httpClient, queueSize, threadCount, executorService, streamDeletes); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java index b987afc032f..538a2b729b3 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java @@ -16,6 +16,23 @@ */ package org.apache.solr.client.solrj.impl; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.lang.invoke.MethodHandles; +import java.net.ConnectException; +import java.net.SocketTimeoutException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; @@ -61,24 +78,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.lang.invoke.MethodHandles; -import java.net.ConnectException; -import java.net.SocketTimeoutException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; - /** * A SolrClient implementation that talks directly to a Solr server via HTTP * @@ -157,16 +156,35 @@ public class HttpSolrClient extends SolrClient { * The URL of the Solr server. For example, " * http://localhost:8983/solr/" if you are using the * standard distribution Solr webapp on your local machine. + * @deprecated use {@link Builder} instead. */ + @Deprecated public HttpSolrClient(String baseURL) { this(baseURL, null, new BinaryResponseParser()); } + /** + * @deprecated use {@link Builder} instead. + */ + @Deprecated public HttpSolrClient(String baseURL, HttpClient client) { this(baseURL, client, new BinaryResponseParser()); } + /** + * @deprecated use {@link Builder} instead. + */ + @Deprecated public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) { + this(baseURL, client, parser, false); + } + + /** + * @deprecated use {@link Builder} instead. This will soon be a 'protected' + * method, and will only be available for use in implementing subclasses. + */ + @Deprecated + public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser, boolean allowCompression) { this.baseUrl = baseURL; if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); @@ -468,7 +486,7 @@ public class HttpSolrClient extends SolrClient { protected NamedList executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException { method.addHeader("User-Agent", AGENT); - + HttpEntity entity = null; InputStream respBody = null; boolean shouldClose = true; @@ -752,4 +770,60 @@ public class HttpSolrClient extends SolrClient { super(code, "Error from server at " + remoteHost + ": " + msg, th); } } + + /** + * Constructs {@link HttpSolrClient} instances from provided configuration. + */ + public static class Builder { + private String baseSolrUrl; + private HttpClient httpClient; + private ResponseParser responseParser; + private boolean compression; + + /** + * Create a Builder object, based on the provided Solr URL. + * + * By default, compression is not enabled in created HttpSolrClient objects. + * + * @param baseSolrUrl the base URL of the Solr server that will be targeted by any created clients. + */ + public Builder(String baseSolrUrl) { + this.baseSolrUrl = baseSolrUrl; + this.responseParser = new BinaryResponseParser(); + } + + /** + * Provides a {@link HttpClient} for the builder to use when creating clients. + */ + public Builder withHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * Provides a {@link ResponseParser} for created clients to use when handling requests. + */ + public Builder withResponseParser(ResponseParser responseParser) { + this.responseParser = responseParser; + return this; + } + + /** + * Chooses whether created {@link HttpSolrClient}s use compression by default. + */ + public Builder allowCompression(boolean compression) { + this.compression = compression; + return this; + } + + /** + * Create a {@link HttpSolrClient} based on provided configuration. + */ + public HttpSolrClient build() { + if (baseSolrUrl == null) { + throw new IllegalArgumentException("Cannot create HttpSolrClient without a valid baseSolrUrl!"); + } + return new HttpSolrClient(baseSolrUrl, httpClient, responseParser, compression); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java index 6d4711e8faf..0b83969f992 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java @@ -16,19 +16,6 @@ */ package org.apache.solr.client.solrj.impl; -import org.apache.http.client.HttpClient; -import org.apache.solr.client.solrj.*; -import org.apache.solr.client.solrj.request.IsUpdateRequest; -import org.apache.solr.client.solrj.request.RequestWriter; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.params.CommonParams; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.NamedList; -import org.apache.solr.common.util.SolrjNamedThreadFactory; -import org.apache.solr.common.SolrException; -import org.slf4j.MDC; - import java.io.IOException; import java.lang.ref.WeakReference; import java.net.ConnectException; @@ -36,9 +23,36 @@ import java.net.MalformedURLException; import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URL; -import java.util.concurrent.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.*; + +import org.apache.http.client.HttpClient; +import org.apache.solr.client.solrj.ResponseParser; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.request.IsUpdateRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.params.CommonParams; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.params.SolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.SolrjNamedThreadFactory; +import org.slf4j.MDC; /** * LBHttpSolrClient or "LoadBalanced HttpSolrClient" is a load balancing wrapper around @@ -206,19 +220,31 @@ public class LBHttpSolrClient extends SolrClient { } } + /** + * @deprecated use {@link Builder} instead. + */ + @Deprecated public LBHttpSolrClient(String... solrServerUrls) throws MalformedURLException { this(null, solrServerUrls); } - /** The provided httpClient should use a multi-threaded connection manager */ + /** + * The provided httpClient should use a multi-threaded connection manager + * @deprecated use {@link Builder} instead. + */ + @Deprecated public LBHttpSolrClient(HttpClient httpClient, String... solrServerUrl) { this(httpClient, new BinaryResponseParser(), solrServerUrl); } - /** The provided httpClient should use a multi-threaded connection manager */ + /** + * The provided httpClient should use a multi-threaded connection manager + * @deprecated use {@link Builder} instead. This will soon be a protected + * method and will only be available for use in implementing subclasses. + */ + @Deprecated public LBHttpSolrClient(HttpClient httpClient, ResponseParser parser, String... solrServerUrl) { clientIsInternal = (httpClient == null); - this.parser = parser; if (httpClient == null) { ModifiableSolrParams params = new ModifiableSolrParams(); if (solrServerUrl.length > 1) { @@ -231,6 +257,9 @@ public class LBHttpSolrClient extends SolrClient { } else { this.httpClient = httpClient; } + + this.parser = parser; + for (String s : solrServerUrl) { ServerWrapper wrapper = new ServerWrapper(makeSolrClient(s)); aliveServers.put(wrapper.getKey(), wrapper); @@ -260,7 +289,10 @@ public class LBHttpSolrClient extends SolrClient { } protected HttpSolrClient makeSolrClient(String server) { - HttpSolrClient client = new HttpSolrClient(server, httpClient, parser); + HttpSolrClient client = new HttpSolrClient.Builder(server) + .withHttpClient(httpClient) + .withResponseParser(parser) + .build(); if (requestWriter != null) { client.setRequestWriter(requestWriter); } @@ -717,4 +749,64 @@ public class LBHttpSolrClient extends SolrClient { private static final int CHECK_INTERVAL = 60 * 1000; //1 minute between checks private static final int NONSTANDARD_PING_LIMIT = 5; // number of times we'll ping dead servers not in the server list + /** + * Constructs {@link LBHttpSolrClient} instances from provided configuration. + */ + public static class Builder { + private final List baseSolrUrls; + private HttpClient httpClient; + private ResponseParser responseParser; + + public Builder() { + this.baseSolrUrls = new ArrayList(); + this.responseParser = new BinaryResponseParser(); + } + + /** + * Provide a Solr endpoint to be used when configuring {@link LBHttpSolrClient} instances. + * + * Method may be called multiple times. All provided values will be used. + */ + public Builder withBaseSolrUrl(String baseSolrUrl) { + this.baseSolrUrls.add(baseSolrUrl); + return this; + } + + /** + * Provide Solr endpoints to be used when configuring {@link LBHttpSolrClient} instances. + * + * Method may be called multiple times. All provided values will be used. + */ + public Builder withBaseSolrUrls(String... solrUrls) { + for (String baseSolrUrl : solrUrls) { + this.baseSolrUrls.add(baseSolrUrl); + } + return this; + } + + + /** + * Provides a {@link HttpClient} for the builder to use when creating clients. + */ + public Builder withHttpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * Provides a {@link ResponseParser} for created clients to use when handling requests. + */ + public Builder withResponseParser(ResponseParser responseParser) { + this.responseParser = responseParser; + return this; + } + + /** + * Create a {@link HttpSolrClient} based on provided configuration. + */ + public LBHttpSolrClient build() { + final String[] baseUrlArray = new String[baseSolrUrls.size()]; + return new LBHttpSolrClient(httpClient, responseParser, baseSolrUrls.toArray(baseUrlArray)); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java index e544c104252..cd992a4215c 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/SolrClientCache.java @@ -21,7 +21,7 @@ import java.io.Serializable; import java.lang.invoke.MethodHandles; import java.util.Map; import java.util.HashMap; -import java.util.Iterator; + import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; @@ -44,7 +44,9 @@ public class SolrClientCache implements Serializable { if (solrClients.containsKey(zkHost)) { client = (CloudSolrClient) solrClients.get(zkHost); } else { - client = new CloudSolrClient(zkHost); + client = new CloudSolrClient.Builder() + .withZkHost(zkHost) + .build(); client.connect(); solrClients.put(zkHost, client); } @@ -57,7 +59,8 @@ public class SolrClientCache implements Serializable { if (solrClients.containsKey(host)) { client = (HttpSolrClient) solrClients.get(host); } else { - client = new HttpSolrClient(host); + client = new HttpSolrClient.Builder(host) + .build(); solrClients.put(host, client); } return client; diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java index d316c83df09..53f5c8dd25e 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/DatabaseMetaDataImpl.java @@ -29,7 +29,7 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.util.SimpleOrderedMap; @@ -119,7 +119,7 @@ class DatabaseMetaDataImpl implements DatabaseMetaData { for (String node : liveNodes) { try { String nodeURL = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(node); - solrClient = new HttpSolrClient(nodeURL); + solrClient = new Builder(nodeURL).build(); QueryResponse rsp = solrClient.query(sysQuery); return String.valueOf(((SimpleOrderedMap) rsp.getResponse().get("lucene")).get("solr-spec-version")); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java index 07e6cb16200..c9c7b22e5ec 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/CloudSolrStream.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.ComparatorOrder; @@ -236,7 +237,9 @@ public class CloudSolrStream extends TupleStream implements Expressible { if(this.cache != null) { this.cloudSolrClient = this.cache.getCloudSolrClient(zkHost); } else { - this.cloudSolrClient = new CloudSolrClient(zkHost); + this.cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); this.cloudSolrClient.connect(); } constructStreams(); @@ -476,4 +479,4 @@ public class CloudSolrStream extends TupleStream implements Expressible { } } } -} \ No newline at end of file +} diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java index e4ae04cba68..3474257efc1 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/FacetStream.java @@ -19,7 +19,6 @@ package org.apache.solr.client.solrj.io.stream; import java.io.IOException; import java.util.HashMap; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -27,6 +26,7 @@ import java.util.Collections; import java.util.Map.Entry; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.ComparatorOrder; @@ -281,7 +281,9 @@ public class FacetStream extends TupleStream implements Expressible { if(cache != null) { cloudSolrClient = cache.getCloudSolrClient(zkHost); } else { - cloudSolrClient = new CloudSolrClient(zkHost); + cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); } FieldComparator[] adjustedSorts = adjustSorts(buckets, bucketSorts); @@ -479,4 +481,4 @@ public class FacetStream extends TupleStream implements Expressible { return bucketSorts[0]; } } -} \ No newline at end of file +} diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SolrStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SolrStream.java index 1c149cc4078..7ff8a4e0810 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SolrStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/SolrStream.java @@ -86,7 +86,7 @@ public class SolrStream extends TupleStream { if(cache == null) { - client = new HttpSolrClient(baseUrl); + client = new HttpSolrClient.Builder(baseUrl).build(); } else { client = cache.getHttpSolrClient(baseUrl); } @@ -230,4 +230,4 @@ public class SolrStream extends TupleStream { return fields; } -} \ No newline at end of file +} diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java index 478bc56074e..6ef49eaf04d 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/StatsStream.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.StreamComparator; @@ -162,7 +163,9 @@ public class StatsStream extends TupleStream implements Expressible { if(cache != null) { cloudSolrClient = cache.getCloudSolrClient(zkHost); } else { - cloudSolrClient = new CloudSolrClient(zkHost); + cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); } ModifiableSolrParams params = getParams(this.props); @@ -290,4 +293,4 @@ public class StatsStream extends TupleStream implements Expressible { map.put(stat+"("+field+")", val); } } -} \ No newline at end of file +} diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java index a52e8f9550b..e3434fc9131 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TopicStream.java @@ -33,7 +33,7 @@ import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.ComparatorOrder; @@ -218,7 +218,9 @@ public class TopicStream extends CloudSolrStream implements Expressible { if(cache != null) { cloudSolrClient = cache.getCloudSolrClient(zkHost); } else { - cloudSolrClient = new CloudSolrClient(zkHost); + cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); this.cloudSolrClient.connect(); } @@ -474,4 +476,4 @@ public class TopicStream extends CloudSolrStream implements Expressible { throw new IOException(e); } } -} \ No newline at end of file +} diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java index 67e52e630bd..9ddd3811514 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/UpdateStream.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.StreamComparator; @@ -219,7 +220,9 @@ public class UpdateStream extends TupleStream implements Expressible { if(this.cache != null) { this.cloudSolrClient = this.cache.getCloudSolrClient(zkHost); } else { - this.cloudSolrClient = new CloudSolrClient(zkHost); + this.cloudSolrClient = new Builder() + .withZkHost(zkHost) + .build(); this.cloudSolrClient.connect(); } } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java index 04807fe2e75..79a56aadf32 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleBinaryTest.java @@ -40,7 +40,7 @@ public class SolrExampleBinaryTest extends SolrExampleTests { try { // setup the server... String url = jetty.getBaseUrl().toString() + "/collection1"; - HttpSolrClient client = new HttpSolrClient( url ); + HttpSolrClient client = getHttpSolrClient(url); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setDefaultMaxConnectionsPerHost(100); client.setMaxTotalConnections(100); 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 6547bc13791..1dd074edf5d 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 @@ -220,7 +220,7 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase if (jetty != null) { // check system wide system handler + "/admin/info/system" String url = jetty.getBaseUrl().toString(); - try (HttpSolrClient adminClient = new HttpSolrClient(url)) { + try (HttpSolrClient adminClient = getHttpSolrClient(url)) { SolrQuery q = new SolrQuery(); q.set("qt", "/admin/info/system"); QueryResponse rsp = adminClient.query(q); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java index f1b77e4e38d..d6eb62a55cc 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleXMLTest.java @@ -37,7 +37,7 @@ public class SolrExampleXMLTest extends SolrExampleTests { public SolrClient createNewSolrClient() { try { String url = jetty.getBaseUrl().toString() + "/collection1"; - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); client.setUseMultiPartPost(random().nextBoolean()); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setDefaultMaxConnectionsPerHost(100); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java index 75a030d8fb7..6af6f731d2f 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java @@ -16,6 +16,8 @@ */ package org.apache.solr.client.solrj; +import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient; + import org.apache.http.impl.client.CloseableHttpClient; import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.client.solrj.impl.HttpClientUtil; @@ -39,7 +41,7 @@ public class SolrExceptionTest extends LuceneTestCase { // set a 1ms timeout to let the connection fail faster. httpClient = HttpClientUtil.createClient(null); HttpClientUtil.setConnectionTimeout(httpClient, 1); - SolrClient client = new HttpSolrClient("http://[ff01::114]:11235/solr/", httpClient); + SolrClient client = getHttpSolrClient("http://[ff01::114]:11235/solr/", httpClient); SolrQuery query = new SolrQuery("test123"); client.query(query); httpClient.close(); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java index dbef180a68e..a2978345dd7 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTest.java @@ -131,7 +131,7 @@ public class SolrSchemalessExampleTest extends SolrExampleTestsBase { try { // setup the server... String url = jetty.getBaseUrl().toString() + "/collection1"; - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setDefaultMaxConnectionsPerHost(100); client.setMaxTotalConnections(100); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java index 5bebd644617..195f0f83dfc 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java @@ -16,6 +16,17 @@ */ package org.apache.solr.client.solrj; +import java.io.File; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.TimeUnit; + import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import junit.framework.Assert; import org.apache.commons.io.FileUtils; @@ -40,17 +51,6 @@ import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.TimeUnit; - /** * Test for LBHttpSolrClient * @@ -110,7 +110,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 { docs.add(doc); } SolrResponseBase resp; - try (HttpSolrClient client = new HttpSolrClient(solrInstance.getUrl(), httpClient)) { + try (HttpSolrClient client = getHttpSolrClient(solrInstance.getUrl(), httpClient)) { resp = client.add(docs); assertEquals(0, resp.getStatus()); resp = client.commit(); @@ -134,7 +134,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 { for (int i = 0; i < solr.length; i++) { s[i] = solr[i].getUrl(); } - LBHttpSolrClient client = new LBHttpSolrClient(httpClient, s); + LBHttpSolrClient client = getLBHttpSolrClient(httpClient, s); client.setAliveCheckInterval(500); SolrQuery solrQuery = new SolrQuery("*:*"); Set names = new HashSet<>(); @@ -172,7 +172,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 { } public void testTwoServers() throws Exception { - LBHttpSolrClient client = new LBHttpSolrClient(httpClient, solr[0].getUrl(), solr[1].getUrl()); + LBHttpSolrClient client = getLBHttpSolrClient(httpClient, solr[0].getUrl(), solr[1].getUrl()); client.setAliveCheckInterval(500); SolrQuery solrQuery = new SolrQuery("*:*"); QueryResponse resp = null; @@ -209,7 +209,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 { params.set(HttpClientUtil.PROP_SO_TIMEOUT, 250); CloseableHttpClient myHttpClient = HttpClientUtil.createClient(params); try { - LBHttpSolrClient client = new LBHttpSolrClient(myHttpClient, s); + LBHttpSolrClient client = getLBHttpSolrClient(myHttpClient, s); client.setAliveCheckInterval(500); // Kill a server and test again diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java index 035619698eb..6022b9acc14 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java @@ -54,7 +54,7 @@ public class SolrExampleJettyTest extends SolrExampleTests { try { // setup the server... String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1/?core=xxx"; - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); Assert.fail("HttpSolrServer should not allow a path with a parameter: " + client.getBaseURL()); } catch( Exception ex ) { diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java index c3fa7846e61..093238d52d8 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java @@ -80,14 +80,8 @@ public class SolrExampleStreamingTest extends SolrExampleTests { public void testWaitOptions() throws Exception { // SOLR-3903 final List failures = new ArrayList<>(); - try (ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient - (jetty.getBaseUrl().toString() + "/collection1", 2, 2) { - @Override - public void handleError(Throwable ex) { - failures.add(ex); - } - }) { - + final String serverUrl = jetty.getBaseUrl().toString() + "/collection1"; + try (ConcurrentUpdateSolrClient concurrentClient = new FailureRecordingConcurrentUpdateSolrClient(serverUrl, 2, 2)) { int docId = 42; for (UpdateRequest.ACTION action : EnumSet.allOf(UpdateRequest.ACTION.class)) { for (boolean waitSearch : Arrays.asList(true, false)) { @@ -110,5 +104,18 @@ public class SolrExampleStreamingTest extends SolrExampleTests { null, failures.get(0)); } } + + class FailureRecordingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient { + private final List failures = new ArrayList<>(); + + public FailureRecordingConcurrentUpdateSolrClient(String serverUrl, int queueSize, int numThreads) { + super(serverUrl, null, queueSize, numThreads, null, false); + } + + @Override + public void handleError(Throwable ex) { + failures.add(ex); + } + } } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java index 2c7ac9d9652..23b73db534b 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java @@ -208,7 +208,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { public void testTimeout() throws Exception { SolrQuery q = new SolrQuery("*:*"); - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/slow/foo")) { + try(HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/slow/foo")) { client.setSoTimeout(2000); client.query(q, METHOD.GET); fail("No exception thrown."); @@ -228,7 +228,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { assertEquals(status + " didn't generate an UNKNOWN error code, someone modified the list of valid ErrorCode's w/o changing this test to work a different way", ErrorCode.UNKNOWN, ErrorCode.getErrorCode(status)); - try ( HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { DebugServlet.setErrorCode(status); try { SolrQuery q = new SolrQuery("foo"); @@ -245,7 +245,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testQuery() throws Exception { DebugServlet.clear(); - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { SolrQuery q = new SolrQuery("foo"); q.setParam("a", "\u1234"); try { @@ -369,7 +369,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testDelete() throws Exception { DebugServlet.clear(); - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { try { client.deleteById("id"); } catch (ParseException ignored) {} @@ -410,7 +410,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testGetById() throws Exception { DebugServlet.clear(); - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { Collection ids = Collections.singletonList("a"); try { client.getById("a"); @@ -433,7 +433,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testUpdate() throws Exception { DebugServlet.clear(); - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { UpdateRequest req = new UpdateRequest(); req.add(new SolrInputDocument()); req.setParam("a", "\u1234"); @@ -497,7 +497,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testRedirect() throws Exception { - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/redirect/foo")) { + final String clientUrl = jetty.getBaseUrl().toString() + "/redirect/foo"; + try (HttpSolrClient client = getHttpSolrClient(clientUrl)) { SolrQuery q = new SolrQuery("*:*"); // default = false try { @@ -524,9 +525,9 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testCompression() throws Exception { - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { SolrQuery q = new SolrQuery("*:*"); - + // verify request header gets set DebugServlet.clear(); try { @@ -564,7 +565,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { } // verify compressed response can be handled - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/collection1")) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString() + "/collection1")) { client.setAllowCompression(true); SolrQuery q = new SolrQuery("foo"); QueryResponse response = client.query(q); @@ -575,7 +576,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testCollectionParameters() throws IOException, SolrServerException { - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString())) { + try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "collection"); client.add("collection1", doc); @@ -584,7 +585,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { assertEquals(1, client.query("collection1", new SolrQuery("id:collection")).getResults().getNumFound()); } - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/collection1")) { + final String collection1Url = jetty.getBaseUrl().toString() + "/collection1"; + try (HttpSolrClient client = getHttpSolrClient(collection1Url)) { assertEquals(1, client.query(new SolrQuery("id:collection")).getResults().getNumFound()); } @@ -594,7 +596,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { public void testSetParametersExternalClient() throws IOException{ try (CloseableHttpClient httpClient = HttpClientUtil.createClient(null); - HttpSolrClient solrClient = new HttpSolrClient(jetty.getBaseUrl().toString(), httpClient)) { + HttpSolrClient solrClient = getHttpSolrClient(jetty.getBaseUrl().toString(), httpClient)) { try { solrClient.setMaxTotalConnections(1); @@ -611,7 +613,7 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testGetRawStream() throws SolrServerException, IOException{ try (CloseableHttpClient client = HttpClientUtil.createClient(null)) { - HttpSolrClient solrClient = new HttpSolrClient(jetty.getBaseUrl().toString() + "/collection1", + HttpSolrClient solrClient = getHttpSolrClient(jetty.getBaseUrl().toString() + "/collection1", client, null); QueryRequest req = new QueryRequest(); NamedList response = solrClient.request(req); @@ -698,8 +700,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { HttpClientUtil.addRequestInterceptor(changeRequestInterceptor); HttpClientUtil.addRequestInterceptor(cookieSettingRequestInterceptor); - try(HttpSolrClient server = new HttpSolrClient(jetty.getBaseUrl().toString() + - "/debug/foo")) { + final String clientUrl = jetty.getBaseUrl().toString() + "/debug/foo"; + try(HttpSolrClient server = getHttpSolrClient(clientUrl)) { SolrQuery q = new SolrQuery("foo"); q.setParam("a", "\u1234"); @@ -770,7 +772,8 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase { @Test public void testQueryString() throws Exception { - try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString() + "/debug/foo")) { + final String clientUrl = jetty.getBaseUrl().toString() + "/debug/foo"; + try(HttpSolrClient client = getHttpSolrClient(clientUrl)) { // test without request query params DebugServlet.clear(); client.setQueryParams(setOf("serverOnly")); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java new file mode 100644 index 00000000000..57692c75e3f --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientBuilderTest.java @@ -0,0 +1,90 @@ +package org.apache.solr.client.solrj.impl; + +import java.io.IOException; +import java.util.ArrayList; + +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class CloudSolrClientBuilderTest extends LuceneTestCase { + private static final String ANY_CHROOT = "/ANY_CHROOT"; + private static final String ANY_ZK_HOST = "ANY_ZK_HOST"; + private static final String ANY_OTHER_ZK_HOST = "ANY_OTHER_ZK_HOST"; + + @Test(expected = IllegalArgumentException.class) + public void testNoZkHostSpecified() { + new Builder() + .withZkChroot(ANY_CHROOT) + .build(); + } + + @Test + public void testSingleZkHostSpecified() throws IOException { + try(CloudSolrClient createdClient = new Builder() + .withZkHost(ANY_ZK_HOST) + .withZkChroot(ANY_CHROOT) + .build()) { + final String clientZkHost = createdClient.getZkHost(); + + assertTrue(clientZkHost.contains(ANY_ZK_HOST)); + } + } + + @Test + public void testSeveralZkHostsSpecifiedSingly() throws IOException { + try (CloudSolrClient createdClient = new Builder() + .withZkHost(ANY_ZK_HOST) + .withZkHost(ANY_OTHER_ZK_HOST) + .withZkChroot(ANY_CHROOT) + .build()) { + final String clientZkHost = createdClient.getZkHost(); + + assertTrue(clientZkHost.contains(ANY_ZK_HOST)); + assertTrue(clientZkHost.contains(ANY_OTHER_ZK_HOST)); + } + } + + @Test + public void testSeveralZkHostsSpecifiedTogether() throws IOException { + final ArrayList zkHosts = new ArrayList(); + zkHosts.add(ANY_ZK_HOST); + zkHosts.add(ANY_OTHER_ZK_HOST); + try(CloudSolrClient createdClient = new Builder() + .withZkHost(zkHosts) + .withZkChroot(ANY_CHROOT) + .build()) { + final String clientZkHost = createdClient.getZkHost(); + + assertTrue(clientZkHost.contains(ANY_ZK_HOST)); + assertTrue(clientZkHost.contains(ANY_OTHER_ZK_HOST)); + } + } + + @Test + public void testByDefaultConfiguresClientToSendUpdatesOnlyToShardLeaders() throws IOException { + try(CloudSolrClient createdClient = new Builder() + .withZkHost(ANY_ZK_HOST) + .withZkChroot(ANY_CHROOT) + .build()) { + assertTrue(createdClient.isUpdatesToLeaders() == true); + } + } +} diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java index 77d8d0fff3b..36aea5817d7 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java @@ -225,7 +225,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { params.add("q", "id:" + id); params.add("distrib", "false"); QueryRequest queryRequest = new QueryRequest(params); - try (HttpSolrClient solrClient = new HttpSolrClient(url)) { + try (HttpSolrClient solrClient = getHttpSolrClient(url)) { QueryResponse queryResponse = queryRequest.process(solrClient); SolrDocumentList docList = queryResponse.getResults(); assertTrue(docList.getNumFound() == 1); @@ -247,7 +247,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { assertTrue(docs.getNumFound() == 0); // Test Multi-Threaded routed updates for UpdateRequest - try (CloudSolrClient threadedClient = new CloudSolrClient(zkServer.getZkAddress())) { + try (CloudSolrClient threadedClient = getCloudSolrClient(zkServer.getZkAddress())) { threadedClient.setParallelUpdates(true); threadedClient.setDefaultCollection(collectionName); response = threadedClient.request(request); @@ -266,7 +266,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { params.add("q", "id:" + id); params.add("distrib", "false"); QueryRequest queryRequest = new QueryRequest(params); - try (HttpSolrClient solrClient = new HttpSolrClient(url)) { + try (HttpSolrClient solrClient = getHttpSolrClient(url)) { QueryResponse queryResponse = queryRequest.process(solrClient); SolrDocumentList docList = queryResponse.getResults(); assertTrue(docList.getNumFound() == 1); @@ -480,7 +480,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { SolrServerException, IOException { NamedList resp; - try (HttpSolrClient client = new HttpSolrClient(baseUrl + "/"+ collectionName)) { + try (HttpSolrClient client = getHttpSolrClient(baseUrl + "/"+ collectionName)) { client.setConnectionTimeout(15000); client.setSoTimeout(60000); ModifiableSolrParams params = new ModifiableSolrParams(); @@ -552,7 +552,8 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { SolrQuery q = new SolrQuery().setQuery("*:*"); HttpSolrClient.RemoteSolrException sse = null; - try (HttpSolrClient solrClient = new HttpSolrClient(r.getStr(ZkStateReader.BASE_URL_PROP) + "/"+collectionName)) { + final String url = r.getStr(ZkStateReader.BASE_URL_PROP) + "/" +collectionName; + try (HttpSolrClient solrClient = getHttpSolrClient(url)) { log.info("should work query, result {}", solrClient.query(q)); //no problem @@ -588,7 +589,9 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { log.info("the node which does not serve this collection{} ",theNode); assertNotNull(theNode); - try (SolrClient solrClient = new HttpSolrClient(theNode + "/"+collectionName)) { + + final String solrClientUrl = theNode + "/" + collectionName; + try (SolrClient solrClient = getHttpSolrClient(solrClientUrl)) { q.setParam(CloudSolrClient.STATE_VERSION, collectionName + ":" + (coll.getZNodeVersion()-1)); try { @@ -605,7 +608,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { } public void testShutdown() throws IOException { - try (CloudSolrClient client = new CloudSolrClient("[ff01::114]:33332")) { + try (CloudSolrClient client = getCloudSolrClient("[ff01::114]:33332")) { client.setZkConnectTimeout(100); client.connect(); fail("Expected exception"); @@ -622,7 +625,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { exception.expect(SolrException.class); exception.expectMessage("cluster not found/not ready"); - try (CloudSolrClient client = new CloudSolrClient(zkServer.getZkAddress() + "/xyz/foo")) { + try (CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress() + "/xyz/foo")) { client.setDefaultCollection(DEFAULT_COLLECTION); client.setZkClientTimeout(1000 * 60); client.connect(); @@ -636,7 +639,7 @@ public class CloudSolrClientTest extends AbstractFullDistribZkTestBase { params.set(HttpClientUtil.PROP_SO_TIMEOUT, 1000); try (CloseableHttpClient client = HttpClientUtil.createClient(params); - CloudSolrClient solrClient = new CloudSolrClient(zkServer.getZkAddress(), client)) { + CloudSolrClient solrClient = getCloudSolrClient(zkServer.getZkAddress(), client)) { assertTrue(solrClient.getLbClient().getHttpClient() == client); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java new file mode 100644 index 00000000000..3389b7fcb3b --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientBuilderTest.java @@ -0,0 +1,33 @@ +package org.apache.solr.client.solrj.impl; + +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Unit tests for {@link Builder}. + */ +public class ConcurrentUpdateSolrClientBuilderTest extends LuceneTestCase { + + @Test(expected = IllegalArgumentException.class) + public void testRejectsMissingBaseSolrUrl() { + new Builder(null).build(); + } +} diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java index bd5e6a25be2..5e2baeb6c84 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java @@ -147,17 +147,8 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase { final StringBuilder errors = new StringBuilder(); @SuppressWarnings("serial") - ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient(serverUrl, cussQueueSize, cussThreadCount) { - @Override - public void handleError(Throwable ex) { - errorCounter.incrementAndGet(); - errors.append(" "+ex); - } - @Override - public void onSuccess(HttpResponse resp) { - successCounter.incrementAndGet(); - } - }; + ConcurrentUpdateSolrClient concurrentClient = new OutcomeCountingConcurrentUpdateSolrClient(serverUrl, cussQueueSize, + cussThreadCount, successCounter, errorCounter, errors); concurrentClient.setPollQueueTime(0); @@ -224,4 +215,28 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase { } } } + + class OutcomeCountingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient { + private final AtomicInteger successCounter; + private final AtomicInteger failureCounter; + private final StringBuilder errors; + public OutcomeCountingConcurrentUpdateSolrClient(String serverUrl, int queueSize, int threadCount, + AtomicInteger successCounter, AtomicInteger failureCounter, StringBuilder errors) { + super(serverUrl, null, queueSize, threadCount, null, false); + + this.successCounter = successCounter; + this.failureCounter = failureCounter; + this.errors = errors; + } + + @Override + public void handleError(Throwable ex) { + failureCounter.incrementAndGet(); + errors.append(" "+ex); + } + @Override + public void onSuccess(HttpResponse resp) { + successCounter.incrementAndGet(); + } + } } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java new file mode 100644 index 00000000000..da56576034f --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java @@ -0,0 +1,76 @@ +package org.apache.solr.client.solrj.impl; + +import java.io.IOException; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.client.solrj.ResponseParser; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Unit tests for {@link Builder}. + */ +public class HttpSolrClientBuilderTest extends LuceneTestCase { + private static final String ANY_BASE_SOLR_URL = "ANY_BASE_SOLR_URL"; + private static final HttpClient ANY_HTTP_CLIENT = HttpClientBuilder.create().build(); + private static final ResponseParser ANY_RESPONSE_PARSER = new NoOpResponseParser(); + + @Test(expected = IllegalArgumentException.class) + public void testBaseSolrUrlIsRequired() { + new Builder(null) + .build(); + } + + @Test + public void testProvidesBaseSolrUrlToClient() throws IOException { + try (HttpSolrClient createdClient = new HttpSolrClient.Builder(ANY_BASE_SOLR_URL).build()) { + assertTrue(createdClient.getBaseURL().equals(ANY_BASE_SOLR_URL)); + } + } + + @Test + public void testProvidesHttpClientToClient() throws IOException { + try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL) + .withHttpClient(ANY_HTTP_CLIENT) + .build()) { + assertTrue(createdClient.getHttpClient().equals(ANY_HTTP_CLIENT)); + } + } + + @Test + public void testProvidesResponseParserToClient() throws IOException { + try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL) + .withResponseParser(ANY_RESPONSE_PARSER) + .build()) { + assertTrue(createdClient.getParser().equals(ANY_RESPONSE_PARSER)); + } + } + + @Test + public void testDefaultsToBinaryResponseParserWhenNoneProvided() throws IOException { + try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL) + .build()) { + final ResponseParser usedParser = createdClient.getParser(); + assertTrue(usedParser instanceof BinaryResponseParser); + } + } +} diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBuilderTest.java new file mode 100644 index 00000000000..6a02da5afbc --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrClientBuilderTest.java @@ -0,0 +1,65 @@ +package org.apache.solr.client.solrj.impl; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.lucene.util.LuceneTestCase; +import org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder; +import org.apache.solr.client.solrj.ResponseParser; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Unit tests for {@link Builder}. + */ +public class LBHttpSolrClientBuilderTest extends LuceneTestCase { + private static final String ANY_BASE_SOLR_URL = "ANY_BASE_SOLR_URL"; + private static final HttpClient ANY_HTTP_CLIENT = HttpClientBuilder.create().build(); + private static final ResponseParser ANY_RESPONSE_PARSER = new NoOpResponseParser(); + + @Test + public void providesHttpClientToClient() { + try(LBHttpSolrClient createdClient = new Builder() + .withBaseSolrUrl(ANY_BASE_SOLR_URL) + .withHttpClient(ANY_HTTP_CLIENT) + .build()) { + assertTrue(createdClient.getHttpClient().equals(ANY_HTTP_CLIENT)); + } + } + + @Test + public void providesResponseParserToClient() { + try(LBHttpSolrClient createdClient = new Builder() + .withBaseSolrUrl(ANY_BASE_SOLR_URL) + .withResponseParser(ANY_RESPONSE_PARSER) + .build()) { + assertTrue(createdClient.getParser().equals(ANY_RESPONSE_PARSER)); + } + } + + @Test + public void testDefaultsToBinaryResponseParserWhenNoneProvided() { + try(LBHttpSolrClient createdClient = new Builder() + .withBaseSolrUrl(ANY_BASE_SOLR_URL) + .build()) { + final ResponseParser usedParser = createdClient.getParser(); + + assertTrue(usedParser instanceof BinaryResponseParser); + } + } +} 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 a751459e596..00b7577d1de 100644 --- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java +++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java @@ -442,7 +442,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 { protected SolrClient createNewSolrClient(int port) { try { // setup the client... - HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME); + HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME); client.setConnectionTimeout(clientConnectionTimeout); client.setSoTimeout(clientSoTimeout); client.setDefaultMaxConnectionsPerHost(100); diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java index 0e77a471381..b5d1b989c2c 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java @@ -151,7 +151,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4 try { // setup the client... String url = jetty.getBaseUrl().toString() + "/" + "collection1"; - HttpSolrClient client = new HttpSolrClient( url ); + HttpSolrClient client = getHttpSolrClient(url); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setDefaultMaxConnectionsPerHost(100); client.setMaxTotalConnections(100); 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 4aed1356415..118c19421b7 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java @@ -16,33 +16,6 @@ */ package org.apache.solr; -import com.google.common.base.Charsets; -import org.apache.commons.io.FileUtils; -import org.apache.lucene.util.IOUtils; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.embedded.JettyConfig; -import org.apache.solr.client.solrj.embedded.JettySolrRunner; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.impl.NoOpResponseParser; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.UpdateResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.NamedList; -import org.apache.solr.core.CoreDescriptor; -import org.apache.solr.request.SolrQueryRequest; -import org.apache.solr.schema.IndexSchema; -import org.apache.solr.schema.SchemaField; -import org.apache.solr.servlet.DirectSolrConnection; -import org.noggit.JSONUtil; -import org.noggit.ObjectBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; @@ -61,6 +34,31 @@ import java.util.Properties; import java.util.Random; import java.util.Set; +import com.google.common.base.Charsets; +import org.apache.commons.io.FileUtils; +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.embedded.JettyConfig; +import org.apache.solr.client.solrj.embedded.JettySolrRunner; +import org.apache.solr.client.solrj.impl.NoOpResponseParser; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.response.UpdateResponse; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.params.SolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.core.CoreDescriptor; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.schema.IndexSchema; +import org.apache.solr.schema.SchemaField; +import org.apache.solr.servlet.DirectSolrConnection; +import org.noggit.JSONUtil; +import org.noggit.ObjectBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + @SolrTestCaseJ4.SuppressSSL //@LuceneTestCase.SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Lucene45","Appending","Asserting"}) @@ -418,7 +416,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 { public SolrClient getSolrJ() { if (solrj == null) { - solrj = new HttpSolrClient(getCollectionURL()); + solrj = getHttpSolrClient(getCollectionURL()); } 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 3ce252f9b4d..a98c62d3435 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -31,6 +31,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.invoke.MethodHandles; +import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -56,6 +57,7 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule; import org.apache.commons.codec.Charsets; import org.apache.commons.io.FileUtils; +import org.apache.http.client.HttpClient; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.index.IndexWriterConfig; @@ -67,7 +69,13 @@ import org.apache.lucene.util.QuickPatchThreadsFilter; import org.apache.lucene.util.TestUtil; import org.apache.solr.client.solrj.embedded.JettyConfig; import org.apache.solr.client.solrj.impl.HttpClientConfigurer; +import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; import org.apache.solr.client.solrj.impl.HttpClientUtil; +import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder; +import org.apache.solr.client.solrj.impl.LBHttpSolrClient; +import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.cloud.IpTables; import org.apache.solr.common.SolrDocument; @@ -2040,6 +2048,140 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { public static Object skewed(Object likely, Object unlikely) { return (0 == TestUtil.nextInt(random(), 0, 9)) ? unlikely : likely; } + + public static CloudSolrClient getCloudSolrClient(String zkHost) { + if (random().nextBoolean()) { + return new CloudSolrClient(zkHost); + } + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .build(); + } + + public static CloudSolrClient getCloudSolrClient(String zkHost, HttpClient httpClient) { + if (random().nextBoolean()) { + return new CloudSolrClient(zkHost, httpClient); + } + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .withHttpClient(httpClient) + .build(); + } + + public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly) { + if (random().nextBoolean()) { + return new CloudSolrClient(zkHost, shardLeadersOnly); + } + + if (shardLeadersOnly) { + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .sendUpdatesOnlyToShardLeaders() + .build(); + } + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .sendUpdatesToAllReplicasInShard() + .build(); + } + + public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly, HttpClient httpClient) { + if (random().nextBoolean()) { + return new CloudSolrClient(zkHost, shardLeadersOnly, httpClient); + } + + if (shardLeadersOnly) { + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .withHttpClient(httpClient) + .sendUpdatesOnlyToShardLeaders() + .build(); + } + return new CloudSolrClient.Builder() + .withZkHost(zkHost) + .withHttpClient(httpClient) + .sendUpdatesToAllReplicasInShard() + .build(); + } + + public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(String baseSolrUrl, int queueSize, int threadCount) { + if (random().nextBoolean()) { + return new ConcurrentUpdateSolrClient(baseSolrUrl, queueSize, threadCount); + } + return new ConcurrentUpdateSolrClient.Builder(baseSolrUrl) + .withQueueSize(queueSize) + .withThreadCount(threadCount) + .build(); + } + + public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(String baseSolrUrl, HttpClient httpClient, int queueSize, int threadCount) { + if (random().nextBoolean()) { + return new ConcurrentUpdateSolrClient(baseSolrUrl, httpClient, queueSize, threadCount); + } + return new ConcurrentUpdateSolrClient.Builder(baseSolrUrl) + .withHttpClient(httpClient) + .withQueueSize(queueSize) + .withThreadCount(threadCount) + .build(); + } + + public static LBHttpSolrClient getLBHttpSolrClient(HttpClient client, String... solrUrls) { + if (random().nextBoolean()) { + return new LBHttpSolrClient(client, solrUrls); + } + + return new LBHttpSolrClient.Builder() + .withHttpClient(client) + .withBaseSolrUrls(solrUrls) + .build(); + } + + public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls) throws MalformedURLException { + if (random().nextBoolean()) { + return new LBHttpSolrClient(solrUrls); + } + return new LBHttpSolrClient.Builder() + .withBaseSolrUrls(solrUrls) + .build(); + } + + public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, ResponseParser responseParser, boolean compression) { + if(random().nextBoolean()) { + return new HttpSolrClient(url, httpClient, responseParser, compression); + } + return new Builder(url) + .withHttpClient(httpClient) + .withResponseParser(responseParser) + .allowCompression(compression) + .build(); + } + + public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, ResponseParser responseParser) { + if(random().nextBoolean()) { + return new HttpSolrClient(url, httpClient, responseParser); + } + return new Builder(url) + .withHttpClient(httpClient) + .withResponseParser(responseParser) + .build(); + } + + public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient) { + if(random().nextBoolean()) { + return new HttpSolrClient(url, httpClient); + } + return new Builder(url) + .withHttpClient(httpClient) + .build(); + } + + public static HttpSolrClient getHttpSolrClient(String url) { + if(random().nextBoolean()) { + return new HttpSolrClient(url); + } + return new Builder(url) + .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 a584dbd450b..6028563bc16 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 @@ -16,11 +16,6 @@ */ package org.apache.solr.cloud; -import static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET; -import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES; -import static org.apache.solr.cloud.OverseerCollectionMessageHandler.SHARDS_PROP; -import static org.apache.solr.common.util.Utils.makeMap; - import java.io.File; import java.io.IOException; import java.lang.invoke.MethodHandles; @@ -90,6 +85,11 @@ import org.noggit.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET; +import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES; +import static org.apache.solr.cloud.OverseerCollectionMessageHandler.SHARDS_PROP; +import static org.apache.solr.common.util.Utils.makeMap; + /** * TODO: we should still test this works as a custom update chain as well as * what we test now - the default update chain @@ -272,7 +272,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes } protected CloudSolrClient createCloudClient(String defaultCollection) { - CloudSolrClient client = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean()); + CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean()); client.setParallelUpdates(random().nextBoolean()); if (defaultCollection != null) client.setDefaultCollection(defaultCollection); client.getLbClient().setConnectionTimeout(30000); @@ -1626,7 +1626,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes // setup the server... String baseUrl = buildUrl(port); String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + DEFAULT_COLLECTION; - HttpSolrClient client = new HttpSolrClient(url); + HttpSolrClient client = getHttpSolrClient(url); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setSoTimeout(60000); client.setDefaultMaxConnectionsPerHost(100); @@ -1640,7 +1640,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes protected SolrClient createNewSolrClient(String collection, String baseUrl) { try { // setup the server... - HttpSolrClient client = new HttpSolrClient(baseUrl + "/" + collection); + HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection); client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); client.setDefaultMaxConnectionsPerHost(100); client.setMaxTotalConnections(100); @@ -1726,7 +1726,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes if (commonCloudSolrClient == null) { boolean updatesToLeaders = random().nextBoolean(); boolean parallelUpdates = random().nextBoolean(); - commonCloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), + commonCloudSolrClient = getCloudSolrClient(zkServer.getZkAddress(), updatesToLeaders); commonCloudSolrClient.getLbClient().setConnectionTimeout(5000); commonCloudSolrClient.getLbClient().setSoTimeout(120000); 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 118f7bef621..d23b37cd4b8 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 @@ -42,6 +42,7 @@ import org.apache.solr.client.solrj.embedded.JettyConfig; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.embedded.SSLConfig; import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.ZkConfigManager; @@ -445,7 +446,9 @@ public class MiniSolrCloudCluster { } protected CloudSolrClient buildSolrClient() { - return new CloudSolrClient(getZkServer().getZkAddress()); + return new Builder() + .withZkHost(getZkServer().getZkAddress()) + .build(); } private static String getHostContextSuitableForServletContext(String ctx) {