Skip to content

Commit

Permalink
SOLR-17066: Switch LBHttp2SolrClient away from core URLs
Browse files Browse the repository at this point in the history
SOLR-17066 introduced a withDefaultCollection builder method that can be
used in lieu of providing a core URL as a "base". (Core URLs are not
ideal as they prevent clients from making core-agnostic requests.)
However, Solr's own client usage still needs modified to use this new
builder method.

This commit migrates all LBHttp2SolrClient usage away from core
URLs and towards using `withDefaultCollection` instead.

Has a test failure in TestLBHttp2SolrClient that still needs resolved.
  • Loading branch information
gerlowskija committed Feb 2, 2024
1 parent 6b3080f commit 06a2065
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerEx
docs.add(doc);
}
SolrResponseBase resp;
try (SolrClient client = getHttpSolrClient(solrInstance.getUrl())) {
try (SolrClient client =
getHttpSolrClient(solrInstance.getBaseUrl(), solrInstance.getDefaultCollection())) {
resp = client.add(docs);
assertEquals(0, resp.getStatus());
resp = client.commit();
Expand All @@ -124,10 +125,12 @@ public void tearDown() throws Exception {
public void testSimple() throws Exception {
String[] solrUrls = new String[solr.length];
for (int i = 0; i < solr.length; i++) {
solrUrls[i] = solr[i].getUrl();
solrUrls[i] = solr[i].getBaseUrl();
}
final String collection = solr[0].getDefaultCollection();
try (LBHttp2SolrClient client =
new LBHttp2SolrClient.Builder(httpClient, solrUrls)
.withDefaultCollection(collection)
.setAliveCheckInterval(500, TimeUnit.MILLISECONDS)
.build()) {
SolrQuery solrQuery = new SolrQuery("*:*");
Expand Down Expand Up @@ -155,7 +158,7 @@ public void testSimple() throws Exception {
// Start the killed server once again
solr[1].startJetty();
// Wait for the alive check to complete
Thread.sleep(1200);
Thread.sleep(1200 * 5);
names.clear();
for (String ignored : solrUrls) {
resp = client.query(solrQuery);
Expand All @@ -166,17 +169,15 @@ public void testSimple() throws Exception {
}
}

private LBHttp2SolrClient getLBHttp2SolrClient(Http2SolrClient httpClient, String... s) {
return new LBHttp2SolrClient.Builder(httpClient, s).build();
}

public void testTwoServers() throws Exception {
String[] solrUrls = new String[2];
for (int i = 0; i < 2; i++) {
solrUrls[i] = solr[i].getUrl();
solrUrls[i] = solr[i].getBaseUrl();
}
final String collection = solr[0].getDefaultCollection();
try (LBHttp2SolrClient client =
new LBHttp2SolrClient.Builder(httpClient, solrUrls)
.withDefaultCollection(collection)
.setAliveCheckInterval(500, TimeUnit.MILLISECONDS)
.build()) {
SolrQuery solrQuery = new SolrQuery("*:*");
Expand Down Expand Up @@ -208,11 +209,12 @@ public void testTwoServers() throws Exception {
public void testReliability() throws Exception {
String[] solrUrls = new String[solr.length];
for (int i = 0; i < solr.length; i++) {
solrUrls[i] = solr[i].getUrl();
solrUrls[i] = solr[i].getBaseUrl();
}

final String collection = solr[0].getDefaultCollection();
try (LBHttp2SolrClient client =
new LBHttp2SolrClient.Builder(httpClient, solrUrls)
.withDefaultCollection(collection)
.setAliveCheckInterval(500, TimeUnit.MILLISECONDS)
.build()) {

Expand Down Expand Up @@ -271,7 +273,15 @@ public String getHomeDir() {
}

public String getUrl() {
return buildUrl(port) + "/collection1";
return getBaseUrl() + "/" + getDefaultCollection();
}

public String getBaseUrl() {
return buildUrl(port);
}

public String getDefaultCollection() {
return "collection1";
}

public String getSchemaFile() {
Expand Down

0 comments on commit 06a2065

Please sign in to comment.