Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SolrTestCase now supports @LogLevel #2869

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Nov 17, 2024

Refactored the functionality into a TestRule, and moved from STCJ4 up to SolrTestCase.
Move reinstatement of the root log level to shutdown()

(part of bigger goal of abandoning SolrTestCaseJ4)

Refactored the functionality into a TestRule, and moved from STCJ4 up to SolrTestCase.
Move reinstatement of the root log level to shutdown()
Copy link
Contributor Author

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

I did some basic observational testing of some classes that used LogLevel at method and class level to see that logs showed up for only certain methods but not others.

Not doing a JIRA for a test refactorings like this.

Comment on lines +157 to +160
// re-instate original log level.
if (!INITIAL_ROOT_LOG_LEVEL.equals(getLogLevelString())) {
changeLogLevel(INITIAL_ROOT_LOG_LEVEL);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The move of this re-instate / reset of the root log level into shutdown() is debatable. I was trying to reduce little details in STC/STCJ4.

* A JUnit {@link TestRule} that sets (and resets) the Log4j2 log level based on the {@code
* LogLevel} annotation.
*/
public class LogLevelTestRule implements TestRule {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, this is the perfect use case for a JUnit's TestRule. It takes advantage of observing the annotations that are present so that it can insert the Statement or skip it. And it works at both the class and method level with the same Statement. And it's generally useful -- I could see someone taking this into their own projects.

Maybe a case could be made for putting this rule as an inner class under LogLevel, so that it's more packaged together.

@hossman
Copy link
Member

hossman commented Nov 22, 2024

I don't know about the shutdown() changes, but moving this logic into a Rule seems great, and and using that @Rule in SolrTestCase (instead of SolrTestCaseJ4) seems fine...

But I'm curious: why not just leave that @Rule in SolrTestCaseJ4 (for backcompat) and let any other SolrTestCase subclasses that want to use this functionality add the @Rule themselves? ... isn't that the real value of the Rule API, that's it's easy to wire in and mix/match?

Either way I would suggest updating the TestLogLevelAnnotations extends ... declaration to use SolrTestCase -- that's the best way to "prove" that making these changes "works".(There are also some comments in that class that probably need updated? ... i think the code they comment is all still true, but they make references to SolrTestCaseJ4 that should probably now refer to something else?)

@dsmiley
Copy link
Contributor Author

dsmiley commented Nov 25, 2024

isn't that the real value of the Rule API, that's it's easy to wire in and mix/match?

Rules bring an encapsulation benefit -- I'd say that's the biggest IMO. Also mix/match, yes. But I don't see why any test would want to opt-out of this one given how cheap/light-weight it is, with its annotation based activation of the underlying Statement wrapper. I think we want to make it super-easy to debug a test with logs -- just add an annotation. Likewise I'm grateful other rules are defined always like system property clearing; I don't want tests to waste lines of code over basic book-keeping. I'd feel differently about a rule that seems heavy and/or is imposing in some way.

@github-actions github-actions bot added the tests label Nov 25, 2024
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