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 2010/08/02 21:20:50 UTC
svn commit: r981661 - in /lucene/dev/trunk/lucene/src:
java/org/apache/lucene/store/FSDirectory.java
test/org/apache/lucene/index/TestIndexWriter.java
Author: mikemccand
Date: Mon Aug 2 19:20:50 2010
New Revision: 981661
URL: http://svn.apache.org/viewvc?rev=981661&view=rev
Log:
LUCENE-2574: add missing seek
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java?rev=981661&r1=981660&r2=981661&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/FSDirectory.java Mon Aug 2 19:20:50 2010
@@ -475,6 +475,10 @@ public abstract class FSDirectory extend
// do the optimized copy
FileChannel in = fsInput.file.getChannel();
+
+ // Necessary because BufferedIndexInput does lazy seeking:
+ in.position(fsInput.getFilePointer());
+
FileChannel out = file.getChannel();
long pos = out.position();
long writeTo = numBytes + pos;
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=981661&r1=981660&r2=981661&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Mon Aug 2 19:20:50 2010
@@ -5070,56 +5070,61 @@ public class TestIndexWriter extends Luc
}
public void testRandomStoredFields() throws IOException {
- Directory dir = new MockRAMDirectory();
- Random rand = newRandom();
- RandomIndexWriter w = new RandomIndexWriter(rand, dir, newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(_TestUtil.nextInt(rand, 5, 20)));
- final int docCount = 200*RANDOM_MULTIPLIER;
- final int fieldCount = _TestUtil.nextInt(rand, 1, 5);
- String[][] fields = new String[fieldCount][];
- for(int i=0;i<fieldCount;i++) {
- fields[i] = new String[docCount];
- }
+ File index = _TestUtil.getTempDir("lucenerandfields");
+ Directory dir = FSDirectory.open(index);
+ try {
+ Random rand = newRandom();
+ RandomIndexWriter w = new RandomIndexWriter(rand, dir, newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(_TestUtil.nextInt(rand, 5, 20)));
+ final int docCount = 200*RANDOM_MULTIPLIER;
+ final int fieldCount = _TestUtil.nextInt(rand, 1, 5);
+ String[][] fields = new String[fieldCount][];
+ for(int i=0;i<fieldCount;i++) {
+ fields[i] = new String[docCount];
+ }
- final List<Integer> fieldIDs = new ArrayList<Integer>();
+ final List<Integer> fieldIDs = new ArrayList<Integer>();
- for(int i=0;i<fieldCount;i++) {
- fieldIDs.add(i);
- }
+ for(int i=0;i<fieldCount;i++) {
+ fieldIDs.add(i);
+ }
- for(int i=0;i<docCount;i++) {
- Document doc = new Document();
- for(int field: fieldIDs) {
- final String s;
- if (rand.nextInt(4) != 3) {
- s = _TestUtil.randomUnicodeString(rand, 1000);
- doc.add(new Field("f"+field, s, Field.Store.YES, Field.Index.NO));
- } else {
- s = null;
+ for(int i=0;i<docCount;i++) {
+ Document doc = new Document();
+ for(int field: fieldIDs) {
+ final String s;
+ if (rand.nextInt(4) != 3) {
+ s = _TestUtil.randomUnicodeString(rand, 1000);
+ doc.add(new Field("f"+field, s, Field.Store.YES, Field.Index.NO));
+ } else {
+ s = null;
+ }
+ fields[field][i] = s;
+ }
+ w.addDocument(doc);
+ if (rand.nextInt(50) == 17) {
+ // mixup binding of field name -> Number every so often
+ Collections.shuffle(fieldIDs);
}
- fields[field][i] = s;
- }
- w.addDocument(doc);
- if (rand.nextInt(50) == 17) {
- // mixup binding of field name -> Number every so often
- Collections.shuffle(fieldIDs);
}
- }
- for(int x=0;x<2;x++) {
- IndexReader r = w.getReader();
+ for(int x=0;x<2;x++) {
+ IndexReader r = w.getReader();
- for(int iter=0;iter<1000*RANDOM_MULTIPLIER;iter++) {
- int docID = rand.nextInt(docCount);
- Document doc = r.document(docID);
- for(int i=0;i<fieldCount;i++) {
- assertEquals(fields[i][docID], doc.get("f"+i));
+ for(int iter=0;iter<1000*RANDOM_MULTIPLIER;iter++) {
+ int docID = rand.nextInt(docCount);
+ Document doc = r.document(docID);
+ for(int i=0;i<fieldCount;i++) {
+ assertEquals(fields[i][docID], doc.get("f"+i));
+ }
}
+ r.close();
+ w.optimize();
}
- r.close();
- w.optimize();
- }
- w.close();
+ w.close();
- dir.close();
+ } finally {
+ dir.close();
+ _TestUtil.rmDir(index);
+ }
}
}