LUCENE-9774: Fix TestDirectIODirectory to probe for supported filesystem (#2396)

TestDirectIODirectory will currently fail if run on an unsupported
filesystem (e.g. tmpfs). Add an "assume" that probes if the filesystem
supports Direct I/O.

Also tweak javadocs to indicate correct @throws clauses for the
IndexInput and IndexOutput. You'll get an IOException (translated from
EINVAL) if the filesystem doesn't support it, not a UOE.
This commit is contained in:
Robert Muir 2021-02-18 20:36:18 -05:00 committed by GitHub
parent f920b9b14e
commit 6deee14382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -206,8 +206,9 @@ public class DirectIODirectory extends FilterDirectory {
* Creates a new instance of DirectIOIndexOutput for writing index output with direct IO
* bypassing OS buffer
*
* @throws UnsupportedOperationException if the operating system, file system or JDK does not
* support Direct I/O or a sufficient equivalent.
* @throws UnsupportedOperationException if the JDK does not support Direct I/O
* @throws IOException if the operating system or filesystem does not support support Direct I/O
* or a sufficient equivalent.
*/
public DirectIOIndexOutput(Path path, String name, int blockSize, int bufferSize)
throws IOException {
@ -300,8 +301,9 @@ public class DirectIODirectory extends FilterDirectory {
* Creates a new instance of DirectIOIndexInput for reading index input with direct IO bypassing
* OS buffer
*
* @throws UnsupportedOperationException if the operating system, file system or JDK does not
* support Direct I/O or a sufficient equivalent.
* @throws UnsupportedOperationException if the JDK does not support Direct I/O
* @throws IOException if the operating system or filesystem does not support support Direct I/O
* or a sufficient equivalent.
*/
public DirectIOIndexInput(Path path, int blockSize, int bufferSize) throws IOException {
super("DirectIOIndexInput(path=\"" + path + "\")");

View File

@ -34,14 +34,21 @@ import org.junit.BeforeClass;
public class TestDirectIODirectory extends BaseDirectoryTestCase {
@BeforeClass
public static void checkSupported() {
public static void checkSupported() throws IOException {
assumeTrue(
"This test required a JDK version that has support for ExtendedOpenOption.DIRECT",
DirectIODirectory.ExtendedOpenOption_DIRECT != null);
// jdk supports it, let's check that the filesystem does too
Path path = createTempDir("directIOProbe");
try (Directory dir = open(path);
IndexOutput out = dir.createOutput("out", IOContext.DEFAULT)) {
out.writeString("test");
} catch (IOException e) {
assumeNoException("test requires filesystem that supports Direct IO", e);
}
}
@Override
protected DirectIODirectory getDirectory(Path path) throws IOException {
private static DirectIODirectory open(Path path) throws IOException {
return new DirectIODirectory(FSDirectory.open(path)) {
@Override
protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) {
@ -50,6 +57,11 @@ public class TestDirectIODirectory extends BaseDirectoryTestCase {
};
}
@Override
protected DirectIODirectory getDirectory(Path path) throws IOException {
return open(path);
}
public void testIndexWriteRead() throws IOException {
try (Directory dir = getDirectory(createTempDir("testDirectIODirectory"))) {
try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {