mirror of https://github.com/apache/lucene.git
LUCENE-6835: add test case confirming listAll is sorted; fix dir impls that weren't
This commit is contained in:
parent
8e784699f0
commit
3c15c3f03d
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -118,7 +119,9 @@ public class FileSwitchDirectory extends Directory {
|
|||
if (exc != null && files.isEmpty()) {
|
||||
throw exc;
|
||||
}
|
||||
return files.toArray(new String[files.size()]);
|
||||
String[] result = files.toArray(new String[files.size()]);
|
||||
Arrays.sort(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Utility method to return a file's extension. */
|
||||
|
|
|
@ -106,7 +106,9 @@ public class NRTCachingDirectory extends FilterDirectory implements Accountable
|
|||
"cache=" + Arrays.toString(cache.listAll()) + ",delegate=" + Arrays.toString(in.listAll()));
|
||||
}
|
||||
}
|
||||
return files.toArray(new String[files.size()]);
|
||||
String[] result = files.toArray(new String[files.size()]);
|
||||
Arrays.sort(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1295,4 +1295,30 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
|
|||
assertTrue(Arrays.asList(fsDir.listAll()).contains(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
public void testListAllIsSorted() throws IOException {
|
||||
try (Directory dir = getDirectory(createTempDir())) {
|
||||
int count = atLeast(20);
|
||||
Set<String> names = new HashSet<>();
|
||||
while(names.size() < count) {
|
||||
String name = TestUtil.randomSimpleString(random());
|
||||
if (name.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (random().nextInt(5) == 1) {
|
||||
IndexOutput out = dir.createTempOutput(name, "foo", IOContext.DEFAULT);
|
||||
names.add(out.getName());
|
||||
out.close();
|
||||
} else if (names.contains(name) == false) {
|
||||
IndexOutput out = dir.createOutput(name, IOContext.DEFAULT);
|
||||
names.add(out.getName());
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
String[] actual = dir.listAll();
|
||||
String[] expected = actual.clone();
|
||||
Arrays.sort(expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue