This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 233eddbcfaa SOLR-17321: Fix TestSolrCoreSnapshots.testBackupRestore 
(#2539)
233eddbcfaa is described below

commit 233eddbcfaaf2c61ce367964b64ec73d9b5a1321
Author: Sanjay Dutt <[email protected]>
AuthorDate: Wed Jul 10 21:52:04 2024 +0530

    SOLR-17321: Fix TestSolrCoreSnapshots.testBackupRestore (#2539)
---
 .../apache/solr/handler/BackupRestoreUtils.java    | 64 ++++++++++++----------
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git 
a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java 
b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
index 200709ef9a2..bd610200895 100644
--- 
a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
+++ 
b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
@@ -21,11 +21,13 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.invoke.MethodHandles;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.lucene.tests.util.TestUtil;
 import org.apache.solr.SolrTestCase;
 import org.apache.solr.client.solrj.SolrClient;
@@ -75,42 +77,46 @@ public class BackupRestoreUtils extends SolrTestCase {
 
   public static void runCoreAdminCommand(
       String baseUrl, String coreName, String action, Map<String, String> 
params)
-      throws IOException {
-    StringBuilder builder = new StringBuilder();
-    builder.append(baseUrl);
-    builder.append("/admin/cores?action=");
-    builder.append(action);
-    builder.append("&core=");
-    builder.append(coreName);
-    for (Map.Entry<String, String> p : params.entrySet()) {
-      builder.append("&");
-      builder.append(p.getKey());
-      builder.append("=");
-      builder.append(p.getValue());
+      throws IOException, URISyntaxException {
+    final URI uri = new URI(baseUrl);
+    final var oldPath = uri.getPath() != null ? uri.getPath().substring(1) : 
"";
+    final var newPath = "admin/cores";
+    final var finalPath = oldPath.isEmpty() ? newPath : oldPath + "/" + 
newPath;
+
+    final URIBuilder builder =
+        new URIBuilder(uri)
+            .setPath(finalPath)
+            .addParameter("action", action)
+            .addParameter("core", coreName);
+
+    // Add additional parameters using loop
+    for (Map.Entry<String, String> entry : params.entrySet()) {
+      builder.addParameter(entry.getKey(), entry.getValue());
     }
-    String leaderUrl = builder.toString();
-    executeHttpRequest(leaderUrl);
+
+    executeHttpRequest(builder.build());
   }
 
   public static void runReplicationHandlerCommand(
       String baseUrl, String coreName, String action, String repoName, String 
backupName)
-      throws IOException {
-    String leaderUrl =
-        baseUrl
-            + "/"
-            + coreName
-            + ReplicationHandler.PATH
-            + "?command="
-            + action
-            + "&repository="
-            + repoName
-            + "&name="
-            + backupName;
-    executeHttpRequest(leaderUrl);
+      throws IOException, URISyntaxException {
+    final URI uri = new URI(baseUrl);
+    final var oldPath = uri.getPath() != null ? uri.getPath().substring(1) : 
"";
+    final var newPath = coreName + ReplicationHandler.PATH;
+    final var finalPath = oldPath.isEmpty() ? newPath : oldPath + "/" + 
newPath;
+
+    final URI finalURI =
+        new URIBuilder(uri)
+            .setPath(finalPath)
+            .addParameter("command", action)
+            .addParameter("repository", repoName)
+            .addParameter("name", backupName)
+            .build();
+    executeHttpRequest(finalURI);
   }
 
-  static void executeHttpRequest(String requestUrl) throws IOException {
-    URL url = URI.create(requestUrl).toURL();
+  private static void executeHttpRequest(URI uri) throws IOException {
+    URL url = uri.toURL();
     try (InputStream stream = url.openStream()) {
       assert stream != null;
     }

Reply via email to