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 requested review from Copilot and removed request for iamsanjay December 23, 2025 16:25
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

This PR is an experimental effort to use AI to migrate Solr tests from the deprecated SolrJettyTestBase to using SolrJettyTestRule. The primary goal is to reduce technical debt by modernizing test infrastructure, with the focus on refining the AI prompt (prompt_to_use.md) rather than reviewing individual test file changes.

Key changes:

  • Migration of numerous test classes from extending SolrJettyTestBase to SolrTestCaseJ4 with @ClassRule SolrJettyTestRule
  • Updates to base test classes (SolrExampleTestsBase, HttpSolrClientTestBase) to support the new pattern
  • Replacement of legacy methods (getBaseUrl(), getSolrClient(), etc.) with rule-based equivalents
  • Documentation of migration progress and patterns in markdown files

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
prompt_to_use.md AI prompt defining migration requirements and patterns
tests_not_migrated.md Documentation of migration status and remaining work
MIGRATION_*.md AI-generated status and progress tracking files
solr/test-framework/.../BasicHttpSolrClientTest.java Migrated to use SolrJettyTestRule with extensive method call replacements
solr/test-framework/.../ConcurrentUpdate*.java Multiple test classes migrated to new pattern
solr/solrj/.../HttpSolrClientTestBase.java Base class updated with DEFAULT_COLLECTION constant and rule support
solr/solrj/.../SolrExampleTestsBase.java Base class refactored with deprecated backward-compatibility methods
solr/solrj/.../*Test.java Various test classes migrated following standard pattern
solr/core/.../ResponseHeaderTest.java Migrated with improved resource management using try-with-resources
solr/core/.../TestTolerantSearch.java Complex multi-collection test migrated with custom setup
solr/core/.../DistributedDebugComponentTest.java Multi-collection test migrated
solr/modules/sql/.../TestSQLHandlerNonCloud.java Migrated with minimal config setup
solr/test-framework/.../SolrTestCaseJ4.java Added documentation to copyMinConf method

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

Comment on lines 86 to 90
// Backward compatibility methods for existing subclasses
@Deprecated
protected static void createAndStartJetty(Path solrHome) throws Exception {
solrJettyTestRule.startSolr(solrHome, new Properties(), JettyConfig.builder().build());
}
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The deprecated method createAndStartJetty is being added to SolrExampleTestsBase but marked as deprecated. This suggests subclasses may still be calling it. Consider removing this method entirely and updating all subclasses to use the new pattern with solrJettyTestRule.startSolr() instead of maintaining backward compatibility with a deprecated API.

Suggested change
// Backward compatibility methods for existing subclasses
@Deprecated
protected static void createAndStartJetty(Path solrHome) throws Exception {
solrJettyTestRule.startSolr(solrHome, new Properties(), JettyConfig.builder().build());
}

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.

This is the one that I am still mulling on if it's worth doing!

Copy link
Contributor

Choose a reason for hiding this comment

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

Why use the 3-arg overload instead of just one to provide only solrHome?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eye! I found 5 other files wtih the same pattern. Cleaned them up. And now removing the deprecated helper emthod.

Comment on lines +117 to +118
collection1 = null;
collection2 = null;
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The clients collection1 and collection2 in TestTolerantSearch are set to null in AfterClass without being closed. This creates a potential resource leak. Either close these clients before nulling them, or verify that the SolrJettyTestRule handles cleanup of all client instances.

Suggested change
collection1 = null;
collection2 = null;
if (collection1 != null) {
collection1.close();
collection1 = null;
}
if (collection2 != null) {
collection2.close();
collection2 = null;
}

Copilot uses AI. Check for mistakes.
@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 ?

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