You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/12/27 06:57:59 UTC

[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer

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


##########
solr/core/src/test/org/apache/solr/update/RootFieldTest.java:
##########
@@ -124,4 +132,8 @@ public void testUpdateWithChildDocs() throws Exception {
     }
     client.commit();
   }
+
+  public EmbeddedSolrServer getSolrClient() {
+    return solrClientTestRule.getSolrClient();
+  }

Review Comment:
   Isn't this already defined on EmbeddedSolrServerTestRule?  (if so, then we needn't specify this)



##########
solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java:
##########
@@ -30,15 +35,19 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    initCore();
+    solrClientTestRule
+        .build()
+        .setSolrHome(Paths.get(SolrJettyTestBase.legacyExampleCollection1SolrHome()))
+        .init();
   }
 
   @Before
   @Override
   public void setUp() throws Exception {
     super.setUp();
-    getSolrClient().deleteByQuery("*:*");
-    getSolrClient()
+    solrClientTestRule.getSolrClient().deleteByQuery("*:*");
+    solrClientTestRule
+        .getSolrClient()

Review Comment:
   Here and in many places in this file, you no longer call getSolrClient(), instead, more verbosely, you go to the solrClientTestRule first.  Is getSolrClient is still defined in EmbeddedSolrServerTestBase which is fine to continue to use?



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName, b.getRequestWriterSupplier());
+    } else if (schemaFile != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName);
+
+    } else {
+      client = new EmbeddedSolrServer(solrHome, collectionName);
+    }
+  }
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  @Override
+  protected void after() {
+
+    try {
+
+      client.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    client.getCoreContainer().shutdown();
+  }
+
+  @Override
+  public EmbeddedSolrServer getSolrClient() {
+    return client;
+  }
+
+  @Override
+  public void clearIndex() throws SolrServerException, IOException {
+    client.deleteByQuery("*:*");

Review Comment:
   if you can combine a delete & commit at the same time; it'd be perfect.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {

Review Comment:
   if it's already a RuntimeException, don't wrap it



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName, b.getRequestWriterSupplier());
+    } else if (schemaFile != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName);
+
+    } else {
+      client = new EmbeddedSolrServer(solrHome, collectionName);
+    }
+  }
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  @Override
+  protected void after() {
+
+    try {
+
+      client.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    client.getCoreContainer().shutdown();
+  }
+
+  @Override
+  public EmbeddedSolrServer getSolrClient() {
+    return client;

Review Comment:
   I would assert that the client isn't null.  I doubt any test checks for null-ness; they assume it's set.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName, b.getRequestWriterSupplier());
+    } else if (schemaFile != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName);
+
+    } else {
+      client = new EmbeddedSolrServer(solrHome, collectionName);
+    }
+  }
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  @Override
+  protected void after() {
+
+    try {
+
+      client.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    client.getCoreContainer().shutdown();
+  }
+
+  @Override
+  public EmbeddedSolrServer getSolrClient() {
+    return client;
+  }
+
+  @Override
+  public void clearIndex() throws SolrServerException, IOException {
+    client.deleteByQuery("*:*");
+  }
+
+  @Override
+  public Path getSolrHome() {
+    return Path.of(client.getCoreContainer().getSolrHome());
+  }
+
+  // From TestHarness
+  private static class TestCoresLocator extends ReadOnlyCoresLocator {
+
+    final String coreName;
+    final String dataDir;
+    final String solrConfig;
+    final String schema;
+
+    public TestCoresLocator(String coreName, String dataDir, String solrConfig, String schema) {
+      this.coreName = coreName == null ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
+      this.dataDir = dataDir;
+      this.schema = schema;
+      this.solrConfig = solrConfig;
+    }
+
+    @Override
+    public List<CoreDescriptor> discover(CoreContainer cc) {
+      return ImmutableList.of(
+          new CoreDescriptor(
+              coreName,
+              cc.getCoreRootDirectory().resolve(coreName),
+              cc,
+              CoreDescriptor.CORE_DATADIR,
+              dataDir,
+              CoreDescriptor.CORE_CONFIG,
+              solrConfig,
+              CoreDescriptor.CORE_SCHEMA,
+              schema,
+              CoreDescriptor.CORE_COLLECTION,
+              System.getProperty("collection", "collection1"),
+              CoreDescriptor.CORE_SHARD,
+              System.getProperty("shard", "shard1")));
+    }
+  }
+
+  // From TestHarness
+  private NodeConfig buildTestNodeConfig(Path solrHome) {
+    CloudConfig cloudConfig =
+        (null == System.getProperty("zkHost"))
+            ? null
+            : new CloudConfig.CloudConfigBuilder(
+                    System.getProperty("host"),
+                    Integer.getInteger("hostPort", 8983),
+                    System.getProperty("hostContext", ""))
+                .setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000))
+                .setZkHost(System.getProperty("zkHost"))
+                .build();
+    UpdateShardHandlerConfig updateShardHandlerConfig =
+        new UpdateShardHandlerConfig(
+            HttpClientUtil.DEFAULT_MAXCONNECTIONS,
+            HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
+            30000,
+            30000,
+            UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY,
+            UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
+    // universal default metric reporter
+    Map<String, Object> attributes = new HashMap<>();
+    attributes.put("name", "default");
+    attributes.put("class", SolrJmxReporter.class.getName());
+    PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
+    MetricsConfig metricsConfig =
+        new MetricsConfig.MetricsConfigBuilder()
+            .setMetricReporterPlugins(new PluginInfo[] {defaultPlugin})
+            .build();
+
+    return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
+        .setUseSchemaCache(Boolean.getBoolean("shareSchema"))

Review Comment:
   TODO remove



##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -32,17 +34,19 @@ public class SolrPingTest extends EmbeddedSolrServerTestBase {
   @BeforeClass
   public static void beforeClass() throws Exception {
     File testHome = createTempDir().toFile();
-    FileUtils.copyDirectory(getFile("solrj/solr"), testHome);
-    initCore("solrconfig.xml", "schema.xml", testHome.getAbsolutePath(), "collection1");
+    FileUtils.copyDirectory(SolrTestCaseJ4.getFile("solrj/solr"), testHome);
+
+    SolrTestCaseJ4.newRandomConfig();
+    // TODO NO COMMIT
+    solrClientTestRule.build().setSolrHome(testHome.toPath()).setSchemaFile("schema.xml").init();

Review Comment:
   We specify this as exactly `nocommit` (no space).
   
   Any way, I think you are now in a position to fix it by simply removing the needless schema reference.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;

Review Comment:
   should have a default as well



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());

Review Comment:
   should use builder's config for the schema



##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java:
##########
@@ -16,12 +16,17 @@
  */
 package org.apache.solr.client.solrj.embedded;
 
+import java.nio.file.Paths;
+import org.apache.solr.SolrJettyTestBase;
 import org.apache.solr.client.solrj.LargeVolumeTestBase;
 import org.junit.BeforeClass;
 
 public class LargeVolumeJettyTest extends LargeVolumeTestBase {
   @BeforeClass
   public static void beforeTest() throws Exception {
-    initCore();
+    solrClientTestRule

Review Comment:
   Let's add a TODO here.  AFAICT, long ago, @gerlowskija removed the Jetty aspect of this test, surely a mistake.



##########
solr/core/src/test/org/apache/solr/update/processor/AbstractAtomicUpdatesMultivalueTestBase.java:
##########
@@ -31,41 +33,46 @@
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import org.apache.solr.EmbeddedSolrServerTestBase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
 import org.hamcrest.MatcherAssert;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 public abstract class AbstractAtomicUpdatesMultivalueTestBase extends EmbeddedSolrServerTestBase {
 
-  @BeforeClass
-  public static void beforeClass() throws Exception {
+  protected static void initWithRequestWriter(RequestWriterSupplier requestWriterSupplier)
+      throws Exception {
     System.setProperty("enable.update.log", "true");
-    initCore("solrconfig.xml", "schema.xml");
+    SolrTestCaseJ4.newRandomConfig();
+    solrClientTestRule
+        .build()
+        .setSolrHome(Paths.get(SolrTestCaseJ4.TEST_HOME()))
+        .setRequestWriterSupplier(requestWriterSupplier)
+        .init();
   }
 
   @Before
   public void before() throws SolrServerException, IOException {
     getSolrClient().deleteByQuery("*:*");
   }
 
-  abstract RequestWriterSupplier getRequestWriterSupplier();
-
-  @Override
   public synchronized EmbeddedSolrServer getSolrClient() {
-    return new EmbeddedSolrServer(
-        h.getCoreContainer(), DEFAULT_CORE_NAME, getRequestWriterSupplier());
+    return solrClientTestRule.getSolrClient();
   }
 
-  private static void assertQR(
-      final String fieldName, final String queryValue, final int numFound) {
-    assertQ(
-        req("q", fieldName + ":" + queryValue, "indent", "true"),
-        "//result[@numFound = '" + numFound + "']");
+  private void assertQR(final String fieldName, final String queryValue, final int numFound)
+      throws SolrServerException, IOException {
+
+    SolrQuery query = new SolrQuery();
+    query.setParam("q", fieldName + ":" + queryValue);

Review Comment:
   note that SolrQuery has a constructor that would simplify this



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {

Review Comment:
   instead of if-else 3 branches, can't we always build basically one way?  Using the logic in this first branch.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName, b.getRequestWriterSupplier());
+    } else if (schemaFile != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName);
+
+    } else {
+      client = new EmbeddedSolrServer(solrHome, collectionName);
+    }
+  }
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  @Override
+  protected void after() {
+
+    try {
+
+      client.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    client.getCoreContainer().shutdown();
+  }
+
+  @Override
+  public EmbeddedSolrServer getSolrClient() {
+    return client;
+  }
+
+  @Override
+  public void clearIndex() throws SolrServerException, IOException {
+    client.deleteByQuery("*:*");
+  }
+
+  @Override
+  public Path getSolrHome() {
+    return Path.of(client.getCoreContainer().getSolrHome());
+  }
+
+  // From TestHarness
+  private static class TestCoresLocator extends ReadOnlyCoresLocator {
+
+    final String coreName;
+    final String dataDir;
+    final String solrConfig;
+    final String schema;
+
+    public TestCoresLocator(String coreName, String dataDir, String solrConfig, String schema) {
+      this.coreName = coreName == null ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
+      this.dataDir = dataDir;
+      this.schema = schema;
+      this.solrConfig = solrConfig;
+    }
+
+    @Override
+    public List<CoreDescriptor> discover(CoreContainer cc) {
+      return ImmutableList.of(
+          new CoreDescriptor(
+              coreName,
+              cc.getCoreRootDirectory().resolve(coreName),
+              cc,
+              CoreDescriptor.CORE_DATADIR,
+              dataDir,
+              CoreDescriptor.CORE_CONFIG,
+              solrConfig,
+              CoreDescriptor.CORE_SCHEMA,
+              schema,
+              CoreDescriptor.CORE_COLLECTION,
+              System.getProperty("collection", "collection1"),
+              CoreDescriptor.CORE_SHARD,
+              System.getProperty("shard", "shard1")));
+    }
+  }
+
+  // From TestHarness
+  private NodeConfig buildTestNodeConfig(Path solrHome) {
+    CloudConfig cloudConfig =
+        (null == System.getProperty("zkHost"))

Review Comment:
   Since EmbeddedSolrServer is not SolrCloud, you can assume "null" here.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,273 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.MetricsConfig;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.metrics.reporters.SolrJmxReporter;
+import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  private EmbeddedSolrServer client = null;
+
+  public EmbeddedSolrServerTestRule() {}
+
+  public class Builder {
+    private Path solrHome;
+    private String schemaFile;
+    private String configFile = "solrconfig.xml";
+    private String collectionName = "collection1";
+    private RequestWriterSupplier requestWriterSupplier;
+
+    public Builder setSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder setSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public Builder setConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public Builder setCollectionName(String collectionName) {
+      this.collectionName = collectionName;
+      return this;
+    }
+
+    public Builder setRequestWriterSupplier(RequestWriterSupplier requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getCollectionName() {
+      return collectionName;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+    Path solrHome = b.getSolrHome();
+    String schemaFile = b.getSchemaFile();
+    String configFile = b.getConfigFile();
+    String collectionName = b.getCollectionName();
+
+    if (b.getRequestWriterSupplier() != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName, b.getRequestWriterSupplier());
+    } else if (schemaFile != null) {
+      SolrConfig solrConfig;
+
+      try {
+        solrConfig = new SolrConfig(solrHome.resolve(collectionName), configFile);
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+
+      NodeConfig nodeConfig = buildTestNodeConfig(solrHome);
+
+      TestCoresLocator testCoreLocator =
+          new TestCoresLocator(
+              collectionName,
+              LuceneTestCase.createTempDir("data-dir").toFile().getAbsolutePath(),
+              solrConfig.getResourceName(),
+              IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig).getResourceName());
+
+      CoreContainer container = new CoreContainer(nodeConfig, testCoreLocator);
+      container.load();
+      client = new EmbeddedSolrServer(container, collectionName);
+
+    } else {
+      client = new EmbeddedSolrServer(solrHome, collectionName);
+    }
+  }
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  @Override
+  protected void after() {
+
+    try {
+
+      client.close();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    client.getCoreContainer().shutdown();
+  }
+
+  @Override
+  public EmbeddedSolrServer getSolrClient() {
+    return client;
+  }
+
+  @Override
+  public void clearIndex() throws SolrServerException, IOException {
+    client.deleteByQuery("*:*");

Review Comment:
   also, this is so generic that it cold be the base impl in the superclass



-- 
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-unsubscribe@solr.apache.org

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


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