From b4eb4fb32cb819199a2fb564750393be439be66e Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 9 Mar 2016 10:56:13 +0100 Subject: [PATCH] LUCENE-7080: Sort files to corrupt to prevent HashSet iteration order issues across JVMs --- .../java/org/apache/lucene/store/MockDirectoryWrapper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java index 962062e0312..7fe7c3b0d5a 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java @@ -45,6 +45,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.NoDeletionPolicy; import org.apache.lucene.index.SegmentInfos; +import org.apache.lucene.util.CollectionUtil; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -296,7 +297,11 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper { public synchronized void corruptFiles(Collection files) throws IOException { // Must make a copy because we change the incoming unsyncedFiles // when we create temp files, delete, etc., below: - for(String name : new ArrayList<>(files)) { + final List filesToCorrupt = new ArrayList<>(files); + // sort the files otherwise we have reproducibility issues + // across JVMs if the incoming collection is a hashSet etc. + CollectionUtil.timSort(filesToCorrupt); + for(String name : filesToCorrupt) { int damage = randomState.nextInt(6); String action = null;