LUCENE-5904: fix false fail

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1621429 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-08-30 08:42:57 +00:00
parent 7bb8cd1e39
commit 24e22029ce
2 changed files with 19 additions and 0 deletions

View File

@ -2504,7 +2504,10 @@ public class TestIndexWriter extends LuceneTestCase {
public void testCorruptFirstCommit() throws Exception { public void testCorruptFirstCommit() throws Exception {
for(int i=0;i<6;i++) { for(int i=0;i<6;i++) {
BaseDirectoryWrapper dir = newDirectory(); BaseDirectoryWrapper dir = newDirectory();
// Create a corrupt first commit:
dir.createOutput("segments_0", IOContext.DEFAULT).close(); dir.createOutput("segments_0", IOContext.DEFAULT).close();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())); IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
int mode = i/2; int mode = i/2;
if (mode == 0) { if (mode == 0) {
@ -2544,6 +2547,16 @@ public class TestIndexWriter extends LuceneTestCase {
if (mode != 0) { if (mode != 0) {
dir.setCheckIndexOnClose(false); dir.setCheckIndexOnClose(false);
} }
if (dir instanceof MockDirectoryWrapper) {
MockDirectoryWrapper mdw = (MockDirectoryWrapper) dir;
if (Arrays.equals(new String[] {"segments_0"}, dir.listAll()) &&
mdw.didTryToDelete("segments_0")) {
// This means virus checker blocked IW deleting the corrupt first commit
dir.setCheckIndexOnClose(false);
}
}
dir.close(); dir.close();
} }
} }

View File

@ -494,6 +494,12 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
in.deleteFile(name); in.deleteFile(name);
} }
/** Returns true if {@link #deleteFile} was called with this
* fileName, but the virus checker prevented the deletion. */
public boolean didTryToDelete(String fileName) {
return triedToDelete.contains(fileName);
}
public synchronized Set<String> getOpenDeletedFiles() { public synchronized Set<String> getOpenDeletedFiles() {
return new HashSet<>(openFilesDeleted); return new HashSet<>(openFilesDeleted);
} }