Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
50ffdd0
SOLR-18390: remove test-framework HTTP client convenience helpers
serhiy-bzhezytskyy Aug 21, 2026
92ed892
SOLR-18390: evaluate Slice.getLeader() once per client, not twice
serhiy-bzhezytskyy Aug 21, 2026
0282e57
SOLR-18390: fix CI -- migrate solr:webapp's 8 missed JettySolrRunner.…
serhiy-bzhezytskyy Aug 22, 2026
ca5b912
SOLR-18390: reuse the runner's shared client instead of constructing …
serhiy-bzhezytskyy Aug 23, 2026
272fe02
SOLR-18390: also remove newClient(int, int) -- there are only 4 callers
serhiy-bzhezytskyy Aug 23, 2026
0455c86
SOLR-18390: remove an unnecessary bare block left over from the migra…
serhiy-bzhezytskyy Aug 23, 2026
ff141be
SOLR-18390: also reuse getSolrClient() where it's reachable via Cloud…
serhiy-bzhezytskyy Aug 23, 2026
cff9aa8
SOLR-18390: migrate TestCustomStream off the legacy AbstractFullDistr…
serhiy-bzhezytskyy Aug 23, 2026
0df6680
Merge remote-tracking branch 'origin/main' into SOLR-18390-remove-tes…
serhiy-bzhezytskyy Aug 24, 2026
41105da
Merge remote-tracking branch 'origin/main' into SOLR-18390-remove-tes…
serhiy-bzhezytskyy Aug 25, 2026
05f7509
SOLR-18390: apply newSolrClient() where a runner is in scope
serhiy-bzhezytskyy Aug 25, 2026
4da7efc
SOLR-18390: address David's review on the remaining call sites
serhiy-bzhezytskyy Aug 26, 2026
f90f2e4
Merge remote-tracking branch 'origin/main' into SOLR-18390-remove-tes…
serhiy-bzhezytskyy Aug 26, 2026
372160f
Merge remote-tracking branch 'origin/main' into SOLR-18390-remove-tes…
serhiy-bzhezytskyy Aug 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public void bootstrapJettyServer() throws Exception {

solrRunner = new JettySolrRunner(tmpSolrHome.toString(), buildJettyConfig());
solrRunner.start(false);
try (SolrClient client = solrRunner.newClient()) {
for (int i = 0; i < NUM_CORES; i++) {
createCore(client, "core-prefix-" + i);
}
SolrClient client = solrRunner.getSolrClient();
for (int i = 0; i < NUM_CORES; i++) {
createCore(client, "core-prefix-" + i);
}
solrRunner.stop();
}
Expand Down
3 changes: 2 additions & 1 deletion solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void testWithoutDistrib() throws SolrServerException, IOException {
coll.getSlices().stream()
.flatMap(s -> s.getReplicas().stream())
.toArray(Replica[]::new));
try (SolrClient client = getHttpSolrClient(randomReplica.getCoreUrl())) {
try (SolrClient client = new HttpJettySolrClient.Builder(randomReplica.getCoreUrl()).build()) {
response = client.query(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.MiniSolrCloudCluster;
Expand Down Expand Up @@ -376,7 +377,9 @@ protected void testExample(String exampleName) throws Exception {

if ("techproducts".equals(exampleName)) {
try (SolrClient solrClient =
getHttpSolrClient("http://localhost:" + bindPort + "/solr", exampleName)) {
new HttpJettySolrClient.Builder("http://localhost:" + bindPort + "/solr")
.withDefaultCollection(exampleName)
.build()) {
SolrQuery query = new SolrQuery("*:*");
QueryResponse qr = solrClient.query(query);
long numFound = qr.getResults().getNumFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,12 @@ private void searchSeveralWays(
// HttpSolrClient
JettySolrRunner jetty = cluster.getRandomJetty(random());
if (random().nextBoolean()) {
try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), collectionList)) {
try (SolrClient client = jetty.newSolrClient(collectionList)) {
responseConsumer.accept(client.query(null, solrQuery));
}
} else {
try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
responseConsumer.accept(client.query(collectionList, solrQuery));
}
SolrClient client = jetty.getSolrClient();
responseConsumer.accept(client.query(collectionList, solrQuery));
}

// Recursively do again; this time with the &collection= param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,17 @@ private void testNodeWithoutCollectionForwarding() throws Exception {

int docs = 2;
for (JettySolrRunner jetty : jettys) {
final String clientUrl = getBaseUrl(jetty);
addAndQueryDocs(clientUrl, docs);
addAndQueryDocs(jetty, docs);
docs += 2;
}
}

// 2 docs added every call
private void addAndQueryDocs(final String baseUrl, int docs) throws Exception {
private void addAndQueryDocs(final JettySolrRunner jetty, int docs) throws Exception {

SolrQuery query = new SolrQuery("*:*");

try (SolrClient client = getHttpSolrClient(baseUrl, "onenodecollection")) {
try (SolrClient client = jetty.newSolrClient("onenodecollection")) {
// add a doc
client.add(sdoc("id", docs));
client.commit();
Expand Down Expand Up @@ -441,27 +440,25 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception {
checkShardConsistency(true, false);

// try a backup command
try (final SolrClient client =
getHttpSolrClient((String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))) {
final String backupName = "the_backup";
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "backup");
params.set("name", backupName);
final Path location = FilterPath.unwrap(createTempDir()).toRealPath();
// Allow non-standard location outside SOLR_HOME
jettys.forEach(j -> j.getCoreContainer().getAllowPaths().add(location));
params.set("location", location.toString());

QueryRequest request = new QueryRequest(ReplicationHandler.PATH, params);
client.request(request, DEFAULT_TEST_COLLECTION_NAME);

final BackupStatusChecker backupStatus =
new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication");
final String backupDirName = backupStatus.waitForBackupSuccess(backupName, 30);
assertTrue(
"Backup dir does not exist: " + backupDirName,
Files.exists(location.resolve(backupDirName)));
}
final SolrClient client = shardToJetty.get(SHARD2).get(0).jetty.getSolrClient();
final String backupName = "the_backup";
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "backup");
params.set("name", backupName);
final Path location = FilterPath.unwrap(createTempDir()).toRealPath();
// Allow non-standard location outside SOLR_HOME
jettys.forEach(j -> j.getCoreContainer().getAllowPaths().add(location));
params.set("location", location.toString());

QueryRequest request = new QueryRequest(ReplicationHandler.PATH, params);
client.request(request, DEFAULT_TEST_COLLECTION_NAME);

final BackupStatusChecker backupStatus =
new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication");
final String backupDirName = backupStatus.waitForBackupSuccess(backupName, 30);
assertTrue(
"Backup dir does not exist: " + backupDirName,
Files.exists(location.resolve(backupDirName)));
}

private void addNewReplica() throws Exception {
Expand Down
163 changes: 61 additions & 102 deletions solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.lucene.util.IOUtils;
Expand All @@ -47,9 +46,9 @@
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.MetricsRequest;
Expand Down Expand Up @@ -111,8 +110,6 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
private String oneInstanceCollection = "oneInstanceCollection";
private String oneInstanceCollection2 = "oneInstanceCollection2";

private AtomicInteger nodeCounter = new AtomicInteger();

CompletionService<Object> completionService;
Set<Future<Object>> pending;

Expand Down Expand Up @@ -914,7 +911,10 @@ private long checkSlicesSameCounts(DocCollection dColl) throws SolrServerExcepti
for (Slice slice : dColl.getActiveSlices()) {
long sliceDocCount = -1;
for (Replica rep : slice.getReplicas()) {
try (SolrClient one = getHttpSolrClient(rep)) {
try (SolrClient one =
new HttpJettySolrClient.Builder(rep.getBaseUrl())
.withDefaultCollection(rep.getCoreName())
.build()) {
SolrQuery query = new SolrQuery("*:*");
query.setDistrib(false);
QueryResponse resp = one.query(query);
Expand Down Expand Up @@ -1043,26 +1043,25 @@ private void testShardParamVariations() throws Exception {

private void testStopAndStartCoresInOneInstance() throws Exception {
JettySolrRunner jetty = jettys.get(0);
try (final var httpSolrClient = jetty.newClient(15000, 60000)) {
ThreadPoolExecutor executor = null;
try {
executor =
new ExecutorUtil.MDCAwareThreadPoolExecutor(
0,
Integer.MAX_VALUE,
5,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new SolrNamedThreadFactory("testExecutor"));
int cnt = 3;

// create the cores
createCollectionInOneInstance(
httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt);
} finally {
if (executor != null) {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
var httpSolrClient = jetty.getSolrClient();
ThreadPoolExecutor executor = null;
try {
executor =
new ExecutorUtil.MDCAwareThreadPoolExecutor(
0,
Integer.MAX_VALUE,
5,
TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new SolrNamedThreadFactory("testExecutor"));
int cnt = 3;

// create the cores
createCollectionInOneInstance(
httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt);
} finally {
if (executor != null) {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
}

Expand Down Expand Up @@ -1379,47 +1378,46 @@ private void testANewCollectionInOneInstanceWithManualShardAssignement() throws
.getLeader("shard1");

// now test that unloading a core gets us a new leader
try (SolrClient unloadClient = jettys.getFirst().newClient(15000, 60000)) {
Unload unloadCmd = new Unload(true);
unloadCmd.setCoreName(leader.getCoreName());

String leaderUrl = leader.getCoreUrl();

testExecutor.execute(
new Runnable() {

@Override
public void run() {
try {
unloadClient.request(unloadCmd);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
SolrClient unloadClient = jettys.getFirst().getSolrClient();
Unload unloadCmd = new Unload(true);
unloadCmd.setCoreName(leader.getCoreName());

String leaderUrl = leader.getCoreUrl();

testExecutor.execute(
new Runnable() {

@Override
public void run() {
try {
unloadClient.request(unloadCmd);
} catch (SolrServerException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
});

try {
ZkStateReader.from(getCommonCloudSolrClient())
.waitForState(
oneInstanceCollection2,
20000,
TimeUnit.MILLISECONDS,
(n, c) -> {
try {
if (leaderUrl.equals(
zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) {
return false;
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
try {
ZkStateReader.from(getCommonCloudSolrClient())
.waitForState(
oneInstanceCollection2,
20000,
TimeUnit.MILLISECONDS,
(n, c) -> {
try {
if (leaderUrl.equals(
zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) {
return false;
}
return true;
});
} catch (TimeoutException | InterruptedException e) {
fail("Leader never changed");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return true;
});
} catch (TimeoutException | InterruptedException e) {
fail("Leader never changed");
}

IOUtils.close(collectionClients);
Expand Down Expand Up @@ -1497,45 +1495,6 @@ private void testANewCollectionInOneInstance() throws Exception {
IOUtils.close(collectionClients);
}

private void createSolrCore(
final String collection,
List<SolrClient> collectionClients,
final String baseUrl,
final int num,
final String shardId) {
Callable<Object> call =
() -> {
try (SolrClient client = getHttpSolrClient(baseUrl)) {
// client.setConnectionTimeout(15000);
Create createCmd = new Create();
createCmd.setCoreName(collection + num);
createCmd.setCollection(collection);

if (random().nextBoolean()) {
// sometimes we use an explicit core node name
createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet());
}

if (shardId == null) {
createCmd.setNumShards(2);
}
createCmd.setDataDir(getDataDir(createTempDir(collection).toString()));
if (shardId != null) {
createCmd.setShardId(shardId);
}
client.request(createCmd);
} catch (Exception e) {
log.error("error creating core", e);
// fail
}
return null;
};

pending.add(completionService.submit(call));

collectionClients.add(createNewSolrClient(baseUrl, collection + num));
}

private void testMultipleCollections() throws Exception {
log.info("### STARTING testMultipleCollections");
// create another 2 collections and search across them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void setupCluster() throws Exception {
clusterBuilder.configure();

// pick an arbitrary node to use for our requests
client = cluster.getRandomJetty(random()).newClient();
client = cluster.getRandomJetty(random()).newSolrClient(null);

CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1)
.processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException
String nodeName = response._getStr("success[0]/key");
String corename = response._getStr(asList("success", nodeName, "core"), null);

try (SolrClient coreClient =
getHttpSolrClient(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient);
assertEquals(
collectionName, status._get(asList("status", corename, "cloud", "collection"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null));
}
// nodeName is actually "nodeName/coreNodeName" (see CollectionHandlingUtils.requestKey)
SolrClient coreClient =
cluster.getJetty(nodeName.substring(0, nodeName.indexOf('/'))).getSolrClient();
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient);
assertEquals(
collectionName, status._get(asList("status", corename, "cloud", "collection"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null));
assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null));
}

@Test
Expand Down
Loading