mirror of https://github.com/apache/lucene.git
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:
parent
f920b9b14e
commit
6deee14382
|
@ -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 + "\")");
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue