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 2012/03/06 17:02:48 UTC
svn commit: r1297545 - in /lucene/dev/branches/branch_3x:
lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java
solr/ solr/core/
Author: mikemccand
Date: Tue Mar 6 16:02:48 2012
New Revision: 1297545
URL: http://svn.apache.org/viewvc?rev=1297545&view=rev
Log:
backport 1225920 to randomize this test case
Modified:
lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java
lucene/dev/branches/branch_3x/solr/ (props changed)
lucene/dev/branches/branch_3x/solr/core/ (props changed)
Modified: lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java?rev=1297545&r1=1297544&r2=1297545&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java (original)
+++ lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/index/TestTermInfosReaderIndex.java Tue Mar 6 16:02:48 2012
@@ -37,26 +37,38 @@ import org.apache.lucene.store.LockObtai
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
public class TestTermInfosReaderIndex extends LuceneTestCase {
- private static final int NUMBER_OF_DOCUMENTS = 1000;
- private static final int NUMBER_OF_FIELDS = 100;
- private TermInfosReaderIndex index;
- private Directory directory;
- private SegmentTermEnum termEnum;
- private int indexDivisor;
- private int termIndexInterval;
- private int readBufferSize = 1024;
- private IndexReader reader;
- private List<Term> sampleTerms;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ private static int NUMBER_OF_DOCUMENTS;
+ private static int NUMBER_OF_FIELDS;
+ private static TermInfosReaderIndex index;
+ private static Directory directory;
+ private static SegmentTermEnum termEnum;
+ private static int indexDivisor;
+ private static int termIndexInterval;
+ private static IndexReader reader;
+ private static List<Term> sampleTerms;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
+ new MockAnalyzer(random, MockTokenizer.KEYWORD, false));
+
+ termIndexInterval = config.getTermIndexInterval();
indexDivisor = _TestUtil.nextInt(random, 1, 10);
+ NUMBER_OF_DOCUMENTS = atLeast(100);
+ NUMBER_OF_FIELDS = atLeast(Math.max(10, 3*termIndexInterval*indexDivisor/NUMBER_OF_DOCUMENTS));
+
directory = newDirectory();
- termIndexInterval = populate(directory);
+ // turn off compound file, this test will open some index files directly.
+ LogMergePolicy mp = newLogMergePolicy();
+ mp.setUseCompoundFile(false);
+ config.setMergePolicy(mp);
+
+ populate(directory, config);
SegmentReader r = SegmentReader.getOnlySegmentReader(directory);
String segment = r.getSegmentName();
@@ -65,6 +77,7 @@ public class TestTermInfosReaderIndex ex
FieldInfos fieldInfos = new FieldInfos(directory, IndexFileNames.segmentFileName(segment, IndexFileNames.FIELD_INFOS_EXTENSION));
String segmentFileName = IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_INDEX_EXTENSION);
long tiiFileLength = directory.fileLength(segmentFileName);
+ final int readBufferSize = _TestUtil.nextInt(random, 1, 65536);
IndexInput input = directory.openInput(segmentFileName, readBufferSize);
termEnum = new SegmentTermEnum(directory.openInput(IndexFileNames.segmentFileName(segment, IndexFileNames.TERMS_EXTENSION), readBufferSize), fieldInfos, false);
int totalIndexInterval = termEnum.indexInterval * indexDivisor;
@@ -76,15 +89,18 @@ public class TestTermInfosReaderIndex ex
reader = IndexReader.open(directory);
sampleTerms = sample(reader,1000);
-
}
- @Override
- public void tearDown() throws Exception {
+ @AfterClass
+ public static void afterClass() throws Exception {
termEnum.close();
reader.close();
directory.close();
- super.tearDown();
+ termEnum = null;
+ reader = null;
+ directory = null;
+ index = null;
+ sampleTerms = null;
}
public void testSeekEnum() throws CorruptIndexException, IOException {
@@ -117,7 +133,7 @@ public class TestTermInfosReaderIndex ex
searcher.close();
}
- private List<Term> sample(IndexReader reader, int size) throws IOException {
+ private static List<Term> sample(IndexReader reader, int size) throws IOException {
List<Term> sample = new ArrayList<Term>();
Random random = new Random();
TermEnum terms = reader.terms();
@@ -137,21 +153,13 @@ public class TestTermInfosReaderIndex ex
private Term findTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index) throws IOException {
int termPosition = index * termIndexInterval * indexDivisor;
for (int i = 0; i < termPosition; i++) {
- if (!termEnum.next()) {
- fail("Should not have run out of terms.");
- }
+ // TODO: this test just uses random terms, so this is always possible
+ assumeTrue("ran out of terms.", termEnum.next());
}
return termEnum.term();
}
- private int populate(Directory directory) throws CorruptIndexException, LockObtainFailedException, IOException {
- IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT,
- new MockAnalyzer(random, MockTokenizer.KEYWORD, false));
- // turn off compound file, this test will open some index files directly.
- LogMergePolicy mp = newLogMergePolicy();
- mp.setUseCompoundFile(false);
- config.setMergePolicy(mp);
-
+ private static void populate(Directory directory, IndexWriterConfig config) throws CorruptIndexException, LockObtainFailedException, IOException {
RandomIndexWriter writer = new RandomIndexWriter(random, directory, config);
for (int i = 0; i < NUMBER_OF_DOCUMENTS; i++) {
Document document = new Document();
@@ -162,10 +170,9 @@ public class TestTermInfosReaderIndex ex
}
writer.forceMerge(1);
writer.close();
- return config.getTermIndexInterval();
}
- private String getText() {
+ private static String getText() {
return Long.toString(random.nextLong(),Character.MAX_RADIX);
}
}