lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Fwd: svn commit: r822301 - /lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
Date Wed, 07 Oct 2009 15:01:05 GMT
Woops, I put this fix onto the 2.4 back-compat branch, not the new 2.9
one, yesterday.

I just fixed it (I think!) on the 2.9 back-compat branch.

Mike

---------- Forwarded message ----------
From:  <mikemccand@apache.org>
Date: Tue, Oct 6, 2009 at 10:53 AM
Subject: svn commit: r822301 -
/lucene/java/branches/lucene_2_4_back_compat_tests/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
To: java-commits@lucene.apache.org


Author: mikemccand
Date: Tue Oct  6 14:53:12 2009
New Revision: 822301

URL: http://svn.apache.org/viewvc?rev=822301&view=rev
Log:
fix TestBackwardsCompatibility to not use deprecated APIs, on back-compat 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=822301&r1=822300&r2=822301&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
Tue Oct  6 14:53:12 2009
@@ -132,7 +132,7 @@
      String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
      unzip(dirName, oldNames[i]);
      String fullPath = fullDir(oldNames[i]);
-      Directory dir = FSDirectory.getDirectory(fullPath);
+      Directory dir = FSDirectory.open(new File(fullPath));
      IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(),
IndexWriter.MaxFieldLength.LIMITED);
      w.optimize();
      w.close();
@@ -156,11 +156,7 @@
    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], true);
-      rmDir(oldNames[i]);
-
-      unzip(dirName, oldNames[i]);
-      changeIndexNoAdds(oldNames[i], false);
+      changeIndexNoAdds(oldNames[i]);
      rmDir(oldNames[i]);
    }
  }
@@ -169,11 +165,7 @@
    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], true);
-      rmDir(oldNames[i]);
-
-      unzip(dirName, oldNames[i]);
-      changeIndexWithAdds(oldNames[i], false);
+      changeIndexWithAdds(oldNames[i]);
      rmDir(oldNames[i]);
    }
  }
@@ -193,8 +185,8 @@

    dirName = fullDir(dirName);

-    Directory dir = FSDirectory.getDirectory(dirName);
-    IndexSearcher searcher = new IndexSearcher(dir);
+    Directory dir = FSDirectory.open(new File(dirName));
+    IndexSearcher searcher = new IndexSearcher(dir, true);
    IndexReader reader = searcher.getIndexReader();

    _TestUtil.checkIndex(dir);
@@ -250,14 +242,14 @@

  /* Open pre-lockless index, add docs, do a delete &
   * setNorm, and search */
-  public void changeIndexWithAdds(String dirName, boolean autoCommit)
throws IOException {
+  public void changeIndexWithAdds(String dirName) throws IOException {

    dirName = fullDir(dirName);

-    Directory dir = FSDirectory.getDirectory(dirName);
+    Directory dir = FSDirectory.open(new File(dirName));

    // open writer
-    IndexWriter writer = new IndexWriter(dir, autoCommit, new
WhitespaceAnalyzer(), false);
+    IndexWriter writer = new IndexWriter(dir, new
WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);

    // add 10 docs
    for(int i=0;i<10;i++) {
@@ -269,7 +261,7 @@
    writer.close();

    // make sure searching sees right # hits
-    IndexSearcher searcher = new IndexSearcher(dir);
+    IndexSearcher searcher = new IndexSearcher(dir, true);
    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"));
@@ -278,7 +270,7 @@

    // make sure we can do delete & setNorm against this
    // pre-lockless segment:
-    IndexReader reader = IndexReader.open(dir);
+    IndexReader reader = IndexReader.open(dir, false);
    Term searchTerm = new Term("id", "6");
    int delCount = reader.deleteDocuments(searchTerm);
    assertEquals("wrong delete count", 1, delCount);
@@ -286,7 +278,7 @@
    reader.close();

    // make sure they "took":
-    searcher = new IndexSearcher(dir);
+    searcher = new IndexSearcher(dir, true);
    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);
@@ -295,11 +287,11 @@
    searcher.close();

    // optimize
-    writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false);
+    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false,
IndexWriter.MaxFieldLength.UNLIMITED);
    writer.optimize();
    writer.close();

-    searcher = new IndexSearcher(dir);
+    searcher = new IndexSearcher(dir, true);
    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);
@@ -312,14 +304,14 @@

  /* Open pre-lockless index, add docs, do a delete &
   * setNorm, and search */
-  public void changeIndexNoAdds(String dirName, boolean autoCommit)
throws IOException {
+  public void changeIndexNoAdds(String dirName) throws IOException {

    dirName = fullDir(dirName);

-    Directory dir = FSDirectory.getDirectory(dirName);
+    Directory dir = FSDirectory.open(new File(dirName));

    // make sure searching sees right # hits
-    IndexSearcher searcher = new IndexSearcher(dir);
+    IndexSearcher searcher = new IndexSearcher(dir, true);
    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);
@@ -328,7 +320,7 @@

    // make sure we can do a delete & setNorm against this
    // pre-lockless segment:
-    IndexReader reader = IndexReader.open(dir);
+    IndexReader reader = IndexReader.open(dir, false);
    Term searchTerm = new Term("id", "6");
    int delCount = reader.deleteDocuments(searchTerm);
    assertEquals("wrong delete count", 1, delCount);
@@ -336,7 +328,7 @@
    reader.close();

    // make sure they "took":
-    searcher = new IndexSearcher(dir);
+    searcher = new IndexSearcher(dir, true);
    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);
@@ -345,11 +337,11 @@
    searcher.close();

    // optimize
-    IndexWriter writer = new IndexWriter(dir, autoCommit, new
WhitespaceAnalyzer(), false);
+    IndexWriter writer = new IndexWriter(dir, new
WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
    writer.optimize();
    writer.close();

-    searcher = new IndexSearcher(dir);
+    searcher = new IndexSearcher(dir, true);
    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);
@@ -366,7 +358,7 @@

    dirName = fullDir(dirName);

-    Directory dir = FSDirectory.getDirectory(dirName);
+    Directory dir = FSDirectory.open(new File(dirName));
    IndexWriter writer = new IndexWriter(dir, new
WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
    writer.setUseCompoundFile(doCFS);
    writer.setMaxBufferedDocs(10);
@@ -374,11 +366,11 @@
    for(int i=0;i<35;i++) {
      addDoc(writer, i);
    }
-    assertEquals("wrong doc count", 35, writer.docCount());
+    assertEquals("wrong doc count", 35, writer.maxDoc());
    writer.close();

    // Delete one doc so we get a .del file:
-    IndexReader reader = IndexReader.open(dir);
+    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);
@@ -392,71 +384,66 @@

  public void testExactFileNames() throws IOException {

-    for(int pass=0;pass<2;pass++) {
-
-      String outputDir = "lucene.backwardscompat0.index";
-      rmDir(outputDir);
+    String outputDir = "lucene.backwardscompat0.index";
+    rmDir(outputDir);

-      try {
-        Directory dir = FSDirectory.getDirectory(fullDir(outputDir));
+    try {
+      Directory dir = FSDirectory.open(new File(fullDir(outputDir)));

-        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();
+      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();

-        // 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;
-          }
+      // 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;
        }
-        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.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);
+      // 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));
      }
+      dir.close();
+    } finally {
+      rmDir(outputDir);
    }
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message