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


##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java:
##########
@@ -46,20 +51,73 @@
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.metrics.SolrCoreMetricManager;
 import org.apache.solr.metrics.SolrMetricManager;
+import org.apache.solr.util.EmbeddedSolrServerTestRule;
 import org.hamcrest.MatcherAssert;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
 import org.junit.rules.TestRule;
 
-public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
+public class TestCoreAdmin extends SolrTestCase {
 
   private static String tempDirProp;
 
+  @Rule public EmbeddedSolrServerTestRule solrClientTestRule = new 
EmbeddedSolrServerTestRule();
+
+  protected static Path SOLR_HOME;
+  protected static Path CONFIG_HOME;
+
+  protected CoreContainer cores = null;
+
   @Rule public TestRule testRule = RuleChain.outerRule(new 
SystemPropertiesRestoreRule());
 
+  @BeforeClass
+  public static void setUpHome() throws IOException {
+    // wtf?
+    if (System.getProperty("tempDir") != null) tempDirProp = 
System.getProperty("tempDir");
+    CONFIG_HOME = getFile("solrj/solr/shared").toPath().toAbsolutePath();
+    SOLR_HOME = createTempDir("solrHome");
+    FileUtils.copyDirectory(CONFIG_HOME.toFile(), SOLR_HOME.toFile());
+  }
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+
+    System.setProperty("solr.solr.home", SOLR_HOME.toString());
+    System.setProperty(
+        "configSetBaseDir", 
CONFIG_HOME.resolve("../configsets").normalize().toString());
+    System.out.println("Solr home: " + SOLR_HOME.toString());
+
+    // The index is always stored within a temporary directory
+    File tempDir = createTempDir().toFile();
+
+    File dataDir = new File(tempDir, "data1");
+    File dataDir2 = new File(tempDir, "data2");
+    System.setProperty("dataDir1", dataDir.getAbsolutePath());
+    System.setProperty("dataDir2", dataDir2.getAbsolutePath());
+    System.setProperty("tempDir", tempDir.getAbsolutePath());
+    System.setProperty("tests.shardhandler.randomSeed", 
Long.toString(random().nextLong()));
+    SolrTestCaseJ4.newRandomConfig();
+    solrClientTestRule.build().withSolrHome(SOLR_HOME).init();
+
+    solrClientTestRule
+        .newCollection(DEFAULT_TEST_COLLECTION_NAME)
+        
.withConfigSet(CONFIG_HOME.resolve("../configsets").normalize().toString())

Review Comment:
   a configSet reference is a simple name, not a path (although it's on disk in 
a like-named directory).  To know which to use, look in 
`solr/solrj/src/test-files/solrj/solr/shared/core0/core.properties` which 
points to one named "shared".



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.Path;
+import java.util.Collections;
+import java.util.List;
+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.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+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.CoreDescriptor;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+
+/** TODO NOCOMMIT document */
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private EmbeddedSolrServer adminClient = null;
+  private EmbeddedSolrServer client = null;
+
+  private CoreContainer container = null;
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  public class Builder {
+    private Path solrHome; // mandatory
+    private Path dataDir;
+    private RequestWriterSupplier requestWriterSupplier = 
RequestWriterSupplier.JavaBin;
+
+    public Builder withSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder withTempDataDir() {
+      this.dataDir = LuceneTestCase.createTempDir("data-dir");
+      return this;
+    }
+
+    public Builder withRequestWriterSupplier(RequestWriterSupplier 
requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public Path getDataDir() {
+      return this.dataDir;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+
+    NodeConfig nodeConfig = buildTestNodeConfig(b);
+
+    // TODO nocommit
+    var coreLocator =
+        new ReadOnlyCoresLocator() {
+          @Override
+          public List<CoreDescriptor> discover(CoreContainer cc) {
+            return Collections.emptyList();
+          }
+        };
+
+    container = new CoreContainer(nodeConfig, coreLocator);
+
+    container.load();
+
+    adminClient = new EmbeddedSolrServer(container, null, 
b.getRequestWriterSupplier());
+  }
+
+  public NewCollectionBuilder newCollection(String name) {
+    return new NewCollectionBuilder(name);
+  }
+
+  public class NewCollectionBuilder {
+    private String name;
+    private String configSet;
+    private String configFile;
+    private String schemaFile;
+
+    public NewCollectionBuilder(String name) {
+      this.name = name;
+    }
+
+    public NewCollectionBuilder withConfigSet(String configSet) {
+      this.configSet = configSet;
+      return this;
+    }
+
+    public NewCollectionBuilder withConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public NewCollectionBuilder withSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public String getConfigSet() {

Review Comment:
   Nobody is using this yet, thus this is probably why the test failed.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.Path;
+import java.util.Collections;
+import java.util.List;
+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.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+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.CoreDescriptor;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+
+/** TODO NOCOMMIT document */
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private EmbeddedSolrServer adminClient = null;
+  private EmbeddedSolrServer client = null;
+
+  private CoreContainer container = null;
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  public class Builder {
+    private Path solrHome; // mandatory
+    private Path dataDir;
+    private RequestWriterSupplier requestWriterSupplier = 
RequestWriterSupplier.JavaBin;
+
+    public Builder withSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder withTempDataDir() {
+      this.dataDir = LuceneTestCase.createTempDir("data-dir");
+      return this;
+    }
+
+    public Builder withRequestWriterSupplier(RequestWriterSupplier 
requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public Path getDataDir() {
+      return this.dataDir;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+
+    NodeConfig nodeConfig = buildTestNodeConfig(b);
+
+    // TODO nocommit
+    var coreLocator =
+        new ReadOnlyCoresLocator() {
+          @Override
+          public List<CoreDescriptor> discover(CoreContainer cc) {
+            return Collections.emptyList();
+          }
+        };
+
+    container = new CoreContainer(nodeConfig, coreLocator);
+
+    container.load();
+
+    adminClient = new EmbeddedSolrServer(container, null, 
b.getRequestWriterSupplier());
+  }
+
+  public NewCollectionBuilder newCollection(String name) {
+    return new NewCollectionBuilder(name);
+  }
+
+  public class NewCollectionBuilder {
+    private String name;
+    private String configSet;
+    private String configFile;
+    private String schemaFile;
+
+    public NewCollectionBuilder(String name) {
+      this.name = name;
+    }
+
+    public NewCollectionBuilder withConfigSet(String configSet) {
+      this.configSet = configSet;
+      return this;
+    }
+
+    public NewCollectionBuilder withConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public NewCollectionBuilder withSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public String getConfigSet() {
+      return configSet;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public void create() throws SolrServerException, IOException {
+      EmbeddedSolrServerTestRule.this.create(this);
+    }
+  }
+
+  private void create(NewCollectionBuilder b) throws SolrServerException, 
IOException {
+
+    client = new EmbeddedSolrServer(container, b.getName());
+
+    CoreAdminRequest.createCore(

Review Comment:
   I recommend inlining this so that you can set the configSet.



##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.Path;
+import java.util.Collections;
+import java.util.List;
+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.embedded.EmbeddedSolrServer.RequestWriterSupplier;
+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.CoreDescriptor;
+import org.apache.solr.core.NodeConfig;
+import org.apache.solr.update.UpdateShardHandlerConfig;
+
+/** TODO NOCOMMIT document */
+public class EmbeddedSolrServerTestRule extends SolrClientTestRule {
+
+  private EmbeddedSolrServer adminClient = null;
+  private EmbeddedSolrServer client = null;
+
+  private CoreContainer container = null;
+
+  public Builder build() {
+    return new Builder();
+  }
+
+  public class Builder {
+    private Path solrHome; // mandatory
+    private Path dataDir;
+    private RequestWriterSupplier requestWriterSupplier = 
RequestWriterSupplier.JavaBin;
+
+    public Builder withSolrHome(Path solrHome) {
+      this.solrHome = solrHome;
+      return this;
+    }
+
+    public Builder withTempDataDir() {
+      this.dataDir = LuceneTestCase.createTempDir("data-dir");
+      return this;
+    }
+
+    public Builder withRequestWriterSupplier(RequestWriterSupplier 
requestWriterSupplier) {
+      this.requestWriterSupplier = requestWriterSupplier;
+      return this;
+    }
+
+    public Path getSolrHome() {
+      return solrHome;
+    }
+
+    public Path getDataDir() {
+      return this.dataDir;
+    }
+
+    public RequestWriterSupplier getRequestWriterSupplier() {
+      return requestWriterSupplier;
+    }
+
+    public void init() {
+      EmbeddedSolrServerTestRule.this.init(this);
+    }
+  }
+
+  private void init(Builder b) {
+
+    NodeConfig nodeConfig = buildTestNodeConfig(b);
+
+    // TODO nocommit
+    var coreLocator =
+        new ReadOnlyCoresLocator() {
+          @Override
+          public List<CoreDescriptor> discover(CoreContainer cc) {
+            return Collections.emptyList();
+          }
+        };
+
+    container = new CoreContainer(nodeConfig, coreLocator);
+
+    container.load();
+
+    adminClient = new EmbeddedSolrServer(container, null, 
b.getRequestWriterSupplier());
+  }
+
+  public NewCollectionBuilder newCollection(String name) {
+    return new NewCollectionBuilder(name);
+  }
+
+  public class NewCollectionBuilder {
+    private String name;
+    private String configSet;
+    private String configFile;
+    private String schemaFile;
+
+    public NewCollectionBuilder(String name) {
+      this.name = name;
+    }
+
+    public NewCollectionBuilder withConfigSet(String configSet) {
+      this.configSet = configSet;
+      return this;
+    }
+
+    public NewCollectionBuilder withConfigFile(String configFile) {
+      this.configFile = configFile;
+      return this;
+    }
+
+    public NewCollectionBuilder withSchemaFile(String schemaFile) {
+      this.schemaFile = schemaFile;
+      return this;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public String getConfigSet() {
+      return configSet;
+    }
+
+    public String getConfigFile() {
+      return configFile;
+    }
+
+    public String getSchemaFile() {
+      return schemaFile;
+    }
+
+    public void create() throws SolrServerException, IOException {
+      EmbeddedSolrServerTestRule.this.create(this);
+    }
+  }
+
+  private void create(NewCollectionBuilder b) throws SolrServerException, 
IOException {
+
+    client = new EmbeddedSolrServer(container, b.getName());
+
+    CoreAdminRequest.createCore(
+        b.getName(),
+        container.getCoreRootDirectory().resolve(b.getName()).toString(),

Review Comment:
   can be simply `b.getName()` as it's relative to the core root dir.



-- 
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