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/07 20:45:52 UTC
[15/21] lucene-solr git commit: MDW's
assertNoUnreferencedFilesOnClose should still run even if checkIndexOnClose
is turned off
MDW's assertNoUnreferencedFilesOnClose should still run even if checkIndexOnClose is turned off
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8e8aa086
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8e8aa086
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8e8aa086
Branch: refs/heads/jira/lucene-5438-nrt-replication
Commit: 8e8aa0869e1e419682fd74b0415efa926d1fea87
Parents: 53597e8
Author: Mike McCandless <mi...@apache.org>
Authored: Sun Feb 7 09:19:57 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Sun Feb 7 09:19:57 2016 -0500
----------------------------------------------------------------------
.../lucene/store/MockDirectoryWrapper.java | 107 ++++++++++---------
1 file changed, 54 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e8aa086/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
----------------------------------------------------------------------
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 51dbffe..68bacbd 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
@@ -722,80 +722,81 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper {
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks, cause);
}
- if (getCheckIndexOnClose()) {
- randomIOExceptionRate = 0.0;
- randomIOExceptionRateOnOpen = 0.0;
+ randomIOExceptionRate = 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
if (LuceneTestCase.VERBOSE) {
System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex");
}
TestUtil.checkIndex(this, getCrossCheckTermVectorsOnClose(), true);
+ }
- // TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
- if (assertNoUnreferencedFilesOnClose) {
+ // TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
+ if (assertNoUnreferencedFilesOnClose) {
- // now look for unreferenced files: discount ones that we tried to delete but could not
- Set<String> allFiles = new HashSet<>(Arrays.asList(listAll()));
- String[] startFiles = allFiles.toArray(new String[0]);
- IndexWriterConfig iwc = new IndexWriterConfig(null);
- iwc.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
+ // now look for unreferenced files: discount ones that we tried to delete but could not
+ Set<String> allFiles = new HashSet<>(Arrays.asList(listAll()));
+ String[] startFiles = allFiles.toArray(new String[0]);
+ IndexWriterConfig iwc = new IndexWriterConfig(null);
+ iwc.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
- // We must do this before opening writer otherwise writer will be angry if there are pending deletions:
- TestUtil.disableVirusChecker(in);
+ // We must do this before opening writer otherwise writer will be angry if there are pending deletions:
+ TestUtil.disableVirusChecker(in);
- new IndexWriter(in, iwc).rollback();
- String[] endFiles = in.listAll();
+ new IndexWriter(in, iwc).rollback();
+ String[] endFiles = in.listAll();
- Set<String> startSet = new TreeSet<>(Arrays.asList(startFiles));
- Set<String> endSet = new TreeSet<>(Arrays.asList(endFiles));
+ Set<String> startSet = new TreeSet<>(Arrays.asList(startFiles));
+ Set<String> endSet = new TreeSet<>(Arrays.asList(endFiles));
- startFiles = startSet.toArray(new String[0]);
- endFiles = endSet.toArray(new String[0]);
+ startFiles = startSet.toArray(new String[0]);
+ endFiles = endSet.toArray(new String[0]);
- if (!Arrays.equals(startFiles, endFiles)) {
- List<String> removed = new ArrayList<>();
- for(String fileName : startFiles) {
- if (!endSet.contains(fileName)) {
- removed.add(fileName);
- }
- }
-
- List<String> added = new ArrayList<>();
- for(String fileName : endFiles) {
- if (!startSet.contains(fileName)) {
- added.add(fileName);
- }
+ if (!Arrays.equals(startFiles, endFiles)) {
+ List<String> removed = new ArrayList<>();
+ for(String fileName : startFiles) {
+ if (!endSet.contains(fileName)) {
+ removed.add(fileName);
}
+ }
- String extras;
- if (removed.size() != 0) {
- extras = "\n\nThese files were removed: " + removed;
- } else {
- extras = "";
+ List<String> added = new ArrayList<>();
+ for(String fileName : endFiles) {
+ if (!startSet.contains(fileName)) {
+ added.add(fileName);
}
+ }
- if (added.size() != 0) {
- extras += "\n\nThese files were added (waaaaaaaaaat!): " + added;
- }
+ String extras;
+ if (removed.size() != 0) {
+ extras = "\n\nThese files were removed: " + removed;
+ } else {
+ extras = "";
+ }
- throw new RuntimeException("unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles) + extras);
+ if (added.size() != 0) {
+ extras += "\n\nThese files were added (waaaaaaaaaat!): " + added;
}
-
- 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;
+
+ 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;