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/01/28 17:29:37 UTC

lucene-solr git commit: fix false failures from test bugs

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_5x 5e5a9cad9 -> faf6ff2d1


fix false failures from test bugs


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

Branch: refs/heads/branch_5x
Commit: faf6ff2d13ce92b8697a7093f6623e2a2c065e88
Parents: 5e5a9ca
Author: Mike McCandless <mi...@apache.org>
Authored: Thu Jan 28 11:29:37 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Thu Jan 28 11:29:37 2016 -0500

----------------------------------------------------------------------
 .../index/TestAllFilesCheckIndexHeader.java     | 23 +++++++++++++++-----
 .../index/TestAllFilesDetectTruncation.java     |  4 +++-
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/faf6ff2d/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
index 9dffaa8..3d8aeff 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesCheckIndexHeader.java
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collections;
 
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -80,7 +81,9 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
   
   private void checkIndexHeader(Directory dir) throws IOException {
     for(String name : dir.listAll()) {
-      checkOneFile(dir, name);
+      if (name.equals(IndexWriter.WRITE_LOCK_NAME) == false) {
+        checkOneFile(dir, name);
+      }
     }
   }
   
@@ -99,15 +102,25 @@ public class TestAllFilesCheckIndexHeader extends LuceneTestCase {
         if (name.equals(victim) == false) {
           dirCopy.copyFrom(dir, name, name, IOContext.DEFAULT);
         } else {
-          try(IndexOutput out = dirCopy.createOutput(name, IOContext.DEFAULT);
-              IndexInput in = dir.openInput(name, IOContext.DEFAULT)) {
+
+          // Iterate until our randomly generated bytes are indeed different from the first bytes of the file ... the vast majority of the
+          // time this will only require one iteration!
+          while (true) {
+            try(IndexOutput out = dirCopy.createOutput(name, IOContext.DEFAULT);
+                IndexInput in = dir.openInput(name, IOContext.DEFAULT)) {
               // keeps same file length, but replaces the first wrongBytes with random bytes:
               byte[] bytes = new byte[wrongBytes];
               random().nextBytes(bytes);
               out.writeBytes(bytes, 0, bytes.length);
-              in.seek(wrongBytes);
-              out.copyBytes(in, victimLength - wrongBytes);
+              byte[] bytes2 = new byte[wrongBytes];
+              in.readBytes(bytes2, 0, bytes2.length);
+              if (Arrays.equals(bytes, bytes2) == false) {
+                // We successfully randomly generated bytes that differ from the bytes in the file:
+                out.copyBytes(in, victimLength - wrongBytes);
+                break;
+              }
             }
+          }
         }
         dirCopy.sync(Collections.singleton(name));
       }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/faf6ff2d/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
index bda5857..e5aa6c7 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesDetectTruncation.java
@@ -80,7 +80,9 @@ public class TestAllFilesDetectTruncation extends LuceneTestCase {
   
   private void checkTruncation(Directory dir) throws IOException {
     for(String name : dir.listAll()) {
-      truncateOneFile(dir, name);
+      if (name.equals(IndexWriter.WRITE_LOCK_NAME) == false) {
+        truncateOneFile(dir, name);
+      }
     }
   }