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/07 12:11:05 UTC
[GitHub] [solr] joshgog opened a new pull request, #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
joshgog opened a new pull request, #1218:
URL: https://github.com/apache/solr/pull/1218
https://issues.apache.org/jira/browse/SOLR-XXXXX
<!--
_(If you are a project committer then you may remove some/all of the following template.)_
Before creating a pull request, please file an issue in the ASF Jira system for Solr:
* https://issues.apache.org/jira/projects/SOLR
For something minor (i.e. that wouldn't be worth putting in release notes), you can skip JIRA.
To create a Jira issue, you will need to create an account there first.
The title of the PR should reference the Jira issue number in the form:
* SOLR-####: <short description of problem or changes>
SOLR must be fully capitalized. A short description helps people scanning pull requests for items they can work on.
Properly referencing the issue in the title ensures that Jira is correctly updated with code review comments and commits. -->
# Description
Please provide a short description of the changes you're making with this pull request.
# Solution
Please provide a short description of the approach taken to implement your solution.
# Tests
Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.
# Checklist
Please review the following and check all that apply:
- [ ] I have reviewed the guidelines for [How to Contribute](https://wiki.apache.org/solr/HowToContribute) and my code conforms to the standards described there to the best of my ability.
- [ ] I have created a Jira issue and added the issue ID to my pull request title.
- [ ] I have given Solr maintainers [access](https://help.github.com/en/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to contribute to my PR branch. (optional but recommended)
- [ ] I have developed this patch against the `main` branch.
- [ ] I have run `./gradlew check`.
- [ ] I have added tests for my changes.
- [ ] I have added documentation for the [Reference Guide](https://github.com/apache/solr/tree/main/solr/solr-ref-guide)
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096789692
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java:
##########
@@ -104,4 +110,8 @@ protected SolrClient getSolrCore1() {
protected SolrClient getSolrCore(String name) {
return new EmbeddedSolrServer(cores, name);
}
+
+ protected SolrClient getSolrAdmin() {
Review Comment:
Cool... So in many of our tests we need an admin client that doesn't have a core/collection name in the path, and then a collection specific one, and this solves that first need?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097731269
##########
solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java:
##########
@@ -30,7 +35,9 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
Review Comment:
Usually it's a reflection of whoever wrote the test and was maybe arbitrary. I'm not sure we can strongly advocate one or the other. I like the empty home dir insofar as the node configuration (usually read from solr.xml) is non-existent so then the test infrastructure is in a position to tweak things for tests; perhaps being more minimalistic. Perhaps a no-arg startSolr() would make this easy-path even easier and thus used more, which is a good thing.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1085229423
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java:
##########
@@ -31,16 +35,19 @@ public class TermsResponseTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
Review Comment:
Does this need the "solrhome" parameter? When I see it, it makes me think it's important somehow.. I saw we also have the use of `.createTempDir()` with no name, is that better in the sense of conveying that it isn't important to have a named directory?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097692849
##########
solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java:
##########
@@ -32,6 +32,15 @@ public class UpdateShardHandlerConfig {
DEFAULT_METRICNAMESTRATEGY,
DEFAULT_MAXRECOVERYTHREADS);
+ public static final UpdateShardHandlerConfig TEST_DEFAULT =
Review Comment:
That's debatable... because there is no obvious place where it would live exactly. I suppose TestHarness *was* okay maybe but now that TestHarness has a competitor, ehh....
As it's just a "config" thing and not some heavy object, its home seems arbitrary to me -- not a problem that it's created in production. I don't have a strong opinion though.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1098782651
##########
solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java:
##########
@@ -35,7 +34,7 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
+ solrClientTestRule.startSolr();
Review Comment:
AWESOME!
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096789163
##########
solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java:
##########
@@ -41,7 +41,7 @@ public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase {
@Test
public void testMultiThreaded() throws Exception {
- SolrClient client = this.getSolrClient();
+ SolrClient client = getSolrClient();
Review Comment:
Should this be `solrClientTestRule.getSolrClient()` ? When do we want to use the explicit `solrClientTestRule` and when do we have a helper like `getSolrClient()`. In some ways, I like the explicit verbosity of the `solrClientTestRule.getSolrClient()` telling me where the client came from...
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1057835402
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
Review Comment:
I don't know the "Solr server" reference you speak about? Any way, this PR is an incremental step. Obviously there is no Jetty/HTTP or SolrCloud stuff in this PR.
--
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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "joshgog (via GitHub)" <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1087414035
##########
solr/core/src/test/org/apache/solr/update/RootFieldTest.java:
##########
@@ -54,7 +54,7 @@ public static void beforeTest() throws Exception {
solrClientTestRule.startSolr(Path.of(SolrTestCaseJ4.TEST_HOME()));
solrClientTestRule
- .newCollection(DEFAULT_TEST_COLLECTION_NAME)
Review Comment:
That was a misunderstanding. We aren't going away from using going away from using `DEFAULT_TEST_COLLECTION_NAME`
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097766488
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- clearIndex();
- assertU(commit());
- assertU(optimize());
+ solrClientTestRule.clearIndex();
Review Comment:
Thanks for clarifying!
--
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
[GitHub] [solr] dsmiley commented on pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on PR #1218:
URL: https://github.com/apache/solr/pull/1218#issuecomment-1418184560
This is ready! I'm looking to commit this Tuesday if I don't hear feedback to the contrary.
Suggested CHANGES.txt:
---------
SOLR-16573: Introduce EmbeddedSolrServerTestRule, a JUnit 4 TestRule for Solr testing. (Joshua Ouma, David Smiley)
Suggested commit summary:
---------
New SolrClientTestRule abstraction with one implementation: EmbeddedSolrServerTestRule
EmbeddedSolrServerTestBase and AbstractEmbeddedSolrServerTestCase were modified to use this abstraction, and yet were also marked deprecated to encourage direct use of the rule. A solr.xml file is optional. Some of the affected tests will run more efficiently because (A) they no longer do file I/O to create a temporary solr-home because the rule is able to use existing solr homes and configSets in-place and because (B) initCore() can double-parse a solrconfig.xml and schema.xml.
SolrTestCaseJ4 / SolrTestCase: Moved ObjectReleaseTracker checking to use a Rule so that it's compatible with Rules that use ObjectReleaseTracker.
--
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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "joshgog (via GitHub)" <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097310816
##########
solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java:
##########
@@ -41,7 +41,7 @@ public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase {
@Test
public void testMultiThreaded() throws Exception {
- SolrClient client = this.getSolrClient();
+ SolrClient client = getSolrClient();
Review Comment:
`getSolrClient()` in `EmbeddedSolrServerTestBase` returns `solrClientTestRule.getSolrClient()`
--
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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "joshgog (via GitHub)" <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097325228
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java:
##########
@@ -104,4 +110,8 @@ protected SolrClient getSolrCore1() {
protected SolrClient getSolrCore(String name) {
return new EmbeddedSolrServer(cores, name);
}
+
+ protected SolrClient getSolrAdmin() {
Review Comment:
True. The client used by these tests do not need a core
--
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
[GitHub] [solr] epugh commented on pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on PR #1218:
URL: https://github.com/apache/solr/pull/1218#issuecomment-1401850595
I think I am slowly starting to grok what this is all about... Let me see if I can state the value.... "Using a TestRule simplifies the setup of a test by abstracting away a lot of the Solr environment setup into the specific TestRule you choose. This means choosing the right TestRule to use is an important decision when writing a test, to make sure you have the right abstraction of Solr you need"...???
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1058297053
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -53,7 +55,7 @@ public class Builder {
private Path solrHome;
private String schemaFile = "schema.xml";
private String configFile = "solrconfig.xml";
- private String collectionName = "collection1";
+ private String collectionName = DEFAULT_TEST_COLLECTION_NAME;
Review Comment:
thanks!
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096788578
##########
solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java:
##########
@@ -32,6 +32,15 @@ public class UpdateShardHandlerConfig {
DEFAULT_METRICNAMESTRATEGY,
DEFAULT_MAXRECOVERYTHREADS);
+ public static final UpdateShardHandlerConfig TEST_DEFAULT =
Review Comment:
Shouldn't a TEST_DEFAULT be declared in some sort of testing class or in the Test Framework jar ???
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1060284411
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
Review Comment:
A good first start. I recommend that you review the [Javadoc style guide](https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#styleguide), especially around the importance of the first sentence and brevity generally. I think the first sentence should be the one you specified 2nd, so I suggest the following (along with some other changes).
```
Provides access to a {@link SolrClient} instance and a running Solr in tests.
Implementations could run Solr in different ways (e.g. strictly embedded, adding HTTP/Jetty, adding SolrCloud, or an external process).
It's a JUnit {@link ExternalResource} (a {@code TestRule}), and thus closes the client and Solr itself when the test completes.
This test utility is encouraged to be used by external projects that wish to test communicating with Solr, especially for plugin providers.
```
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Review Comment:
can be removed
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
+
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ }
Review Comment:
can be removed
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
+
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ }
+
+ public abstract SolrClient getSolrClient();
+
+ public void clearIndex() throws SolrServerException, IOException {
+ new UpdateRequest().deleteByQuery("*:*").commit(solrClientTestRule.getSolrClient(), null);
+ }
+
+ public abstract Path getSolrHome();
Review Comment:
needs docs.
BTW I recall there is some doubt as to wether we actually need this. I suspect we don't? If we can eliminate it -- even better.
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
+
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ }
+
+ public abstract SolrClient getSolrClient();
Review Comment:
needs docs
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
+
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ }
+
+ public abstract SolrClient getSolrClient();
+
+ public void clearIndex() throws SolrServerException, IOException {
Review Comment:
needs docs
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
Review Comment:
can be removed
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ protected SolrClientTestRule() {}
+
+ @Override
+ protected void before() throws Throwable {
+ super.before();
+ }
+
+ public abstract SolrClient getSolrClient();
+
+ public void clearIndex() throws SolrServerException, IOException {
+ new UpdateRequest().deleteByQuery("*:*").commit(solrClientTestRule.getSolrClient(), null);
Review Comment:
woah, this is suspicious -- the `solrClientTestRule.` part. What's going on here?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1061100619
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
+ return new Builder();
+ }
+
+ public class Builder {
+ private Path solrHome; // mandatory
+ private Path dataDir;
+ private String collectionName = DEFAULT_TEST_COLLECTION_NAME;
+ private String configFile;
+ private String schemaFile;
+ private RequestWriterSupplier requestWriterSupplier = RequestWriterSupplier.JavaBin;
+
+ public Builder setSolrHome(Path solrHome) {
+ this.solrHome = solrHome;
+ return this;
+ }
+
+ public Builder useTempDataDir() {
+ this.dataDir = LuceneTestCase.createTempDir("data-dir");
+ return this;
+ }
+
+ public Builder setSchemaFile(String schemaFile) {
Review Comment:
Should use "with" in general -- basically whatever reads well.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
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-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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "joshgog (via GitHub)" <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1090366966
##########
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:
@dsmiley I already used it in TestHarness line 231 `.setUpdateShardHandlerConfig(UpdateShardHandlerConfig.TEST_DEFAULT)`
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1073134160
##########
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());
Review Comment:
I realized we don't need to set this as a System Property, we can do so in an ad-hoc Properties instance that we pass below to the 2nd arg of `fromSolrHome`. That will be cleaner.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1084222675
##########
solr/core/src/java/org/apache/solr/core/FileSystemConfigSetService.java:
##########
@@ -282,7 +282,12 @@ private String normalizePathToOsSeparator(String path) {
protected Path locateInstanceDir(CoreDescriptor cd) {
String configSet = cd.getConfigSet();
+
if (configSet == null) return cd.getInstanceDir();
+
+ if (configSet != null && configSet.endsWith("/conf")) {
Review Comment:
I'd rather leave this to another PR
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java:
##########
@@ -57,38 +105,58 @@ public void testProperties() throws Exception {
// Add to core0
up.add(doc);
- up.process(getSolrCore0());
+ up.process(solrClientTestRule.getSolrClient("core0"));
SolrTestCaseJ4.ignoreException("unknown field");
// You can't add it to core1
- expectThrows(Exception.class, () -> up.process(getSolrCore1()));
+ expectThrows(Exception.class, () -> up.process(solrClientTestRule.getSolrClient("core1")));
// Add to core1
doc.setField("id", "BBB");
doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
doc.removeField("core0");
up.add(doc);
- up.process(getSolrCore1());
+ up.process(solrClientTestRule.getSolrClient("core1"));
// You can't add it to core1
SolrTestCaseJ4.ignoreException("core0");
- expectThrows(Exception.class, () -> up.process(getSolrCore0()));
+ expectThrows(Exception.class, () -> up.process(solrClientTestRule.getSolrClient("core0")));
SolrTestCaseJ4.resetExceptionIgnores();
// now Make sure AAA is in 0 and BBB in 1
SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest(q);
q.setQuery("id:AAA");
- assertEquals(1, r.process(getSolrCore0()).getResults().size());
- assertEquals(0, r.process(getSolrCore1()).getResults().size());
+ assertEquals(1, r.process(solrClientTestRule.getSolrClient("core0")).getResults().size());
+ assertEquals(0, r.process(solrClientTestRule.getSolrClient("core1")).getResults().size());
// Now test Changing the default core
- assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
- assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
-
- assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
- assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
+ assertEquals(
+ 1,
+ (solrClientTestRule.getSolrClient("core0"))
Review Comment:
still pending
##########
solr/core/src/java/org/apache/solr/update/UpdateShardHandlerConfig.java:
##########
@@ -32,6 +32,16 @@ public class UpdateShardHandlerConfig {
DEFAULT_METRICNAMESTRATEGY,
DEFAULT_MAXRECOVERYTHREADS);
+ public static final UpdateShardHandlerConfig UPDATE_SHARD_HANDLER_CONFIG =
Review Comment:
Rename to TEST_DEFAULT. TestHarness should refer to this as well.
##########
solr/core/src/test/org/apache/solr/update/RootFieldTest.java:
##########
@@ -46,7 +49,15 @@ public static void beforeTest() throws Exception {
useRootSchema = random().nextBoolean();
// schema15.xml declares _root_ field, while schema-rest.xml does not.
String schema = useRootSchema ? "schema15.xml" : "schema-rest.xml";
- initCore("solrconfig.xml", schema);
+ SolrTestCaseJ4.newRandomConfig();
+
+ solrClientTestRule.startSolr(Path.of(SolrTestCaseJ4.TEST_HOME()));
+
+ solrClientTestRule
+ .newCollection(DEFAULT_TEST_COLLECTION_NAME)
Review Comment:
(still pending; affects many tests)
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -86,7 +85,7 @@ public void startSolr(NodeConfig nodeConfig) {
public NodeConfig.NodeConfigBuilder newNodeConfigBuilder(Path solrHome) {
return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
- .setUpdateShardHandlerConfig(UPDATE_SHARD_HANDLER_CONFIG)
+ .setUpdateShardHandlerConfig(TEST_DEFAULT)
Review Comment:
Please have a qualified (class) reference here instead of a static field import.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java:
##########
@@ -31,16 +35,19 @@ public class TermsResponseTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
Review Comment:
> Does this need the "solrhome" parameter? When I see it, it makes me think it's important somehow
I suppose you are wondering, could we have a default of some temp directory so that the test doesn't even need to specify it? We could do that. I leaned to specifying it because this is such a foundational thing to Solr.
> I saw we also have the use of .createTempDir() with no name
It's cosmetic so that if we debug issues, it's more evident what purpose this temp dir is for.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1057782462
##########
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 {
Review Comment:
I'd love to see some Javadocs that explain when you would want to use this TestRule. I find it often confusing to figure out which type of unit test base calss to use... Maybe text about that needs to also go in our dev-docs?
--
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
[GitHub] [solr] gerlowskija commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
gerlowskija commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1060787589
##########
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:
🤔 I don't remember doing that in particular, but I guess that'd be expected if it was an unintentional mistake 🤷
You don't have a commit hash handy do you @dsmiley ? (No worries if not; I can dig it up with git log/blame, was just hoping to save myself the trouble...)
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097739481
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
Review Comment:
I concur that "I don't think that I see this normally". But hey why not? Your example looks nicer but it only applies to a well-known config. Here in the SolrJ module, there are configSets in its own module that some tests use. Would you propose creating a SolrJExternalPaths.COLLECTION1? _Meh_.
--
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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1058265485
##########
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:
Should I define getSolrClient() in EmbeddedSolrServerTestBase to return the client created in the test rule or I should revert to how it was defined initially?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1061098020
##########
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:
319cb005d314e6f15dd73339e99657d8e39218a4
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1061098953
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java:
##########
@@ -37,14 +40,18 @@ public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule
+ .build()
+ .setSolrHome(Paths.get(SolrJettyTestBase.legacyExampleCollection1SolrHome()))
+ .init();
}
static String field = "name";
+ SolrClient client = getSolrClient();
Review Comment:
Agreed on putting this at the end of beforeClass
--
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
[GitHub] [solr] dsmiley commented on pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on PR #1218:
URL: https://github.com/apache/solr/pull/1218#issuecomment-1402176092
> I think I am slowly starting to grok what this is all about... Let me see if I can state the value.... "Using a TestRule simplifies the setup of a test by abstracting away a lot of the Solr environment setup into the specific TestRule you choose. This means choosing the right TestRule to use is an important decision when writing a test, to make sure you have the right abstraction of Solr you need"...???
Yes! One could argue we have similar things already -- EmbeddedSolrServer, JettySolrRunner, MiniSolrCloudCluster, and corresponding base classes. But the look & feel is very different. So the aim standardizes the approach between them so that using any of these requires little new knowledge. This isn't evident in this PR as it's just one rule but there are more to create.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096789742
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java:
##########
@@ -16,12 +16,17 @@
*/
package org.apache.solr.client.solrj.embedded;
+import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.LargeVolumeTestBase;
+import org.apache.solr.util.ExternalPaths;
import org.junit.BeforeClass;
public class LargeVolumeJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- initCore();
+ // TODO
Review Comment:
left over or real?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1061101498
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
Review Comment:
Yeah I hear you on breaking precedent so maybe not a good idea. How about initializeWithSolrHome(...).withBlahBlah().init(); We are "initializing" not "building"? This idea standardizes on the Solr home coming first which is mandatory.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1061100149
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
+ return new Builder();
+ }
+
+ public class Builder {
+ private Path solrHome; // mandatory
+ private Path dataDir;
+ private String collectionName = DEFAULT_TEST_COLLECTION_NAME;
+ private String configFile;
+ private String schemaFile;
+ private RequestWriterSupplier requestWriterSupplier = RequestWriterSupplier.JavaBin;
+
+ public Builder setSolrHome(Path solrHome) {
+ this.solrHome = solrHome;
+ return this;
+ }
+
+ public Builder useTempDataDir() {
Review Comment:
It's rather common for tests to create Solr pointed at SOLR_HOME -- an existing directory that should be considered read-only (instead of some build/ or temp dir). Tests will complain (via the SecurityManager) if this mistake is overlooked. I could easily imagine plugin writers making use of this as well. If the solr home provided is a temp dir populated from something, then there's no need for this. It could be worth exploring creating one combo method like withMutableSolrHome vs withTemplateSolrHome (thus read-only) but I'm kind of "meh" on this. Regardless, javadoc is necessary to help users understand when to use these methods.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096790167
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
Review Comment:
do we need relative pathing like this? I don't think that I see this normally... Here is an example of the more common pattern: `solrClientTestRule.newCollection().withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET).create();`
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096791114
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java:
##########
@@ -34,17 +38,26 @@
* @since solr 1.3
*/
public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
+ private static SolrClient client;
Review Comment:
Maybe this is partly to avoid changing so many lines of the test?
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097324599
##########
solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java:
##########
@@ -41,7 +41,7 @@ public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase {
@Test
public void testMultiThreaded() throws Exception {
- SolrClient client = this.getSolrClient();
+ SolrClient client = getSolrClient();
Review Comment:
I get that.. What I'm wondering is that it appears that sometimes we use the helper pattern of a `getSolrClient()`, but in other tests we use the full explicit `solrClientTestRule.getSolrClient()`.... Feels like we should try and have one pattern? Maybe just a bikeshed..
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097686717
##########
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:
@joshgog in the new Jetty based TestRule you are working on, lets address this issue above (a test that should be using Jetty but isn't any longer) on this test by using the new rule! Basically, change LargeVolumeTestBase to subclass SolrTestCase instead of EmbeddedSolrServerTestBase, and instead declare whichever rule we want based on the test.
CC @epugh this is the TODO that wasn't clear
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1057836168
##########
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 {
Review Comment:
Agreed; I held back on that feedback that came to my mind as well. I think we want to get the API right before documenting said API.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1057783517
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
Review Comment:
Do we need more detail on Solr server? I.e, does this support solr cloud mode? Does this support http apis?
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
Review Comment:
Do we need more detail on "Solr server"? I.e, does this support solr cloud mode? Does this support http apis?
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097733584
##########
solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java:
##########
@@ -41,7 +41,7 @@ public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase {
@Test
public void testMultiThreaded() throws Exception {
- SolrClient client = this.getSolrClient();
+ SolrClient client = getSolrClient();
Review Comment:
EmbeddedSolrServerTestBase is henceforth deprecated; it needn't exist; it barely does anything. If someone wishes to remove it, then they can make that change then. But those tests use this test base today so... why change them today.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097758339
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- clearIndex();
- assertU(commit());
- assertU(optimize());
+ solrClientTestRule.clearIndex();
Review Comment:
TestRules (a JUnit thing) can either be declared statically and thus become a so-called `@ClassRule` (they are annotated this way; see EmbeddedSolrServerTestBase in this PR), or non-statically declared rule is annotated `@Rule`. ClassRule operate for the whole class; don't participate in life-cycle between individual tests in the class. Rule is for each test.
So with that background, if a test needs a separate Solr instance per test, it could do so by defining this rule using `@Rule` and it would not need to bother clearing the index.
If a test does not need to restart Solr between tests (typical; why bother), then if a test also creates data, it'll need to arrange for that data to be cleaned up. This is not a new concern; it exists today. It's sometimes annoying to call clearIndex. I could imagine some new mechanism where we create a new separate `@Rule` _from_ the `@ClassRule` that represents the data so that it cleans up so that it has the life-cycle hooks to call clearIndex. If it works, it'll be one line of code in a test. It'd be a pretty unusual / weird thing though. :shrug: could warrant an exploration.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097759108
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java:
##########
@@ -34,17 +38,26 @@
* @since solr 1.3
*/
public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
+ private static SolrClient client;
Review Comment:
Indeed; some subclasses assumed this and we are restraining ourselves a bit from doing more work than needed.
--
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
[GitHub] [solr] dsmiley merged pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley merged PR #1218:
URL: https://github.com/apache/solr/pull/1218
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
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-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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1042159303
##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import org.apache.solr.client.solrj.SolrClient;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SolrClientTestRule extends ExternalResource {
Review Comment:
For classes that are going to have a long life, like this one in the `test-framework` starting to introduce some JavaDocs to explain what this class does would be great!
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096791009
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java:
##########
@@ -34,17 +38,26 @@
* @since solr 1.3
*/
public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
+ private static SolrClient client;
Review Comment:
Do we need a static client?
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096790762
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
}
@Before
@Override
public void setUp() throws Exception {
super.setUp();
- clearIndex();
- assertU(commit());
- assertU(optimize());
+ solrClientTestRule.clearIndex();
Review Comment:
maybe a nit pick, but do we need to do this kind of clean up in our before's? Shouldn't the overall framework take care of having a clean index? I would hope that every test would start with an empty index right?
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097765893
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +30,18 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+
+ SolrTestCaseJ4.newRandomConfig();
+ solrClientTestRule.newCollection().withConfigSet("../collection1").create();
Review Comment:
Fair... I have a old PR open where I tried to deal with that issue of the solrj module...
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097765116
##########
solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java:
##########
@@ -41,7 +41,7 @@ public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase {
@Test
public void testMultiThreaded() throws Exception {
- SolrClient client = this.getSolrClient();
+ SolrClient client = getSolrClient();
Review Comment:
Right... I think you suggested that... So let's make sure to create a JIRA post merging this to get EmbeddedSolrServerTestBase removed ;-) I'd be happy to sign up for that, removing deprecations is fun!
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1058397971
##########
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:
> Should I define getSolrClient() in EmbeddedSolrServerTestBase to return the client created in the test rule
Yes.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1087083741
##########
solr/core/src/test/org/apache/solr/update/RootFieldTest.java:
##########
@@ -54,7 +54,7 @@ public static void beforeTest() throws Exception {
solrClientTestRule.startSolr(Path.of(SolrTestCaseJ4.TEST_HOME()));
solrClientTestRule
- .newCollection(DEFAULT_TEST_COLLECTION_NAME)
Review Comment:
are we going away from using `DEFAULT_TEST_COLLECTION_NAME` everywhere? I'm okay with that, just want to do it everywhere then ;-)
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1071731157
##########
solr/core/src/test/org/apache/solr/update/RootFieldTest.java:
##########
@@ -46,7 +49,15 @@ public static void beforeTest() throws Exception {
useRootSchema = random().nextBoolean();
// schema15.xml declares _root_ field, while schema-rest.xml does not.
String schema = useRootSchema ? "schema15.xml" : "schema-rest.xml";
- initCore("solrconfig.xml", schema);
+ SolrTestCaseJ4.newRandomConfig();
+
+ solrClientTestRule.startSolr(Path.of(SolrTestCaseJ4.TEST_HOME()));
+
+ solrClientTestRule
+ .newCollection(DEFAULT_TEST_COLLECTION_NAME)
Review Comment:
Let's make "collection1" the default if no arg is provided. Most tests don't care what its name is.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java:
##########
@@ -26,18 +33,59 @@
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.util.EmbeddedSolrServerTestRule;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.rules.TestRule;
-/**
- * @since solr 1.3
- */
-public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+/** Test properties in configuration files. */
+public class TestSolrProperties extends SolrTestCase {
Review Comment:
Lets bring back AbstractEmbeddedSolrServerTestCase to keep code in common between its two subclasses, but mark it deprecated.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/TestSolrProperties.java:
##########
@@ -57,38 +105,58 @@ public void testProperties() throws Exception {
// Add to core0
up.add(doc);
- up.process(getSolrCore0());
+ up.process(solrClientTestRule.getSolrClient("core0"));
SolrTestCaseJ4.ignoreException("unknown field");
// You can't add it to core1
- expectThrows(Exception.class, () -> up.process(getSolrCore1()));
+ expectThrows(Exception.class, () -> up.process(solrClientTestRule.getSolrClient("core1")));
// Add to core1
doc.setField("id", "BBB");
doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
doc.removeField("core0");
up.add(doc);
- up.process(getSolrCore1());
+ up.process(solrClientTestRule.getSolrClient("core1"));
// You can't add it to core1
SolrTestCaseJ4.ignoreException("core0");
- expectThrows(Exception.class, () -> up.process(getSolrCore0()));
+ expectThrows(Exception.class, () -> up.process(solrClientTestRule.getSolrClient("core0")));
SolrTestCaseJ4.resetExceptionIgnores();
// now Make sure AAA is in 0 and BBB in 1
SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest(q);
q.setQuery("id:AAA");
- assertEquals(1, r.process(getSolrCore0()).getResults().size());
- assertEquals(0, r.process(getSolrCore1()).getResults().size());
+ assertEquals(1, r.process(solrClientTestRule.getSolrClient("core0")).getResults().size());
+ assertEquals(0, r.process(solrClientTestRule.getSolrClient("core1")).getResults().size());
// Now test Changing the default core
- assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
- assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
-
- assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
- assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
+ assertEquals(
+ 1,
+ (solrClientTestRule.getSolrClient("core0"))
Review Comment:
This is too verbose. getSolrCore0 & 1 can return; ehhh?
##########
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);
+
+ return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
+ .setUpdateShardHandlerConfig(updateShardHandlerConfig)
+ .setCoreRootDirectory(LuceneTestCase.createTempDir("cores").toString());
+ }
+
+ 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) {
+ // Chop off "/conf" if found -- configSet can be a path.
+ // This is a hack so that we can continue to use ExternalPaths.DEFAULT_CONFIGSET etc. as-is.
+ // TODO FileSystemConfigSetService.locateInstanceDir should have this logic.
+ // Without this, managed resources might be written to
+ // conf/conf/_schema_analysis_stopwords_english.json because SolrResourceLoader points to the
+ // wrong dir.
+ if (configSet != null && configSet.endsWith("/conf")) {
+ configSet = configSet.substring(0, configSet.length() - "/conf".length());
+ }
Review Comment:
I'll tend to this improvement in another issue/PR.
##########
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 {
Review Comment:
@joshgog still waiting for docs in general. Just give it a shot; I can clean up after.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TermsResponseTest.java:
##########
@@ -31,16 +35,19 @@ public class TermsResponseTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
+
+ solrClientTestRule
+ .newCollection(DEFAULT_TEST_COLLECTION_NAME)
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
Review Comment:
Exemplifies we're not after shaving lines of code. Starting Solr and creating a collection with a known configSet is explicit and should be -- isn't verbose either.
##########
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:
Let's create a constant declared at package scope so that TestHarness can refer to it, and we'll be done. Actually, defining it on UpdateShardHandlerConfig would be nicer (debatable).
##########
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);
+
+ return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
+ .setUpdateShardHandlerConfig(updateShardHandlerConfig)
+ .setCoreRootDirectory(LuceneTestCase.createTempDir("cores").toString());
+ }
+
+ public NewCollectionBuilder newCollection(String name) {
Review Comment:
Define on SolrClientTestRule as it's going to be common to all rules. Obviously, the builder would tag along with it.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java:
##########
@@ -53,32 +50,15 @@ public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServ
@BeforeClass
public static void beforeClass() throws Exception {
- final String sourceHome = ExternalPaths.SOURCE_HOME;
-
- final File tempSolrHome = LuceneTestCase.createTempDir().toFile();
- FileUtils.copyFileToDirectory(new File(sourceHome, "server/solr/solr.xml"), tempSolrHome);
- final File collectionDir = new File(tempSolrHome, COLLECTION_NAME);
- FileUtils.forceMkdir(collectionDir);
- final File configSetDir =
- new File(sourceHome, "server/solr/configsets/sample_techproducts_configs/conf");
- FileUtils.copyDirectoryToDirectory(configSetDir, collectionDir);
-
- final Properties props = new Properties();
- props.setProperty("name", COLLECTION_NAME);
-
- try (Writer writer =
- new OutputStreamWriter(
- FileUtils.openOutputStream(new File(collectionDir, "core.properties")), "UTF-8"); ) {
- props.store(writer, null);
- }
- final String config =
- tempSolrHome.getAbsolutePath() + "/" + COLLECTION_NAME + "/conf/solrconfig.xml";
- final String schema =
- tempSolrHome.getAbsolutePath() + "/" + COLLECTION_NAME + "/conf/managed-schema";
- initCore(config, schema, tempSolrHome.getAbsolutePath(), COLLECTION_NAME);
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
+
+ solrClientTestRule
+ .newCollection(COLLECTION_NAME)
+ .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET)
+ .create();
Review Comment:
Huge improvement as I said before; maybe best example. Interestingly this shows how we can use some empty temp dir as Solr home, and all we need to do is reference a path to the configSet we want when creating a collection. @gerlowskija I believe you wrote this originally.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java:
##########
@@ -46,35 +50,58 @@
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 {
Review Comment:
Again, let's keep AbstractEmbeddedSolrServerTestCase to avoid the duplication between here & the properties test. I don't think its worth or time now to eliminate some questionable base classes.
##########
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);
+
+ return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
+ .setUpdateShardHandlerConfig(updateShardHandlerConfig)
+ .setCoreRootDirectory(LuceneTestCase.createTempDir("cores").toString());
+ }
+
+ 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) {
+ // Chop off "/conf" if found -- configSet can be a path.
+ // This is a hack so that we can continue to use ExternalPaths.DEFAULT_CONFIGSET etc. as-is.
+ // TODO FileSystemConfigSetService.locateInstanceDir should have this logic.
+ // Without this, managed resources might be written to
+ // conf/conf/_schema_analysis_stopwords_english.json because SolrResourceLoader points to the
+ // wrong dir.
+ if (configSet != null && configSet.endsWith("/conf")) {
+ configSet = configSet.substring(0, configSet.length() - "/conf".length());
+ }
+
+ 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.Create req = new CoreAdminRequest.Create();
+ req.setCoreName(b.getName());
+ req.setInstanceDir(b.getName());
+
+ if (b.getConfigSet() != null) {
+ req.setConfigSet(b.getConfigSet());
+ }
+ if (b.getConfigFile() != null) {
+ req.setConfigName(b.getConfigFile());
+ }
+ if (b.getSchemaFile() != null) {
+ req.setSchemaName(b.getSchemaFile());
+ }
+
+ req.process(client);
+ }
+
+ @Override
+ protected void after() {
+ if (container != null) container.shutdown();
+
+ if (clearCoreDirSysProp) {
+ System.clearProperty(CORE_DIR_PROP);
+ }
+ }
+
+ @Override
+ public EmbeddedSolrServer getSolrClient() {
+ if (client == null) {
+ return adminClient;
+ } else {
+ return client;
+ }
+ }
+
+ @Override
+ public EmbeddedSolrServer getSolrClient(String name) {
+ if (client == null) {
+ return new EmbeddedSolrServer(adminClient.getCoreContainer(), name);
+ } else {
+ return new EmbeddedSolrServer(client.getCoreContainer(), name);
+ }
Review Comment:
always use adminClient; no point in flip-flopping.
##########
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);
+
+ return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
+ .setUpdateShardHandlerConfig(updateShardHandlerConfig)
+ .setCoreRootDirectory(LuceneTestCase.createTempDir("cores").toString());
+ }
+
+ 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) {
+ // Chop off "/conf" if found -- configSet can be a path.
+ // This is a hack so that we can continue to use ExternalPaths.DEFAULT_CONFIGSET etc. as-is.
+ // TODO FileSystemConfigSetService.locateInstanceDir should have this logic.
+ // Without this, managed resources might be written to
+ // conf/conf/_schema_analysis_stopwords_english.json because SolrResourceLoader points to the
+ // wrong dir.
+ if (configSet != null && configSet.endsWith("/conf")) {
+ configSet = configSet.substring(0, configSet.length() - "/conf".length());
+ }
+
+ 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.Create req = new CoreAdminRequest.Create();
+ req.setCoreName(b.getName());
+ req.setInstanceDir(b.getName());
+
+ if (b.getConfigSet() != null) {
+ req.setConfigSet(b.getConfigSet());
+ }
+ if (b.getConfigFile() != null) {
+ req.setConfigName(b.getConfigFile());
+ }
+ if (b.getSchemaFile() != null) {
+ req.setSchemaName(b.getSchemaFile());
+ }
+
+ req.process(client);
+ }
+
+ @Override
+ protected void after() {
+ if (container != null) container.shutdown();
+
+ if (clearCoreDirSysProp) {
+ System.clearProperty(CORE_DIR_PROP);
+ }
+ }
+
+ @Override
+ public EmbeddedSolrServer getSolrClient() {
+ if (client == null) {
+ return adminClient;
+ } else {
+ return client;
+ }
Review Comment:
Let's not assume the last call to create a collection is the default client (the `client` field). Instead, let's establish that `getSolrClient` will always return a client to "collection1". It should work even if there is such a core loaded by Solr in startSolr (i.e. no call to explicitly create a collection). Don't return adminClient here either.
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java:
##########
@@ -31,18 +32,21 @@ 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");
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
Review Comment:
I think this is cool as it shows that in more cases than previously, we can use existing read-only Solr homes that act as templates directly without having to copy them, doing wasteful IO.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1057782874
##########
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";
Review Comment:
In another PR, we are trying to use the constant for places where we say `collection1`, something like `DEFAULT_TEST_COLLECTION_NAME`.... I like it from the perspective that it cues me that the actual name of the collection doesn't matter to the behaviour of the test.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097734387
##########
solr/solrj/src/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java:
##########
@@ -16,12 +16,17 @@
*/
package org.apache.solr.client.solrj.embedded;
+import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.LargeVolumeTestBase;
+import org.apache.solr.util.ExternalPaths;
import org.junit.BeforeClass;
public class LargeVolumeJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
- initCore();
+ // TODO
Review Comment:
See previous thread I at-mentioned you on.
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1097764373
##########
solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java:
##########
@@ -30,7 +35,9 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
Review Comment:
Maybe it's just my love for the Rails world's view of "convention over configuration"... I'd love to see us strongly advocate for one approach whenever there are two approaches available because of the wide variety of folks working on Solr. I suspect most folks are copy/pasting to decide how to do things, and aren't thinking carefully thorugh one option or the other. If you provide two options that appear similarily good then you will live with two ways of doing it henceforth! I'd love to see that `startSolr()` ;-)
--
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
[GitHub] [solr] epugh commented on pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on PR #1218:
URL: https://github.com/apache/solr/pull/1218#issuecomment-1418240952
This is really exciting.. I love seeing this effort to simplify how our tests are written. I have found them at times to be quite difficult to understand, so this is a great step.
--
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
[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096268870
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java:
##########
@@ -38,7 +39,6 @@
@SuppressSSL
public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServerTestBase {
- private static final String COLLECTION_NAME = "techproducts";
Review Comment:
Why not leave this but merely change the value to collection1? This way you avoid changing many lines below.
--
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
[GitHub] [solr] joshgog commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "joshgog (via GitHub)" <gi...@apache.org>.
joshgog commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096510726
##########
solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java:
##########
@@ -38,7 +39,6 @@
@SuppressSSL
public class DirectJsonQueryRequestFacetingEmbeddedTest extends EmbeddedSolrServerTestBase {
- private static final String COLLECTION_NAME = "techproducts";
Review Comment:
Sure that's logical
--
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
[GitHub] [solr] epugh commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1096788848
##########
solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java:
##########
@@ -30,7 +35,9 @@ public class GetByIdTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule.startSolr(LuceneTestCase.createTempDir("solrhome"));
Review Comment:
Why do some use `solrClientTestRule.startSolr(Paths.get(SolrTestCaseJ4.TEST_HOME()));` and some need their own temp dir like in this? Maybe this is really asking about some documentation somewhere on how to write good tests that use this Rule?
--
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
[GitHub] [solr] gerlowskija commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer
Posted by GitBox <gi...@apache.org>.
gerlowskija commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1060810965
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
+ return new Builder();
+ }
+
+ public class Builder {
+ private Path solrHome; // mandatory
+ private Path dataDir;
+ private String collectionName = DEFAULT_TEST_COLLECTION_NAME;
+ private String configFile;
+ private String schemaFile;
+ private RequestWriterSupplier requestWriterSupplier = RequestWriterSupplier.JavaBin;
+
+ public Builder setSolrHome(Path solrHome) {
+ this.solrHome = solrHome;
+ return this;
+ }
+
+ public Builder useTempDataDir() {
+ this.dataDir = LuceneTestCase.createTempDir("data-dir");
+ return this;
+ }
+
+ public Builder setSchemaFile(String schemaFile) {
Review Comment:
[0] Eric Pugh has been working recently on a Builder pattern for creating Solr clients that has methods with names like: `withFoo`, `withBar`, etc.
I love that you're consistent across this Builder here with using `set`. But is there any value in being consistent with the SolrClient builders and using `with` instead of `set`? (Maybe there's not - solrj and solr-test-framework are different animals. Just bringing it up for conversation in case it hasn't been raised yet.)
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
Review Comment:
[0] Definitely getting into "personal-preference territory" here, but I don't love the `build()/init()` method names that are used to create the builder and finish its initialization.
In most of the builders I've worked with (e.g. [ToStringBuilder](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/ToStringBuilder.html#build--), [HttpClientBuilder](https://hc.apache.org/httpcomponents-client-4.5.x/current/httpclient/apidocs/org/apache/http/impl/client/HttpClientBuilder.html#build()), and of course [HttpSolrClient.Builder](https://solr.apache.org/docs/7_4_0/solr-solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.Builder.html#build--)), `build()` is the final method in the call chain that takes all of the provided settings and uses them to actually create an instance of the object in question.
Using `build()` to create the builder itself breaks that common convention and (I think) will be confusing for readers/users. Is there a good reason we're not just sticking to the common convention here?
##########
solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java:
##########
@@ -37,14 +40,18 @@ public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore();
+ solrClientTestRule
+ .build()
+ .setSolrHome(Paths.get(SolrJettyTestBase.legacyExampleCollection1SolrHome()))
+ .init();
}
static String field = "name";
+ SolrClient client = getSolrClient();
Review Comment:
[0] I don't think it's _wrong_ per se, but I'd rather see this in a method (maybe at the end of `beforeClass` or in a separate `@Before` annotated method?
Not a strong opinion though; if there's a reason you've done it this way then ignore me.
##########
solr/test-framework/src/java/org/apache/solr/util/EmbeddedSolrServerTestRule.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.apache.solr.SolrTestCaseJ4.DEFAULT_TEST_COLLECTION_NAME;
+
+import java.io.IOException;
+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.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.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 client = null;
+
+ public Builder build() {
+ return new Builder();
+ }
+
+ public class Builder {
+ private Path solrHome; // mandatory
+ private Path dataDir;
+ private String collectionName = DEFAULT_TEST_COLLECTION_NAME;
+ private String configFile;
+ private String schemaFile;
+ private RequestWriterSupplier requestWriterSupplier = RequestWriterSupplier.JavaBin;
+
+ public Builder setSolrHome(Path solrHome) {
+ this.solrHome = solrHome;
+ return this;
+ }
+
+ public Builder useTempDataDir() {
Review Comment:
[Q] Maybe trimming down the functionality exposed is beyond scope of this issue/PR, since at this point we need to support the tests that exist currently. But I am curious: what's the value of exposing this option to users?
Do tests actually care about where data lives, or is this just something that has historically been exposed to support tests that need multiple EmbeddedSolrServers? If the latter, could we just always use a temp-dir and eliminate this method entirely?
--
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