Apache Solr open-source search software
LUCENE-9774: Fix TestDirectIODirectory to probe for supported filesystem (#2396)
Robert Muir6deee143823b
diff --git a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.javaindex 8676668f661..d51ab5cc7ba 100644--- a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java+++ b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java@@ -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 + "\")");diff --git a/lucene/misc/src/test/org/apache/lucene/misc/store/TestDirectIODirectory.java b/lucene/misc/src/test/org/apache/lucene/misc/store/TestDirectIODirectory.javaindex 1c11782199c..b24fc4cefbe 100644--- a/lucene/misc/src/test/org/apache/lucene/misc/store/TestDirectIODirectory.java+++ b/lucene/misc/src/test/org/apache/lucene/misc/store/TestDirectIODirectory.java@@ -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)) {@Overrideprotected 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)) {