1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
24 import org.apache.lucene.util.*;
25 import org.apache.lucene.store.*;
26 import org.apache.lucene.document.*;
28 public class TestStressAdvance extends LuceneTestCase {
30 public void testStressAdvance() throws Exception {
31 for(int iter=0;iter<3;iter++) {
33 System.out.println("\nTEST: iter=" + iter);
35 Directory dir = newDirectory();
36 RandomIndexWriter w = new RandomIndexWriter(random, dir);
37 final Set<Integer> aDocs = new HashSet<Integer>();
38 final Document doc = new Document();
39 final Field f = newField("field", "", Field.Index.NOT_ANALYZED_NO_NORMS);
41 final Field idField = newField("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
43 int num = atLeast(5000);
44 for(int id=0;id<num;id++) {
45 if (random.nextInt(4) == 3) {
51 idField.setValue(""+id);
57 final List<Integer> aDocIDs = new ArrayList<Integer>();
58 final List<Integer> bDocIDs = new ArrayList<Integer>();
60 final IndexReader r = w.getReader();
61 final int[] idToDocID = new int[r.maxDoc()];
62 for(int docID=0;docID<idToDocID.length;docID++) {
63 int id = Integer.parseInt(r.document(docID).get("id"));
64 if (aDocs.contains(id)) {
70 final TermDocs de = r.termDocs();
72 for(int iter2=0;iter2<10;iter2++) {
74 System.out.println("\nTEST: iter=" + iter + " iter2=" + iter2);
76 de.seek(new Term("field", "a"));
79 de.seek(new Term("field", "b"));
89 private void testOne(TermDocs docs, List<Integer> expected) throws Exception {
91 System.out.println("test");
94 while(upto < expected.size()) {
96 System.out.println(" cycle upto=" + upto + " of " + expected.size());
99 if (random.nextInt(4) == 1 || upto == expected.size()-1) {
102 System.out.println(" do nextDoc");
112 final int inc = _TestUtil.nextInt(random, 1, expected.size()-1-upto);
114 System.out.println(" do advance inc=" + inc);
117 if (docs.skipTo(expected.get(upto))) {
123 if (upto == expected.size()) {
125 System.out.println(" expect docID=" + -1 + " actual=" + docID);
127 assertEquals(-1, docID);
130 System.out.println(" expect docID=" + expected.get(upto) + " actual=" + docID);
132 assertTrue(docID != -1);
133 assertEquals(expected.get(upto).intValue(), docID);