Skip to content

SOLR-15788: Remove the use of legacyExampleCollection1SolrHome() in test setup #4147

Open
epugh wants to merge 5 commits intoapache:mainfrom
epugh:SOLR-15788_another_take
Open

SOLR-15788: Remove the use of legacyExampleCollection1SolrHome() in test setup #4147
epugh wants to merge 5 commits intoapache:mainfrom
epugh:SOLR-15788_another_take

Conversation

@epugh
Copy link
Contributor

@epugh epugh commented Feb 19, 2026

https://issues.apache.org/jira/browse/SOLR-15788

Description

Remove the use of legacyExampleCollection1SolrHome() in test setup in favour of our solrTestRule methods.

Solution

Back in 2021 I opened #410 and it was one of my first attempts to make sense of how crazy the Solr code base was! It never landed because it just didn't seem better.

Fastforward 5 years almost, and we have better ways of doing things. Turns our SolrTestRule's give us helpful builder methods that made it easy to remove this old legacy setup method. And simplified some tests too!

Tests

Existing tests pass.

…eprecated calls

legacyExampleCollection1SolrHome() being called but didn't offer anything that just using solrTestRule.newCollection methods didn't provide!
Remove the use of custom setup code in favour of our solrTestRule methods.
@epugh
Copy link
Contributor Author

epugh commented Feb 19, 2026

@dsmiley we are sprinkling around EnvUtils.setProperty( ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString()); a lot, I wonder if this should be set in a base class like SolrTestCase? Or we live with it...

@@ -119,26 +131,17 @@ public Set<String> getContentTypes() {
}

public void testContentTypeHtmlBecomesTextPlain() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method demonstrates what we have to start doing to get rid of h.getCore...

(ContentStreamBase.FileStream) rsp.getValues().get("content");
// System attempts to guess content type, but will only return XML, JSON, CSV, never HTML
assertEquals("application/xml", content.getContentType());
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whyis this called "collection1"? that's ugly. SHouldn't it be called "core1"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a while ago, we standardized on "collection1" no matter what Solr's mode is. I like it.

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

IMO, no test should need to set EnvUtils.setProperty(ALLOW_PATHS_SYSPROP ) since our tests shouldn't be constrained by a production concern. Our test infrastructure, on the other hand, may very well need to configure allow-paths in some way (or disable it).

@@ -71,14 +80,17 @@ public void test404Locally() {

// bypass TestHarness since it will throw any exception found in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have made this comment obsolete (thankfully)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but moreover, I don't see why this test uses Solr internals. Can't we query Solr normally / with SolrJ, and check the exception type and check for the 404?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe.. I was trying not to get too frisky with changing the tests to be better, I was focused on just the migration. I DO think we could tee up a whole set of analysis to run... What tests add value? what tests are duplicative? what tests can be simplified... let's get 5000 bucks of claude credits and have him go to town.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood; let's not go to far afield in this PR

(ContentStreamBase.FileStream) rsp.getValues().get("content");
// System attempts to guess content type, but will only return XML, JSON, CSV, never HTML
assertEquals("application/xml", content.getContentType());
try (SolrCore core = solrTestRule.getCoreContainer().getCore("collection1")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a while ago, we standardized on "collection1" no matter what Solr's mode is. I like it.

*/
public class SolrExampleEmbeddedTest extends SolrExampleTests {

@BeforeClass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused that you removed this. Look at the name of this test. This test should be using EmbeddedSolrServer in some way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't know, because the line solrTestRule.startSolr(legacyExampleCollection1SolrHome()); doesn't start up solr... I looked a bit, and I think this class has been suing a solrTestRule that was inherited from SolrExampleTestsBase, and there it was defined as a SolrJettyTestRule. I will look about overriding the @ClassRule and see if we can have a EmbeddedSolrServerTestRule here...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I did a refactor and pushed it to this PR. Renamed this as I think this test is the best test to test EmbeddedSolrServer itself. Using EmbeddedSolrServer in createNewClient.

Comment on lines +117 to 118
client.deleteByQuery(DEFAULT_TEST_COLLECTION_NAME, "*:*");
client.commit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful! You are referencing a specific collection on line 117 but neglect to on line 118 (for the commit). This is so subtle.

This is my biggest concern with SolrJ API... making collection name optional on all the SolrClient methods... it's a mess. IMO there ought to have been a separate abstraction that has the resolved collection name that you call various methods on to do collection/core specific operations on. CC @gerlowskija

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's funny that everyting is passing with the issue on the client commit.... I kind of think maybe we just need to bite bullet and make core speicfic api calls require a core. collection specific api calls require a collection. And node ones not require either!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked claude and it turns out because the client was created with a default collection, if i pass it in great, and if I don't that's fine too. So, do we have a preference? I could move the tests to always taking a collection name, or maybe remove them everywhere, just to pick one of the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a given test, either embrace the default if you can (ideal), or thoroughly pass the collection/core with every SolrJ call (which is freaking annoying, granted -- I don't like our API). Don't mix the two approaches!

…st.java to become EmbeddedSolrServerTest.java

And Use EmbeddedSolrServer in createNewSolrClient.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments