make all Directory.listAll's sort, and add BaseDirectoryTestCase; add TODO; suppress VirusCheckingFS for another test

This commit is contained in:
Mike McCandless 2016-02-04 12:17:46 -05:00
parent 9cf74f791c
commit dd6379c05f
8 changed files with 21 additions and 9 deletions

View File

@ -699,14 +699,15 @@ final class IndexFileDeleter implements Closeable {
infoStream.message("IFD", "delete \"" + names + "\""); infoStream.message("IFD", "delete \"" + names + "\"");
} }
// nocommit put annoying windows-specific segments_N heroics back?
for(String name : names) { for(String name : names) {
try { try {
directory.deleteFile(name); directory.deleteFile(name);
} catch (NoSuchFileException | FileNotFoundException e) { } catch (NoSuchFileException | FileNotFoundException e) {
// IndexWriter should only ask us to delete files it knows it wrote, so if we hit this, something is wrong! // IndexWriter should only ask us to delete files it knows it wrote, so if we hit this, something is wrong!
if (Constants.WINDOWS) { 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 // LUCENE-6684: we suppress this assert for Windows, since a file could be in a confusing "pending delete" state, and falsely
// return NSFE/FNFE // return NSFE/FNFE
} else { } else {

View File

@ -754,8 +754,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* IO error * IO error
*/ */
public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException { public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException {
if (d instanceof FSDirectory && ((FSDirectory) d).checkPendingDeletions()) { Directory unwrapped = FilterDirectory.unwrap(d);
throw new IllegalArgumentException("Directory still has pending deleted files"); 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 conf.setIndexWriter(this); // prevent reuse by other instances

View File

@ -43,7 +43,7 @@ import org.apache.lucene.util.IOUtils;
public abstract class Directory implements Closeable { 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 * @throws IOException in case of IO error
*/ */

View File

@ -21,6 +21,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -119,8 +120,12 @@ public class RAMDirectory extends BaseDirectory implements Accountable {
// concurrently // concurrently
Set<String> fileNames = fileMap.keySet(); Set<String> fileNames = fileMap.keySet();
List<String> names = new ArrayList<>(fileNames.size()); List<String> names = new ArrayList<>(fileNames.size());
for (String name : fileNames) names.add(name); for (String name : fileNames) {
return names.toArray(new String[names.size()]); names.add(name);
}
String[] namesArray = names.toArray(new String[names.size()]);
Arrays.sort(namesArray);
return namesArray;
} }
public final boolean fileNameExists(String name) { public final boolean fileNameExists(String name) {

View File

@ -2738,7 +2738,7 @@ public class TestIndexWriter extends LuceneTestCase {
try { try {
w = new IndexWriter(dir, iwc); w = new IndexWriter(dir, iwc);
} catch (IllegalArgumentException iae) { } 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(); in.close();
} }

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; 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.SortedSetDocValues;
import org.apache.lucene.index.SortingMergePolicy; import org.apache.lucene.index.SortingMergePolicy;
import org.apache.lucene.index.Term; 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.Occur;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Collector; import org.apache.lucene.search.Collector;
import org.apache.lucene.search.EarlyTerminatingSortingCollector; import org.apache.lucene.search.EarlyTerminatingSortingCollector;

View File

@ -45,10 +45,12 @@ import org.apache.lucene.search.suggest.Lookup.LookupResult;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.junit.Test; import org.junit.Test;
@SuppressFileSystems("VirusCheckingFS")
public class AnalyzingInfixSuggesterTest extends LuceneTestCase { public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
public void testBasic() throws Exception { public void testBasic() throws Exception {

View File

@ -33,9 +33,11 @@ import org.apache.lucene.search.suggest.Input;
import org.apache.lucene.search.suggest.InputArrayIterator; import org.apache.lucene.search.suggest.InputArrayIterator;
import org.apache.lucene.search.suggest.Lookup; import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
@SuppressFileSystems("VirusCheckingFS")
public class BlendedInfixSuggesterTest extends LuceneTestCase { public class BlendedInfixSuggesterTest extends LuceneTestCase {