Use mock filesystem in tests [LUCENE-6072]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
We went through the trouble to convert to NIO.2, but we don't take advantage of it in tests...
Since everything boils down to LuceneTestCase's temp dir (which is just Path), we can wrap the filesystem with useful stuff:
- detect file handle leaks (better than mockdir: not just index files)
- act like windows (don't delete open files, case-insensitivity, etc)
- verbosity (add what is going on to infostream for debugging)
I prototyped some of this in a patch. Currently it makes a chain like this:
```Java
private FileSystem initializeFileSystem() {
FileSystem fs = FileSystems.getDefault();
if (LuceneTestCase.VERBOSE) {
fs = new VerboseFS(fs,
new PrintStreamInfoStream(System.out)).getFileSystem(null);
}
fs = new LeakFS(fs).getFileSystem(null);
fs = new WindowsFS(fs).getFileSystem(null);
return fs.provider().getFileSystem(URI.create("file:///"));
}
```
Some things to figure out:
- I don't think we want to wrap all the time (worry about hiding bugs)
- its currently a bit lenient (e.g. these filesystems allow calling toFile, which can "escape" and allow you to do broken things). But only 2 or 3 tests really need File, so we could fix that.
- its currently complicated and messy (i blame the jdk api here, but maybe we can simplify it)
---
Migrated from [LUCENE-6072](https://issues.apache.org/jira/browse/LUCENE-6072) by Robert Muir (@rmuir), updated Nov 26 2014
Attachments: [LUCENE-6072.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-6072/LUCENE-6072.patch) (versions: 3)
Contributor guide
Research direction
Start by reviewing the attached LUCENE-6072.patch and LuceneTestCase's temporary-directory handling. Determine how the proposed filesystem wrappers should be applied and simplified, then verify that tests cover leak detection, Windows-like behavior, and optional verbose output without allowing unintended File escapes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, testing
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100