-
Notifications
You must be signed in to change notification settings - Fork 699
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
base: main
Are you sure you want to change the base?
Conversation
File file = new File(directory, name); | ||
if (!file.exists()) { | ||
Path directory = ((FSDirectory) in).getDirectory(); | ||
Path file = directory.resolve(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just purely cosmentic, but should this really be path
instead of file
? In all the places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I like 'file' to differentiate from a 'dir'. 'path' is generic if could be either.
There was a problem hiding this 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....
ClassLoader cld = h.getCore().getResourceLoader().getClassLoader(); | ||
String path = pckgname.replace('.', '/'); | ||
Enumeration<URL> resources = cld.getResources(path); | ||
while (resources.hasMoreElements()) { | ||
final URI uri = resources.nextElement().toURI(); | ||
if (!"file".equalsIgnoreCase(uri.getScheme())) continue; | ||
final File f = new File(uri); | ||
final Path f = Path.of(uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
instead of f
?
} | ||
for (Path directory : directories) { | ||
if (Files.exists(directory)) { | ||
try (Stream<Path> files = Files.list(directory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the try helping? Is this a try-with-resources pattern?
@@ -84,9 +83,11 @@ private static int findAvailablePort() throws IOException { | |||
private static Pair<Integer, Process> createProcess(int port, boolean https) throws IOException { | |||
// Get the path to the java executable from the current JVM | |||
String classPath = | |||
Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)) | |||
Arrays.stream( | |||
System.getProperty("java.class.path").split(System.getProperty("path.separator"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suprised we don't have sort of nicer way of doing this than System.getProperty
.. Is this common enough that we should have a helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "FileSystems.getDefault().getSeparator();" a possiblity?
|
||
StreamTool.LocalCatStream catStream = | ||
new StreamTool.LocalCatStream(localFile.getAbsolutePath(), -1); | ||
new StreamTool.LocalCatStream(localFile.toAbsolutePath().toString(), -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just pass in a path here?
|
||
String[] toolArgs = | ||
new String[] { | ||
"-e", "techproducts", | ||
"--server-dir", solrServerDir.getAbsolutePath(), | ||
"--example-dir", solrExampleDir.getAbsolutePath(), | ||
"--server-dir", solrServerDir.toAbsolutePath().toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shame that this requires all these .toString
.. Is there a smarter way of handling this toolArgs? var toolArgs
? And then internally we call .toString on anything passed in?????
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed a subset of this but I'll pause until you react to this feedback.(1) Don't use Path.of if you can instead resolve() against the existing path.
(2) Don't rely on referring to the separator char for string concatenation if the scenario could simply be path.resolve()
@@ -279,12 +292,16 @@ public void testCp() throws Exception { | |||
// src and cp3 are valid | |||
|
|||
String localNamed = | |||
tmp.normalize() + File.separator + "localnamed" + File.separator + "renamed.txt"; | |||
tmp.normalize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we use resolve() instead?
"file:" + srcPathCheck.normalize().toAbsolutePath() + File.separator + "solrconfig.xml", | ||
"file:" | ||
+ srcPathCheck.normalize().toAbsolutePath() | ||
+ FileSystems.getDefault().getSeparator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we use resolve instead? And everywhere else in this source file probably.
@@ -417,7 +434,7 @@ public void testCp() throws Exception { | |||
res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args)); | |||
assertEquals("Copy should have succeeded.", 0, res); | |||
|
|||
Path locEmpty = Paths.get(tmp2.toAbsolutePath().toString(), "stopwords", "emptyfile"); | |||
Path locEmpty = Path.of(tmp2.toAbsolutePath().toString(), "stopwords", "emptyfile"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use resolve here instead? and in many other places similarly
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
toPath
. There should be no more imports usingFile
in the project. We are close to makingFile
a forbidden API after this but still more work needed.Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.