Skip to content

Apache Lucene open-source search software

SOLR-7125: Call process() before trying to upload/download configs

Alan Woodward4fbb2b36e8b9
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 e5216196de4..2adc7578dff 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
@@ -514,6 +514,7 @@ public class CloudSolrClient extends SolrClient {
* @throws IOException if an IO error occurs
*/
public void uploadConfig(Path configPath, String configName) throws IOException {
+ connect();
zkStateReader.getConfigManager().uploadConfigDir(configPath, configName);
}
@@ -524,6 +525,7 @@ public class CloudSolrClient extends SolrClient {
* @throws IOException if an I/O exception occurs
*/
public void downloadConfig(String configName, Path downloadPath) throws IOException {
+ connect();
zkStateReader.getConfigManager().downloadConfigDir(configName, downloadPath);
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
index 50eba190999..cce65518b35 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
@@ -21,9 +21,11 @@ import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.ZkConfigManager;
import org.junit.Test;
import java.io.File;
+import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
public class TestCloudSolrClientConnections extends SolrTestCaseJ4 {
@@ -61,4 +63,33 @@ public class TestCloudSolrClientConnections extends SolrTestCaseJ4 {
}
+ @Test
+ public void testCloudClientUploads() throws Exception {
+
+ File solrXml = getFile("solrj").toPath().resolve("solr/solr.xml").toFile();
+ Path configPath = getFile("solrj").toPath().resolve("solr/configsets/configset-2/conf");
+
+ MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(0, createTempDir().toFile(), solrXml, buildJettyConfig("/solr"));
+ try {
+ CloudSolrClient client = cluster.getSolrClient();
+ try {
+ client.uploadConfig(configPath, "testconfig");
+ fail("Requests to a non-running cluster should throw a SolrException");
+ } catch (SolrException e) {
+ assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("cluster not found/not ready"));
+ }
+
+ cluster.startJettySolrRunner();
+ client.connect(20, TimeUnit.SECONDS);
+
+ client.uploadConfig(configPath, "testconfig");
+
+ ZkConfigManager configManager = new ZkConfigManager(client.getZkStateReader().getZkClient());
+ assertTrue("List of uploaded configs does not contain 'testconfig'", configManager.listConfigs().contains("testconfig"));
+
+ } finally {
+ cluster.shutdown();
+ }
+ }
+
}