orpiske commented on code in PR #14865:
URL: https://github.com/apache/camel/pull/14865#discussion_r1682653859


##########
components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrCloudFixture.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.solr;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+import org.apache.camel.util.IOHelper;
+import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.cloud.MiniSolrCloudCluster;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.params.CollectionParams.CollectionAction;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.embedded.JettySolrRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SolrCloudFixture {
+
+    private static final Logger LOG;
+    private static final Path TEMP_DIR;
+
+    /**
+     * Create a temp dir under the maven target folder
+     */
+    static {
+        LOG = LoggerFactory.getLogger(SolrCloudFixture.class);
+        TEMP_DIR = Paths.get("target", "tmp");
+        try {
+            Files.createDirectories(TEMP_DIR);
+            LOG.info("Created: " + TEMP_DIR);
+        } catch (IOException e) {
+            LOG.error("Unable to create " + TEMP_DIR, e);
+        }
+
+    }
+
+    MiniSolrCloudCluster miniCluster;
+    File testDir;
+    SolrZkClient zkClient;
+
+    CloudSolrClient solrClient;
+
+    public SolrCloudFixture(String solrHome) throws Exception {
+        String xml = IOHelper.loadText(new FileInputStream(new File(solrHome, 
"solr-no-core.xml")));
+        miniCluster = new MiniSolrCloudCluster(1, "/solr", TEMP_DIR, xml, 
null, null);
+        String zkAddr = miniCluster.getZkServer().getZkAddress();
+        String zkHost = miniCluster.getZkServer().getZkHost();
+
+        buildZooKeeper(zkHost, zkAddr, new File(solrHome), "solrconfig.xml", 
"schema.xml");
+        List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
+        for (JettySolrRunner jetty : jettys) {
+            if (!jetty.isRunning()) {
+                LOG.warn("JETTY NOT RUNNING!");
+            } else {
+                LOG.info("JETTY RUNNING AT " + jetty.getBaseUrl() + " PORT " + 
jetty.getLocalPort());
+            }
+        }
+
+        solrClient = new CloudHttp2SolrClient.Builder(Arrays.asList(zkAddr), 
Optional.empty())
+                .withDefaultCollection("collection1")
+                .build();
+        solrClient.connect();
+
+        createCollection(solrClient, "collection1", 1, 1, "conf1");
+        Thread.sleep(1000); // takes some time to setup the collection...
+                           // otherwise you'll get no live solr servers
+
+        SolrInputDocument doc = new SolrInputDocument();
+        doc.setField("id", "1");
+
+        solrClient.add(doc);
+        solrClient.commit();
+    }
+
+    public static void putConfig(String confName, SolrZkClient zkClient, File 
solrhome, final String name)
+            throws Exception {
+        putConfig(confName, zkClient, solrhome, name, name);
+    }
+
+    protected NamedList<Object> createCollection(
+            CloudSolrClient server, String name, int numShards,
+            int replicationFactor, String configName)
+            throws Exception {
+        ModifiableSolrParams modParams = new ModifiableSolrParams();
+        modParams.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
+        modParams.set("name", name);
+        modParams.set("numShards", numShards);
+        modParams.set("replicationFactor", replicationFactor);
+        modParams.set("collection.configName", configName);
+        QueryRequest request = new QueryRequest(modParams);
+        request.setPath("/admin/collections");
+        return server.request(request);
+    }
+
+    public static void putConfig(
+            String confName, SolrZkClient zkClient, File solrhome, final 
String srcName,
+            String destName)
+            throws Exception {
+        File file = new File(solrhome, "collection1" + File.separator + "conf" 
+ File.separator + srcName);
+        if (!file.exists()) {
+            LOG.info("zk skipping " + file.getAbsolutePath() + " because it 
doesn't exist");

Review Comment:
   Log placeholders here and in all other places.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to