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

SOLR-16903: Migrate all tests using File to NIO Path #3263

Merged
merged 23 commits into from
Mar 28, 2025

Conversation

mlbiscoc
Copy link
Contributor

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

Description

WIP - Leaving in draft state for now as there is still more work from refactor needed but most tests pass so can be semi-reviewed.

Migrate all imports using File to Path. There should be no more imports using File in the project. We are close to making File a forbidden API after this but still more work needed.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute 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 to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • 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

Copy link
Contributor

@epugh epugh left a comment

Choose a reason for hiding this comment

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

Wow, so much work! In general I love the removing of the indirection that using Path is showing....

@mlbiscoc
Copy link
Contributor Author

Tests seem to fail on TestCoreDiscovery.java due to

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessUserInformation")

Seems Files.getPosixFilePermissions isn't allowed on Crave running the tests. I could try to get around it without the getPosixFilePermissions to make files readable or unreadable but I suspect we will still run into the same issue of Files.setAttribute after...

@dsmiley
Copy link
Contributor

dsmiley commented Mar 19, 2025

A quick google suggests we should add this to our tests policy for the security manager:

`permission java.lang.RuntimePermission "accessUserInformation";`

But it wasn't needed before... nonetheless if this fixes the matter then it's fine. Eventually we'll be disabling the security manager and perhaps implementing other measures to stop tests from writing where they shouldn't.

@mlbiscoc
Copy link
Contributor Author

A quick google suggests we should add this to our tests policy for the security manager:

`permission java.lang.RuntimePermission "accessUserInformation";`

But it wasn't needed before... nonetheless if this fixes the matter then it's fine. Eventually we'll be disabling the security manager and perhaps implementing other measures to stop tests from writing where they shouldn't.

I think that worked. I removed permissions from default.policy on my local machine to reproduce and added in the accessUserInformation in 6b37693 which looks to pass now.

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.

Just a few more observations but I won't be looking further than this. I expect a contributor on Windows that I've been chatting with will validate this as well.

Copy link
Contributor Author

@mlbiscoc mlbiscoc left a comment

Choose a reason for hiding this comment

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

Got a VM of windows on my laptop to run the tests. The only test that failed was the file permissions tests in TestCoreDiscovery and fixed that accordingly. Still think would be good if someone else ran the test locally (windows and unix). I think this is in a state I'm happy with.

Comment on lines 649 to 658
try {
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(homeDir);
perms.remove(PosixFilePermission.OWNER_READ);
perms.remove(PosixFilePermission.GROUP_READ);
perms.remove(PosixFilePermission.OTHERS_READ);
Files.setAttribute(homeDir, "posix:permissions", perms);
} catch (IOException e) {
throw new AssumptionViolatedException(
"Cannot make " + homeDir + " non-readable. Test aborted.", e);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like on windows this wasn't possible which is why there is a assumeTrue call. This will replicate that and just ignore the test on windows.

@mlbiscoc mlbiscoc marked this pull request as ready for review March 21, 2025 19:10
@dsmiley
Copy link
Contributor

dsmiley commented Mar 24, 2025

I ran the tests last Friday, especially the Windows sensitive one you found and they all passed. I don't recall if there's any outstanding comment of mine that is unfulfilled. I know there's a contributor that may share his results when running Windows.

@mlbiscoc
Copy link
Contributor Author

I ran the tests last Friday, especially the Windows sensitive one you found and they all passed. I don't recall if there's any outstanding comment of mine that is unfulfilled. I know there's a contributor that may share his results when running Windows.

Thanks for helping run the tests. Trying to be careful for something this large of a change. Did a few passthroughs of the PR since opening this. At this point I should have went through all the comments in this PR and resolved them but happy to make more changes if anyone catches something.

@dsmiley dsmiley mentioned this pull request Mar 27, 2025
7 tasks
@dsmiley
Copy link
Contributor

dsmiley commented Mar 28, 2025

I plan to merge this Friday afternoon. Looks like the tests passed on Windows for another contributor.

@dsmiley dsmiley merged commit 86f2afd into apache:main Mar 28, 2025
1 of 2 checks passed
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.

Glad to have merged this finally! Thanks again @mlbiscoc !

@dsmiley
Copy link
Contributor

dsmiley commented Mar 28, 2025

In IntelliJ, I did a find-usages of File (methods, fields, etc.) across project files. Excluding gradle (uses File a lot), there are still a number of usages. For example TestRestore. On that spot in particular, wow, the few lines there are so back & forth on Path -> File -> String -> Path ... makes my head spin

@HoustonPutman
Copy link
Contributor

@mlbiscoc I think we only have 1 failing test from this, so good job!

CustomTLogDirTest.testExternal is failing often enough on the MacOS and Linux builds. One example:
https://jenkins.thetaphi.de/view/Solr/job/Solr-main-macOS/5363

@mlbiscoc
Copy link
Contributor Author

@mlbiscoc I think we only have 1 failing test from this, so good job!

CustomTLogDirTest.testExternal is failing often enough on the MacOS and Linux builds. One example: https://jenkins.thetaphi.de/view/Solr/job/Solr-main-macOS/5363

Ah so close.... Thanks @HoustonPutman Will try and fix this today.

@HoustonPutman
Copy link
Contributor

Oh, well it looks like the nightly tests are less happy... https://ci-builds.apache.org/job/Solr/job/Solr-NightlyTests-main

@mlbiscoc
Copy link
Contributor Author

Thats sad. I ran these tests many times locally. Does nightly not clean up directories? Many of those tests seem to fail where a file/directory already exists. ./gradlew test doesn't seem to run into this issue. Hoping the fix should be small.

CustomTLogDirTest.testExternal is an interesting one. That seed that was run (or I guess depending on the seed it generates), LuceneTestCase.createTempDir() is returning a windowsPath object instead of it's normal filterPath and Path doesn't play well with it. I ran into an issue with LuceneTestCase.createTempDir() earlier in this PR and fixed it with FilterPath.unwrap and looks like unwraping here bandaids the issue.

Will try to fix these errors today.

@mlbiscoc
Copy link
Contributor Author

mlbiscoc commented Apr 1, 2025

PR to fix nightly tests and CustomTLogDirTest.testExternal

colvinco pushed a commit to colvinco/solr that referenced this pull request Apr 4, 2025
* Remove unnecessary toAbsolutePath() calls
* Remove some callers of FileSystems.getDefault().getSeparator()
* Remove Path.toString in where it could easily be avoided.
* Use Path.toFile().setReadable in TestCoreDiscovery
* Throw AssumptionViolatedException for file permissions on windows


Co-authored-by: David Smiley <[email protected]>
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.

4 participants