You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/01/16 19:54:51 UTC

[GitHub] [lucene-solr] zacharymorn commented on a change in pull request #2052: LUCENE-8982: Make NativeUnixDirectory pure java with FileChannel direct IO flag, and rename to DirectIODirectory

zacharymorn commented on a change in pull request #2052:
URL: https://github.com/apache/lucene-solr/pull/2052#discussion_r559025677



##########
File path: lucene/misc/src/test/org/apache/lucene/misc/store/TestDirectIODirectory.java
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.misc.store;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.lucene.document.*;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.store.*;
+import org.junit.BeforeClass;
+
+public class TestDirectIODirectory extends BaseDirectoryTestCase {
+
+  @BeforeClass
+  public static void checkSupported() {
+    assumeTrue(
+        "This test required a JDK version that has support for ExtendedOpenOption.DIRECT",
+        DirectIODirectory.ExtendedOpenOption_DIRECT != null);
+  }
+
+  @Override
+  protected DirectIODirectory getDirectory(Path path) throws IOException {
+    return new DirectIODirectory(
+        FSDirectory.open(path), DirectIODirectory.DEFAULT_MERGE_BUFFER_SIZE, 0L) {
+      @Override
+      protected boolean useDirectIO(IOContext context) {
+        return true;
+      }
+    };
+  }
+
+  public void testIndexWriteRead() throws IOException {
+    try (Directory dir = getDirectory(createTempDir("testDirectIODirectory"))) {
+      try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
+        Document doc = new Document();
+        Field field = newField("field", "foo bar", TextField.TYPE_STORED);
+        doc.add(field);
+
+        iw.addDocument(doc);
+        iw.commit();
+      }
+
+      try (IndexReader ir = DirectoryReader.open(dir)) {
+        IndexSearcher s = newSearcher(ir);
+        assertEquals(1, s.count(new PhraseQuery("field", "foo", "bar")));
+      }
+    }
+  }
+
+  public void testIllegalEOFWithFileSizeMultipleOfBlockSize() throws Exception {
+    Path path = createTempDir("testIllegalEOF");
+    final int fileSize = Math.toIntExact(Files.getFileStore(path).getBlockSize()) * 2;

Review comment:
       Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org