Skip to content

Conversation

@epugh
Copy link
Contributor

@epugh epugh commented Dec 14, 2025

This is a bit of an experiment. I wanted to see if I could reduce the amount of effort to get our tests updated. Over time we've been accumulating tech debt in our tests, and addressing that manually appears pretty difficult!

In this PR I've checked in my prompt prompt_to_use.md that I used in VS Code. My thought is that the most important aspect of this PR is crafting a really great prompt. Instead of reviewing and commenting on the changes made per individual test file, what I really want is review of the overall change, and feed that review BACK into my prompt. Then I will re-run the improved prompt and that hopefully will output the final set of changes. Maybe in this PR, maybe in another fresh PR with improved prompt.

As an example of feeding back input, after running everything I noticed in one test it hardcoded a 127.0.0.1 url, and so I added Please do not create hard coded urls like 127.0.0.1 in the tests. to prevent that in the future.

There are three files that start with MIGRATION_*.md and they are somewhat messy AI generated status files. I wanted it to maintain tests_not_migrated.md as the but it kind of forgot that file....

…rTestCaseJ4

I used the prompt that I previously checked in, and pretty much just let it go to town.  I had to help it a bit on the BasicHttpSolrClientTest.   tests_not_migrated.md represents the ones that didn't go on the first pass.
…ious batch

They all look pretty straightforward however.
@epugh
Copy link
Contributor Author

epugh commented Dec 15, 2025

Some lessons learned:

  • Be more prescriptive on the process. After migrating the first ten or so, Chat wanted to migrate three or five classes at a time, instead of grinding them out one by one.
  • It's hard not to just engage with Chat to steer him to fix things. Which then made me feel more committed to getting this specific PR done... Versus my original plan of coming up with one "perfect" prompt and then just re run it multiple times till everything worked.
  • Chat really understands how multiple Java components talk to each and the flow in a way that takes me hours of stepping through code....

@dsmiley
Copy link
Contributor

dsmiley commented Dec 19, 2025

Big changes like this should be a multi-step journey. Anticipate that and ask the AI where to start and just stay focused there. For example look at SolrJettyTestBase and focus on removing that. Perhaps even that might be too much for one PR, so narrow further on RestTestBae, for example.

@dsmiley dsmiley marked this pull request as draft December 19, 2025 17:20
@epugh epugh changed the title [EXPERIMENT!] Use AI to migrate Solr tests from SolrJettyTestBase to using SolrJettyTestRule Migrate Solr tests from SolrJettyTestBase to using SolrJettyTestRule Dec 28, 2025
@epugh
Copy link
Contributor Author

epugh commented Dec 28, 2025

Tracking my prompt here:

The class #file:solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java has been deprecated in favour of using #file:solr/test-framework/src/java/org/apache/solr/util/SolrJettyTestRule.java.

I want to migrate our tests away from #file:solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java.   Please go through the code base and migrate each test one by one.  I want you to migrate each test, running the unit test after each one.  If you can't successfully migrate it, then I want you to write it out to "tests_not_migrated.md" and move on.

Please look at #file:solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java as an example of good use of #file:solr/test-framework/src/java/org/apache/solr/util/SolrJettyTestRule.java test rule.

Please do not change createTempDir() method to LuceneTestCase.createTempDir().

Please do not create hard coded urls like 127.0.0.1 in the tests.

We use the try-with-resources pattern to make sure resouces such as httpclients, solrclients, cores etc are closed.  Please use that where possible and skip manually closing the resource.  Unless of course we run into issues with the `ObjectReleaseTracker`.

@epugh
Copy link
Contributor Author

epugh commented Dec 29, 2025

At this point, I'm down to working on migrating how we create collections to follow the pattern that TestPrometheusWriter has and that I also used in DistributedDebugComponentTest. I could keep going, however I think maybe we should merge at this point, and then do that in the next one??? WDYT @dsmiley ?

@epugh
Copy link
Contributor Author

epugh commented Dec 29, 2025

Just discovered EmbeddedSolrServerTestBase, I guess it's next on the list to be migrated!

Migrate to Path, and wraps the few places we have a string value with Path.of.  I suspect they may be refactored away in the future as well.
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 again for undertaking this!

Adding a couple more comments but I suppose this is in pretty good shape!


// NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient and I can't
// bring myself to deal with the nonsense that is SolrJettyTestBase.
// NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient.
Copy link
Contributor

Choose a reason for hiding this comment

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

LOL. Maybe this becomes a TODO now that we have a nice rule encapsulating Solr lifecycle for Jetty
CC @gerlowskija

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 82 out of 82 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (configSet.endsWith(confSuffix)) {
configSet = configSet.substring(0, configSet.length() - confSuffix.length());
}
this.configSet = configSet;
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The assignment this.configSet = configSet; has been moved inside the conditional block. If the configSet doesn't end with the confSuffix, this field will not be set, which could cause the configSet to remain uninitialized or keep its previous value.

Copilot uses AI. Check for mistakes.
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 changed it so if you pass in a null you get a null.


@ClassRule
public static final SolrClientTestRule solrClientTestRule =
public static final SolrClientTestRule solrTestRule =
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Inconsistent naming: This file uses solrClientTestRule for the rule name, while most other migrated files use solrTestRule. This inconsistency makes the codebase harder to maintain.

Copilot uses AI. Check for mistakes.
protected void before() {
System.setProperty("solr.directoryFactory", "solr.NRTCachingDirectoryFactory");
solrClientTestRule.startSolr(LuceneTestCase.createTempDir());
solrTestRule.startSolr(LuceneTestCase.createTempDir());
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

The solrClientTestRule.startSolr() call is using the wrong rule name - it should be solrTestRule.startSolr() to match the field name on line 37.

Copilot uses AI. Check for mistakes.
@epugh epugh merged commit 6b82523 into apache:main Dec 30, 2025
10 of 12 checks passed
epugh added a commit that referenced this pull request Dec 30, 2025
…3947)

Embrace the use of @ClassRule setup to manage the Solr lifecycle using SolrClientTestRule in our tests.  This PR is to finish the migration to using SolrJettyTestRule, which extends SolrClientTestRule across our tests.

There is also plenty of small cleanups of the tests throughout.  Lint cleanups and places where we had extra setup steps that did not need to happen for the goal of a individual test to be accomplished.
@hossman
Copy link
Member

hossman commented Dec 30, 2025

DistributedDebugComponentTest seems to now be failing 100% of the time, regardless of seed

}

@AfterClass
public static void destroyThings() throws Exception {
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 wonder if this logic needs to be restored to fix the policeman build?

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.

3 participants