dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1087443678


##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.solr.util;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.SolrXmlConfig;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+
+/** TODO NOCOMMIT document */
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final String CORE_DIR_PROP = "coreRootDirectory";
+  private EmbeddedSolrServer adminClient = null;
+  private EmbeddedSolrServer client = null;
+  private CoreContainer container = null;
+
+  private boolean clearCoreDirSysProp = false;
+
+  public EmbeddedSolrServer getAdminClient() {
+    return adminClient;
+  }
+
+  public void startSolr(Path solrHome) {
+    NodeConfig nodeConfig;
+    if (Files.exists(solrHome.resolve(SolrXmlConfig.SOLR_XML_FILE))) {
+      // existing solr.xml; perhaps not recommended for new/most tests
+
+      // solr.xml coreRootDirectory is best set to a temp directory in a test 
so that
+      //  (a) we don't load existing cores
+      //      Because it's better for tests to explicitly create cores.
+      //  (b) we don't write data in the test to a likely template directory
+      //  But a test can insist on something if it sets the property.
+      if (System.getProperty(CORE_DIR_PROP) == null) {
+        clearCoreDirSysProp = true;
+        System.setProperty(CORE_DIR_PROP, 
LuceneTestCase.createTempDir("cores").toString());
+      }
+
+      nodeConfig = SolrXmlConfig.fromSolrHome(solrHome, null);
+    } else {
+      // test oriented config (preferred)
+      nodeConfig = newNodeConfigBuilder(solrHome).build();
+    }
+
+    startSolr(nodeConfig);
+  }
+
+  public void startSolr(NodeConfig nodeConfig) {
+    container = new CoreContainer(nodeConfig);
+    container.load();
+    adminClient = new EmbeddedSolrServer(container, null);
+  }
+
+  public NodeConfig.NodeConfigBuilder newNodeConfigBuilder(Path solrHome) {
+    // TODO nocommit dedupe this with TestHarness
+    var updateShardHandlerConfig =
+        new UpdateShardHandlerConfig(
+            HttpClientUtil.DEFAULT_MAXCONNECTIONS,
+            HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
+            30000,
+            30000,
+            UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY,
+            UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);

Review Comment:
   @joshgog still pending use in TestHarness



-- 
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: issues-unsubscr...@solr.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to