You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2010/10/31 17:29:55 UTC
svn commit: r1029397 -
/lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
Author: mikemccand
Date: Sun Oct 31 16:29:55 2010
New Revision: 1029397
URL: http://svn.apache.org/viewvc?rev=1029397&view=rev
Log:
fix broken TestBackwardsCompatibility on 2.4.x bw branch
Modified:
lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
Modified: lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1029397&r1=1029396&r2=1029397&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Sun Oct 31 16:29:55 2010
@@ -132,7 +132,7 @@ public class TestBackwardsCompatibility
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
unzip(dirName, oldNames[i]);
String fullPath = fullDir(oldNames[i]);
- Directory dir = FSDirectory.open(new File(fullPath));
+ Directory dir = FSDirectory.getDirectory(fullPath);
IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
w.optimize();
w.close();
@@ -156,7 +156,11 @@ public class TestBackwardsCompatibility
for(int i=0;i<oldNames.length;i++) {
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
unzip(dirName, oldNames[i]);
- changeIndexNoAdds(oldNames[i]);
+ changeIndexNoAdds(oldNames[i], true);
+ rmDir(oldNames[i]);
+
+ unzip(dirName, oldNames[i]);
+ changeIndexNoAdds(oldNames[i], false);
rmDir(oldNames[i]);
}
}
@@ -165,7 +169,11 @@ public class TestBackwardsCompatibility
for(int i=0;i<oldNames.length;i++) {
String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
unzip(dirName, oldNames[i]);
- changeIndexWithAdds(oldNames[i]);
+ changeIndexWithAdds(oldNames[i], true);
+ rmDir(oldNames[i]);
+
+ unzip(dirName, oldNames[i]);
+ changeIndexWithAdds(oldNames[i], false);
rmDir(oldNames[i]);
}
}
@@ -185,8 +193,8 @@ public class TestBackwardsCompatibility
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
- IndexSearcher searcher = new IndexSearcher(dir, true);
+ Directory dir = FSDirectory.getDirectory(dirName);
+ IndexSearcher searcher = new IndexSearcher(dir);
IndexReader reader = searcher.getIndexReader();
_TestUtil.checkIndex(dir);
@@ -242,14 +250,14 @@ public class TestBackwardsCompatibility
/* Open pre-lockless index, add docs, do a delete &
* setNorm, and search */
- public void changeIndexWithAdds(String dirName) throws IOException {
+ public void changeIndexWithAdds(String dirName, boolean autoCommit) throws IOException {
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = FSDirectory.getDirectory(dirName);
// open writer
- IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
+ IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false);
// add 10 docs
for(int i=0;i<10;i++) {
@@ -261,7 +269,7 @@ public class TestBackwardsCompatibility
writer.close();
// make sure searching sees right # hits
- IndexSearcher searcher = new IndexSearcher(dir, true);
+ IndexSearcher searcher = new IndexSearcher(dir);
ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
Document d = searcher.doc(hits[0].doc);
assertEquals("wrong first document", "21", d.get("id"));
@@ -270,7 +278,7 @@ public class TestBackwardsCompatibility
// make sure we can do delete & setNorm against this
// pre-lockless segment:
- IndexReader reader = IndexReader.open(dir, false);
+ IndexReader reader = IndexReader.open(dir);
Term searchTerm = new Term("id", "6");
int delCount = reader.deleteDocuments(searchTerm);
assertEquals("wrong delete count", 1, delCount);
@@ -278,7 +286,7 @@ public class TestBackwardsCompatibility
reader.close();
// make sure they "took":
- searcher = new IndexSearcher(dir, true);
+ searcher = new IndexSearcher(dir);
hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
assertEquals("wrong number of hits", 43, hits.length);
d = searcher.doc(hits[0].doc);
@@ -287,11 +295,11 @@ public class TestBackwardsCompatibility
searcher.close();
// optimize
- writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
+ writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false);
writer.optimize();
writer.close();
- searcher = new IndexSearcher(dir, true);
+ searcher = new IndexSearcher(dir);
hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
assertEquals("wrong number of hits", 43, hits.length);
d = searcher.doc(hits[0].doc);
@@ -304,14 +312,14 @@ public class TestBackwardsCompatibility
/* Open pre-lockless index, add docs, do a delete &
* setNorm, and search */
- public void changeIndexNoAdds(String dirName) throws IOException {
+ public void changeIndexNoAdds(String dirName, boolean autoCommit) throws IOException {
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = FSDirectory.getDirectory(dirName);
// make sure searching sees right # hits
- IndexSearcher searcher = new IndexSearcher(dir, true);
+ IndexSearcher searcher = new IndexSearcher(dir);
ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
assertEquals("wrong number of hits", 34, hits.length);
Document d = searcher.doc(hits[0].doc);
@@ -320,7 +328,7 @@ public class TestBackwardsCompatibility
// make sure we can do a delete & setNorm against this
// pre-lockless segment:
- IndexReader reader = IndexReader.open(dir, false);
+ IndexReader reader = IndexReader.open(dir);
Term searchTerm = new Term("id", "6");
int delCount = reader.deleteDocuments(searchTerm);
assertEquals("wrong delete count", 1, delCount);
@@ -328,7 +336,7 @@ public class TestBackwardsCompatibility
reader.close();
// make sure they "took":
- searcher = new IndexSearcher(dir, true);
+ searcher = new IndexSearcher(dir);
hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
assertEquals("wrong number of hits", 33, hits.length);
d = searcher.doc(hits[0].doc);
@@ -337,11 +345,11 @@ public class TestBackwardsCompatibility
searcher.close();
// optimize
- IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
+ IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false);
writer.optimize();
writer.close();
- searcher = new IndexSearcher(dir, true);
+ searcher = new IndexSearcher(dir);
hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs;
assertEquals("wrong number of hits", 33, hits.length);
d = searcher.doc(hits[0].doc);
@@ -358,7 +366,7 @@ public class TestBackwardsCompatibility
dirName = fullDir(dirName);
- Directory dir = FSDirectory.open(new File(dirName));
+ Directory dir = FSDirectory.getDirectory(dirName);
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
writer.setUseCompoundFile(doCFS);
writer.setMaxBufferedDocs(10);
@@ -366,11 +374,11 @@ public class TestBackwardsCompatibility
for(int i=0;i<35;i++) {
addDoc(writer, i);
}
- assertEquals("wrong doc count", 35, writer.maxDoc());
+ assertEquals("wrong doc count", 35, writer.docCount());
writer.close();
// Delete one doc so we get a .del file:
- IndexReader reader = IndexReader.open(dir, false);
+ IndexReader reader = IndexReader.open(dir);
Term searchTerm = new Term("id", "7");
int delCount = reader.deleteDocuments(searchTerm);
assertEquals("didn't delete the right number of documents", 1, delCount);
@@ -384,66 +392,71 @@ public class TestBackwardsCompatibility
public void testExactFileNames() throws IOException {
- String outputDir = "lucene.backwardscompat0.index";
- rmDir(outputDir);
+ for(int pass=0;pass<2;pass++) {
+
+ String outputDir = "lucene.backwardscompat0.index";
+ rmDir(outputDir);
- try {
- Directory dir = FSDirectory.open(new File(fullDir(outputDir)));
+ try {
+ Directory dir = FSDirectory.getDirectory(fullDir(outputDir));
- IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
- writer.setRAMBufferSizeMB(16.0);
- for(int i=0;i<35;i++) {
- addDoc(writer, i);
- }
- assertEquals("wrong doc count", 35, writer.docCount());
- writer.close();
+ boolean autoCommit = 0 == pass;
+
+ IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true);
+ writer.setRAMBufferSizeMB(16.0);
+ for(int i=0;i<35;i++) {
+ addDoc(writer, i);
+ }
+ assertEquals("wrong doc count", 35, writer.docCount());
+ writer.close();
- // Delete one doc so we get a .del file:
- IndexReader reader = IndexReader.open(dir, false);
- Term searchTerm = new Term("id", "7");
- int delCount = reader.deleteDocuments(searchTerm);
- assertEquals("didn't delete the right number of documents", 1, delCount);
-
- // Set one norm so we get a .s0 file:
- reader.setNorm(21, "content", (float) 1.5);
- reader.close();
-
- // The numbering of fields can vary depending on which
- // JRE is in use. On some JREs we see content bound to
- // field 0; on others, field 1. So, here we have to
- // figure out which field number corresponds to
- // "content", and then set our expected file names below
- // accordingly:
- CompoundFileReader cfsReader = new CompoundFileReader(dir, "_0.cfs");
- FieldInfos fieldInfos = new FieldInfos(cfsReader, "_0.fnm");
- int contentFieldIndex = -1;
- for(int i=0;i<fieldInfos.size();i++) {
- FieldInfo fi = fieldInfos.fieldInfo(i);
- if (fi.name.equals("content")) {
- contentFieldIndex = i;
- break;
+ // Delete one doc so we get a .del file:
+ IndexReader reader = IndexReader.open(dir);
+ Term searchTerm = new Term("id", "7");
+ int delCount = reader.deleteDocuments(searchTerm);
+ assertEquals("didn't delete the right number of documents", 1, delCount);
+
+ // Set one norm so we get a .s0 file:
+ reader.setNorm(21, "content", (float) 1.5);
+ reader.close();
+
+ // The numbering of fields can vary depending on which
+ // JRE is in use. On some JREs we see content bound to
+ // field 0; on others, field 1. So, here we have to
+ // figure out which field number corresponds to
+ // "content", and then set our expected file names below
+ // accordingly:
+ CompoundFileReader cfsReader = new CompoundFileReader(dir, "_0.cfs");
+ FieldInfos fieldInfos = new FieldInfos(cfsReader, "_0.fnm");
+ int contentFieldIndex = -1;
+ for(int i=0;i<fieldInfos.size();i++) {
+ FieldInfo fi = fieldInfos.fieldInfo(i);
+ if (fi.name.equals("content")) {
+ contentFieldIndex = i;
+ break;
+ }
}
- }
- cfsReader.close();
- assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);
+ cfsReader.close();
+ assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);
- // Now verify file names:
- String[] expected;
- expected = new String[] {"_0.cfs",
- "_0_1.del",
- "_0_1.s" + contentFieldIndex,
- "segments_3",
- "segments.gen"};
-
- String[] actual = dir.listAll();
- Arrays.sort(expected);
- Arrays.sort(actual);
- if (!Arrays.equals(expected, actual)) {
- fail("incorrect filenames in index: expected:\n " + asString(expected) + "\n actual:\n " + asString(actual));
+ // Now verify file names:
+ String[] expected;
+ expected = new String[] {"_0.cfs",
+ "_0_1.del",
+ "_0_1.s" + contentFieldIndex,
+ "segments_3",
+ "segments.gen"};
+
+ String[] actual = dir.list();
+ Arrays.sort(expected);
+ Arrays.sort(actual);
+ if (!Arrays.equals(expected, actual)) {
+ fail("incorrect filenames in index: expected:\n " + asString(expected) + "\n actual:\n " + asString(actual));
+ }
+ dir.close();
+ } finally {
+ rmDir(outputDir);
}
- dir.close();
- } finally {
- rmDir(outputDir);
}
}