From dd6379c05fa879705fc4717d60c9f44fd47659c0 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Thu, 4 Feb 2016 12:17:46 -0500 Subject: [PATCH] make all Directory.listAll's sort, and add BaseDirectoryTestCase; add TODO; suppress VirusCheckingFS for another test --- .../java/org/apache/lucene/index/IndexFileDeleter.java | 5 +++-- .../src/java/org/apache/lucene/index/IndexWriter.java | 5 +++-- .../core/src/java/org/apache/lucene/store/Directory.java | 2 +- .../src/java/org/apache/lucene/store/RAMDirectory.java | 9 +++++++-- .../test/org/apache/lucene/index/TestIndexWriter.java | 2 +- .../suggest/analyzing/AnalyzingInfixSuggester.java | 3 ++- .../suggest/analyzing/AnalyzingInfixSuggesterTest.java | 2 ++ .../suggest/analyzing/BlendedInfixSuggesterTest.java | 2 ++ 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java index 2e5d5cff19c..d00cec86acf 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java @@ -699,14 +699,15 @@ final class IndexFileDeleter implements Closeable { infoStream.message("IFD", "delete \"" + names + "\""); } - // nocommit put annoying windows-specific segments_N heroics back? - for(String name : names) { try { directory.deleteFile(name); } catch (NoSuchFileException | FileNotFoundException e) { // IndexWriter should only ask us to delete files it knows it wrote, so if we hit this, something is wrong! + if (Constants.WINDOWS) { + // TODO: can we remove this OS-specific hacky logic? If windows deleteFile is buggy, we should instead contain this workaround in + // a WindowsFSDirectory ... // LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, and falsely // return NSFE/FNFE } else { diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index f161f5a98f7..7d72603f1a7 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -754,8 +754,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { * IO error */ public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException { - if (d instanceof FSDirectory && ((FSDirectory) d).checkPendingDeletions()) { - throw new IllegalArgumentException("Directory still has pending deleted files"); + Directory unwrapped = FilterDirectory.unwrap(d); + if (unwrapped instanceof FSDirectory && ((FSDirectory) unwrapped).checkPendingDeletions()) { + throw new IllegalArgumentException("Directory still has pending deleted files; cannot initialize IndexWriter"); } conf.setIndexWriter(this); // prevent reuse by other instances diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java index 6aa46e90a61..f13150c0725 100644 --- a/lucene/core/src/java/org/apache/lucene/store/Directory.java +++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java @@ -43,7 +43,7 @@ import org.apache.lucene.util.IOUtils; public abstract class Directory implements Closeable { /** - * Returns an array of strings, one for each entry in the directory. + * Returns an array of strings, one for each entry in the directory, in sorted (UTF16, java's String.compare) order. * * @throws IOException in case of IO error */ diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java index d1dc0d071b6..a001a0e6919 100644 --- a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -119,8 +120,12 @@ public class RAMDirectory extends BaseDirectory implements Accountable { // concurrently Set fileNames = fileMap.keySet(); List names = new ArrayList<>(fileNames.size()); - for (String name : fileNames) names.add(name); - return names.toArray(new String[names.size()]); + for (String name : fileNames) { + names.add(name); + } + String[] namesArray = names.toArray(new String[names.size()]); + Arrays.sort(namesArray); + return namesArray; } public final boolean fileNameExists(String name) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index a75d0324a95..d6b8f84dc2d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -2738,7 +2738,7 @@ public class TestIndexWriter extends LuceneTestCase { try { w = new IndexWriter(dir, iwc); } catch (IllegalArgumentException iae) { - assertEquals("Directory still has pending deleted files", iae.getMessage()); + assertEquals("Directory still has pending deleted files; cannot initialize IndexWriter", iae.getMessage()); } in.close(); } diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java index 5aaabbdc888..760535fff29 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.StringReader; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -58,8 +59,8 @@ import org.apache.lucene.index.SegmentReader; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.SortingMergePolicy; import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Collector; import org.apache.lucene.search.EarlyTerminatingSortingCollector; diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java index b51894d1b8c..8fc65d7a5c4 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java @@ -45,10 +45,12 @@ import org.apache.lucene.search.suggest.Lookup.LookupResult; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; import org.junit.Test; +@SuppressFileSystems("VirusCheckingFS") public class AnalyzingInfixSuggesterTest extends LuceneTestCase { public void testBasic() throws Exception { diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java index 614a1a2c4fa..470d6a2a71a 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java @@ -33,9 +33,11 @@ import org.apache.lucene.search.suggest.Input; import org.apache.lucene.search.suggest.InputArrayIterator; import org.apache.lucene.search.suggest.Lookup; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; +@SuppressFileSystems("VirusCheckingFS") public class BlendedInfixSuggesterTest extends LuceneTestCase {