You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2021/02/19 01:36:44 UTC
[lucene-solr] branch master updated: LUCENE-9774: Fix
TestDirectIODirectory to probe for supported filesystem (#2396)
This is an automated email from the ASF dual-hosted git repository.
rmuir pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 6deee14 LUCENE-9774: Fix TestDirectIODirectory to probe for supported filesystem (#2396)
6deee14 is described below
commit 6deee143823bcba3849fe204b035d6e0bca23e83
Author: Robert Muir <rm...@apache.org>
AuthorDate: Thu Feb 18 20:36:18 2021 -0500
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.
---
.../apache/lucene/misc/store/DirectIODirectory.java | 10 ++++++----
.../lucene/misc/store/TestDirectIODirectory.java | 18 +++++++++++++++---
2 files changed, 21 insertions(+), 7 deletions(-)
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.java
index 8676668..d51ab5c 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.java
index 1c11782..b24fc4c 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)) {
@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)) {