Skip to content

Commit

Permalink
LUCENE-9774: Fix TestDirectIODirectory to probe for supported filesys…
Browse files Browse the repository at this point in the history
…tem (apache#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.
  • Loading branch information
rmuir authored Feb 19, 2021
1 parent f920b9b commit 6deee14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ private static final class DirectIOIndexOutput extends IndexOutput {
* 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 {
Expand Down Expand Up @@ -300,8 +301,9 @@ private static final class DirectIOIndexInput extends IndexInput {
* 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 + "\")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@
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) {
Expand All @@ -50,6 +57,11 @@ protected boolean useDirectIO(String name, IOContext context, OptionalLong fileL
};
}

@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)) {
Expand Down

0 comments on commit 6deee14

Please sign in to comment.