You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2016/02/06 15:41:18 UTC

lucene-solr git commit: LUCENE-6835: add test case confirming listAll is sorted; fix dir impls that weren't

Repository: lucene-solr
Updated Branches:
  refs/heads/master 8e784699f -> 3c15c3f03


LUCENE-6835: add test case confirming listAll is sorted; fix dir impls that weren't


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/3c15c3f0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/3c15c3f0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/3c15c3f0

Branch: refs/heads/master
Commit: 3c15c3f03df2d769174964e59a760264dce918d8
Parents: 8e78469
Author: Mike McCandless <mi...@apache.org>
Authored: Sat Feb 6 09:41:46 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Sat Feb 6 09:41:46 2016 -0500

----------------------------------------------------------------------
 .../lucene/store/FileSwitchDirectory.java       |  5 +++-
 .../lucene/store/NRTCachingDirectory.java       |  4 ++-
 .../lucene/store/BaseDirectoryTestCase.java     | 26 ++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3c15c3f0/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
index eb3fa0f..db9f085 100644
--- a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java
@@ -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. */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3c15c3f0/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index 4f3b254..ef7b895 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/3c15c3f0/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
index c2e1996..3d9c20d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
@@ -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);
+    }
+  }
 }