FileDocCategorySizeDatePackage
TestLazyBug.javaAPI DocApache Lucene 2.1.04224Wed Feb 14 10:46:36 GMT 2007org.apache.lucene.index

TestLazyBug

public class TestLazyBug extends TestCase
Test demonstrating EOF bug on the last field of the last doc if other docs have allready been accessed.

Fields Summary
public static int
BASE_SEED
public static int
NUM_DOCS
public static int
NUM_FIELDS
private static String[]
data
private static Set
dataset
private static String
MAGIC_FIELD
private static FieldSelector
SELECTOR
Constructors Summary
Methods Summary
public static voiddoTest(int[] docs)

    Directory dir = makeIndex();
    IndexReader reader = IndexReader.open(dir);
    for (int i = 0; i < docs.length; i++) {
      Document d = reader.document(docs[i], SELECTOR);
      String trash = d.get(MAGIC_FIELD);
      
      List fields = d.getFields();
      for (Iterator fi = fields.iterator(); fi.hasNext(); ) {
        Fieldable f=null;
        try {
          f = (Fieldable) fi.next();
          String fname = f.name();
          String fval = f.stringValue();
          assertNotNull(docs[i]+" FIELD: "+fname, fval);
          String[] vals = fval.split("#");
          if (!dataset.contains(vals[0]) || !dataset.contains(vals[1])) {        
            fail("FIELD:"+fname+",VAL:"+fval);
          }
        } catch (Exception e) {
          throw new Exception(docs[i]+" WTF: "+f.name(), e);
        }
      }
    }
    reader.close();
  
private static org.apache.lucene.store.DirectorymakeIndex()

  
         
    Directory dir = new RAMDirectory();
    try {
      Random r = new Random(BASE_SEED + 42) ; 
      Analyzer analyzer = new SimpleAnalyzer();
      IndexWriter writer = new IndexWriter(dir, analyzer, true);
      
      writer.setUseCompoundFile(false);
      
      for (int d = 1; d <= NUM_DOCS; d++) {
        Document doc = new Document();
        for (int f = 1; f <= NUM_FIELDS; f++ ) {
          doc.add(new Field("f"+f, 
                            data[f % data.length] 
                            + '#" + data[r.nextInt(data.length)], 
                            Field.Store.YES, 
                            Field.Index.TOKENIZED));
        }
        writer.addDocument(doc);
      }
      writer.close();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return dir;
  
public voidtestLazyAlsoWorks()

    doTest(new int[] { 399, 150 });
  
public voidtestLazyBroken()

    doTest(new int[] { 150, 399 });
  
public voidtestLazyWorks()

    doTest(new int[] { 399 });