Skip to content

Commit

Permalink
SOLR-17321: Fix TestSolrCoreSnapshots.testBackupRestore (#2539)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsanjay authored Jul 10, 2024
1 parent e9511d5 commit 233eddb
Showing 1 changed file with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
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;
Expand Down Expand Up @@ -75,42 +77,46 @@ public static void verifyDocs(int nDocs, SolrClient leaderClient, String collect

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;
}
Expand Down

0 comments on commit 233eddb

Please sign in to comment.