mirror of https://github.com/apache/lucene.git
MDW's assertNoUnreferencedFilesOnClose should still run even if checkIndexOnClose is turned off
This commit is contained in:
parent
53597e8f8e
commit
8e8aa0869e
|
@ -722,80 +722,81 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
|
||||||
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks, cause);
|
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCheckIndexOnClose()) {
|
randomIOExceptionRate = 0.0;
|
||||||
randomIOExceptionRate = 0.0;
|
randomIOExceptionRateOnOpen = 0.0;
|
||||||
randomIOExceptionRateOnOpen = 0.0;
|
|
||||||
|
if ((getCheckIndexOnClose() || assertNoUnreferencedFilesOnClose) && DirectoryReader.indexExists(this)) {
|
||||||
|
if (LuceneTestCase.VERBOSE) {
|
||||||
|
System.out.println("\nNOTE: MockDirectoryWrapper: now crush");
|
||||||
|
}
|
||||||
|
if (getCheckIndexOnClose()) {
|
||||||
|
|
||||||
if (DirectoryReader.indexExists(this)) {
|
|
||||||
if (LuceneTestCase.VERBOSE) {
|
|
||||||
System.out.println("\nNOTE: MockDirectoryWrapper: now crush");
|
|
||||||
}
|
|
||||||
crash(); // corrupt any unsynced-files
|
crash(); // corrupt any unsynced-files
|
||||||
if (LuceneTestCase.VERBOSE) {
|
if (LuceneTestCase.VERBOSE) {
|
||||||
System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex");
|
System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex");
|
||||||
}
|
}
|
||||||
|
|
||||||
TestUtil.checkIndex(this, getCrossCheckTermVectorsOnClose(), true);
|
TestUtil.checkIndex(this, getCrossCheckTermVectorsOnClose(), true);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
|
// TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
|
||||||
if (assertNoUnreferencedFilesOnClose) {
|
if (assertNoUnreferencedFilesOnClose) {
|
||||||
|
|
||||||
// now look for unreferenced files: discount ones that we tried to delete but could not
|
// now look for unreferenced files: discount ones that we tried to delete but could not
|
||||||
Set<String> allFiles = new HashSet<>(Arrays.asList(listAll()));
|
Set<String> allFiles = new HashSet<>(Arrays.asList(listAll()));
|
||||||
String[] startFiles = allFiles.toArray(new String[0]);
|
String[] startFiles = allFiles.toArray(new String[0]);
|
||||||
IndexWriterConfig iwc = new IndexWriterConfig(null);
|
IndexWriterConfig iwc = new IndexWriterConfig(null);
|
||||||
iwc.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
|
iwc.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
|
||||||
|
|
||||||
// We must do this before opening writer otherwise writer will be angry if there are pending deletions:
|
// We must do this before opening writer otherwise writer will be angry if there are pending deletions:
|
||||||
TestUtil.disableVirusChecker(in);
|
TestUtil.disableVirusChecker(in);
|
||||||
|
|
||||||
new IndexWriter(in, iwc).rollback();
|
new IndexWriter(in, iwc).rollback();
|
||||||
String[] endFiles = in.listAll();
|
String[] endFiles = in.listAll();
|
||||||
|
|
||||||
Set<String> startSet = new TreeSet<>(Arrays.asList(startFiles));
|
Set<String> startSet = new TreeSet<>(Arrays.asList(startFiles));
|
||||||
Set<String> endSet = new TreeSet<>(Arrays.asList(endFiles));
|
Set<String> endSet = new TreeSet<>(Arrays.asList(endFiles));
|
||||||
|
|
||||||
startFiles = startSet.toArray(new String[0]);
|
startFiles = startSet.toArray(new String[0]);
|
||||||
endFiles = endSet.toArray(new String[0]);
|
endFiles = endSet.toArray(new String[0]);
|
||||||
|
|
||||||
if (!Arrays.equals(startFiles, endFiles)) {
|
if (!Arrays.equals(startFiles, endFiles)) {
|
||||||
List<String> removed = new ArrayList<>();
|
List<String> removed = new ArrayList<>();
|
||||||
for(String fileName : startFiles) {
|
for(String fileName : startFiles) {
|
||||||
if (!endSet.contains(fileName)) {
|
if (!endSet.contains(fileName)) {
|
||||||
removed.add(fileName);
|
removed.add(fileName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> added = new ArrayList<>();
|
|
||||||
for(String fileName : endFiles) {
|
|
||||||
if (!startSet.contains(fileName)) {
|
|
||||||
added.add(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String extras;
|
|
||||||
if (removed.size() != 0) {
|
|
||||||
extras = "\n\nThese files were removed: " + removed;
|
|
||||||
} else {
|
|
||||||
extras = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (added.size() != 0) {
|
|
||||||
extras += "\n\nThese files were added (waaaaaaaaaat!): " + added;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles) + extras);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectoryReader ir1 = DirectoryReader.open(this);
|
List<String> added = new ArrayList<>();
|
||||||
int numDocs1 = ir1.numDocs();
|
for(String fileName : endFiles) {
|
||||||
ir1.close();
|
if (!startSet.contains(fileName)) {
|
||||||
new IndexWriter(this, new IndexWriterConfig(null)).close();
|
added.add(fileName);
|
||||||
DirectoryReader ir2 = DirectoryReader.open(this);
|
}
|
||||||
int numDocs2 = ir2.numDocs();
|
}
|
||||||
ir2.close();
|
|
||||||
assert numDocs1 == numDocs2 : "numDocs changed after opening/closing IW: before=" + numDocs1 + " after=" + numDocs2;
|
String extras;
|
||||||
|
if (removed.size() != 0) {
|
||||||
|
extras = "\n\nThese files were removed: " + removed;
|
||||||
|
} else {
|
||||||
|
extras = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (added.size() != 0) {
|
||||||
|
extras += "\n\nThese files were added (waaaaaaaaaat!): " + added;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles) + extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DirectoryReader ir1 = DirectoryReader.open(this);
|
||||||
|
int numDocs1 = ir1.numDocs();
|
||||||
|
ir1.close();
|
||||||
|
new IndexWriter(this, new IndexWriterConfig(null)).close();
|
||||||
|
DirectoryReader ir2 = DirectoryReader.open(this);
|
||||||
|
int numDocs2 = ir2.numDocs();
|
||||||
|
ir2.close();
|
||||||
|
assert numDocs1 == numDocs2 : "numDocs changed after opening/closing IW: before=" + numDocs1 + " after=" + numDocs2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
|
|
Loading…
Reference in New Issue