LUCENE-2639: remove random juggling in tests, add -Dtests.seed

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@995772 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-09-10 12:34:18 +00:00
parent aa3e1599e9
commit d38ec19a28
213 changed files with 1253 additions and 1870 deletions

View File

@ -68,6 +68,7 @@
<property name="tests.timezone" value="random" />
<property name="tests.directory" value="random" />
<property name="tests.iter" value="1" />
<property name="tests.seed" value="random" />
<property name="javac.deprecation" value="off"/>
<property name="javac.debug" value="on"/>
@ -450,6 +451,8 @@
<sysproperty key="tests.directory" value="${tests.directory}"/>
<!-- set the number of times tests should run -->
<sysproperty key="tests.iter" value="${tests.iter}"/>
<!-- set the test seed -->
<sysproperty key="tests.seed" value="${tests.seed}"/>
<!-- TODO: create propertyset for test properties, so each project can have its own set -->
<sysproperty key="tests.multiplier" value="${tests.multiplier}"/>

View File

@ -115,7 +115,7 @@ public class JEStoreTest extends LuceneTestCase {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random r = newRandom();
Random r = random;
final long seed = r.nextLong();
Random gen = new Random(seed);
int totalLength = 0;
@ -261,7 +261,7 @@ public class JEStoreTest extends LuceneTestCase {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random r = newRandom();
Random r = random;
final long seed = r.nextLong();
Random gen = new Random(seed);
int totalLength = 0;
@ -493,7 +493,7 @@ public class JEStoreTest extends LuceneTestCase {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random r = newRandom();
Random r = random;
final long seed = r.nextLong();
Random gen = new Random(seed);
int totalLength = 0;

View File

@ -116,7 +116,7 @@ public class DbStoreTest extends LuceneTestCase {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random r = newRandom();
Random r = random;
final long seed = r.nextLong();
Random gen = new Random(seed);
@ -267,7 +267,7 @@ public class DbStoreTest extends LuceneTestCase {
final int count = 250;
final int LENGTH_MASK = 0xffff;
Random r = newRandom();
Random r = random;
final long seed = r.nextLong();
Random gen = new Random(seed);

View File

@ -18,7 +18,6 @@ package org.apache.lucene.search.highlight;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@ -53,13 +52,12 @@ import org.apache.lucene.util.OpenBitSet;
public class HighlighterPhraseTest extends LuceneTestCase {
private static final String FIELD = "text";
private Random random = newRandom();
public void testConcurrentPhrase() throws CorruptIndexException,
LockObtainFailedException, IOException, InvalidTokenOffsetsException {
final String TEXT = "the fox jumped";
final Directory directory = newDirectory(random);
final Directory directory = newDirectory();
final IndexWriter indexWriter = new IndexWriter(directory,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
try {
final Document document = new Document();
document.add(new Field(FIELD, new TokenStreamConcurrent(),
@ -101,9 +99,9 @@ public class HighlighterPhraseTest extends LuceneTestCase {
public void testConcurrentSpan() throws CorruptIndexException,
LockObtainFailedException, IOException, InvalidTokenOffsetsException {
final String TEXT = "the fox jumped";
final Directory directory = newDirectory(random);
final Directory directory = newDirectory();
final IndexWriter indexWriter = new IndexWriter(directory,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
try {
final Document document = new Document();
document.add(new Field(FIELD, new TokenStreamConcurrent(),
@ -171,9 +169,9 @@ public class HighlighterPhraseTest extends LuceneTestCase {
public void testSparsePhrase() throws CorruptIndexException,
LockObtainFailedException, IOException, InvalidTokenOffsetsException {
final String TEXT = "the fox did not jump";
final Directory directory = newDirectory(random);
final Directory directory = newDirectory();
final IndexWriter indexWriter = new IndexWriter(directory,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
try {
final Document document = new Document();
document.add(new Field(FIELD, new TokenStreamSparse(),
@ -214,9 +212,9 @@ public class HighlighterPhraseTest extends LuceneTestCase {
public void testSparsePhraseWithNoPositions() throws CorruptIndexException,
LockObtainFailedException, IOException, InvalidTokenOffsetsException {
final String TEXT = "the fox did not jump";
final Directory directory = newDirectory(random);
final Directory directory = newDirectory();
final IndexWriter indexWriter = new IndexWriter(directory,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
try {
final Document document = new Document();
document.add(new Field(FIELD, TEXT, Store.YES, Index.ANALYZED,
@ -255,9 +253,9 @@ public class HighlighterPhraseTest extends LuceneTestCase {
public void testSparseSpan() throws CorruptIndexException,
LockObtainFailedException, IOException, InvalidTokenOffsetsException {
final String TEXT = "the fox did not jump";
final Directory directory = newDirectory(random);
final Directory directory = newDirectory();
final IndexWriter indexWriter = new IndexWriter(directory,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
try {
final Document document = new Document();
document.add(new Field(FIELD, new TokenStreamSparse(),

View File

@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
@ -99,7 +98,6 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
int numHighlights = 0;
final Analyzer analyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
TopDocs hits;
private Random random;
String[] texts = {
"Hello this is a piece of text that is very long and contains too much preamble and the meat is really here which says kennedy has been shot",
@ -1322,8 +1320,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
public void testMultiSearcher() throws Exception {
// setup index 1
Directory ramDir1 = newDirectory(random);
IndexWriter writer1 = new IndexWriter(ramDir1, newIndexWriterConfig(random,
Directory ramDir1 = newDirectory();
IndexWriter writer1 = new IndexWriter(ramDir1, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));
Document d = new Document();
Field f = new Field(FIELD_NAME, "multiOne", Field.Store.YES, Field.Index.ANALYZED);
@ -1334,8 +1332,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
IndexReader reader1 = IndexReader.open(ramDir1, true);
// setup index 2
Directory ramDir2 = newDirectory(random);
IndexWriter writer2 = new IndexWriter(ramDir2, newIndexWriterConfig(random,
Directory ramDir2 = newDirectory();
IndexWriter writer2 = new IndexWriter(ramDir2, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));
d = new Document();
f = new Field(FIELD_NAME, "multiTwo", Field.Store.YES, Field.Index.ANALYZED);
@ -1723,10 +1721,9 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
ramDir = newDirectory(random);
IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(random,
dir = newDirectory();
ramDir = newDirectory();
IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));
for (int i = 0; i < texts.length; i++) {
addDoc(writer, texts[i]);

View File

@ -92,7 +92,7 @@ public abstract class AbstractTestCase extends LuceneTestCase {
analyzerK = new MockAnalyzer(MockTokenizer.KEYWORD, false);
paW = new QueryParser(TEST_VERSION_CURRENT, F, analyzerW );
paB = new QueryParser(TEST_VERSION_CURRENT, F, analyzerB );
dir = newDirectory(newRandom());
dir = newDirectory();
}
@Override

View File

@ -59,9 +59,8 @@ public class TestEmptyIndex extends LuceneTestCase {
ii.close();
// make sure a Directory acts the same
Random random = newRandom();
Directory d = newDirectory(random);
new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())).close();
Directory d = newDirectory();
new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())).close();
r = IndexReader.open(d, false);
testNorms(r);
r.close();
@ -92,9 +91,8 @@ public class TestEmptyIndex extends LuceneTestCase {
ii.close();
// make sure a Directory acts the same
Random random = newRandom();
Directory d = newDirectory(random);
new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())).close();
Directory d = newDirectory();
new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())).close();
r = IndexReader.open(d, false);
termsEnumTest(r);
r.close();

View File

@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
@ -61,11 +60,10 @@ public class TestIndicesEquals extends LuceneTestCase {
public void testLoadIndexReader() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// create dir data
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 20; i++) {
Document document = new Document();
@ -86,12 +84,11 @@ public class TestIndicesEquals extends LuceneTestCase {
public void testInstantiatedIndexWriter() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
InstantiatedIndex ii = new InstantiatedIndex();
// create dir data
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 500; i++) {
Document document = new Document();

View File

@ -27,15 +27,13 @@ import org.apache.lucene.document.Field;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Random;
public class TestSerialization extends LuceneTestCase {
public void test() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("foo", "bar rab abr bra rba", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
doc.add(new Field("moo", "bar rab abr bra rba", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));

View File

@ -16,7 +16,6 @@ package org.apache.lucene.store.instantiated;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
@ -34,8 +33,7 @@ import org.apache.lucene.document.Field;
public class TestUnoptimizedReaderOnConstructor extends LuceneTestCase {
public void test() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocument(iw, "Hello, world!");
addDocument(iw, "All work and no play makes jack a dull boy");

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import org.apache.lucene.analysis.Analyzer;
@ -46,7 +45,6 @@ import org.apache.lucene.util._TestUtil;
*/
public class MemoryIndexTest extends BaseTokenStreamTestCase {
private Set<String> queries = new HashSet<String>();
private Random random;
public static final int ITERATIONS = 100 * RANDOM_MULTIPLIER;
@ -55,7 +53,6 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {
super.setUp();
queries.addAll(readQueries("testqueries.txt"));
queries.addAll(readQueries("testqueries2.txt"));
random = newRandom();
}
/**
@ -106,7 +103,7 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {
termField.append(randomTerm());
}
Directory ramdir = newDirectory(random);
Directory ramdir = newDirectory();
Analyzer analyzer = randomAnalyzer();
IndexWriter writer = new IndexWriter(ramdir,
new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setCodecProvider(_TestUtil.alwaysCodec("Standard")));

View File

@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -57,9 +56,8 @@ public class TestFieldNormModifier extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
store = newDirectory(random);
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random,
store = newDirectory();
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < NUM_DOCS; i++) {

View File

@ -16,8 +16,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -28,15 +26,13 @@ import org.apache.lucene.util.BytesRef;
public class TestMultiPassIndexSplitter extends LuceneTestCase {
IndexReader input;
int NUM_DOCS = 11;
private Random random;
Directory dir;
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc;
for (int i = 0; i < NUM_DOCS; i++) {
doc = new Document();
@ -66,9 +62,9 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {
public void testSplitRR() throws Exception {
MultiPassIndexSplitter splitter = new MultiPassIndexSplitter();
Directory[] dirs = new Directory[]{
newDirectory(random),
newDirectory(random),
newDirectory(random)
newDirectory(),
newDirectory(),
newDirectory()
};
splitter.split(input, dirs, false);
IndexReader ir;
@ -111,9 +107,9 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {
public void testSplitSeq() throws Exception {
MultiPassIndexSplitter splitter = new MultiPassIndexSplitter();
Directory[] dirs = new Directory[]{
newDirectory(random),
newDirectory(random),
newDirectory(random)
newDirectory(),
newDirectory(),
newDirectory()
};
splitter.split(input, dirs, true);
IndexReader ir;

View File

@ -6,7 +6,6 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import java.util.Random;
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,9 +24,8 @@ import java.util.Random;
public class TestTermVectorAccessor extends LuceneTestCase {
public void test() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc;

View File

@ -17,8 +17,6 @@ package org.apache.lucene.misc;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.util.BytesRef;
@ -37,9 +35,8 @@ public class TestHighFreqTerms extends LuceneTestCase {
public void setUp() throws Exception {
super.setUp();
Random random = newRandom();
dir= newDirectory(random);
writer = new IndexWriter(dir, newIndexWriterConfig(random,
dir= newDirectory();
writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false))
.setMaxBufferedDocs(2));
indexDocs(writer);

View File

@ -18,7 +18,6 @@ package org.apache.lucene.misc;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -26,7 +25,6 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.index.FieldNormModifier;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.DefaultSimilarity;
@ -61,9 +59,8 @@ public class TestLengthNormModifier extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
store = newDirectory(random);
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random,
store = newDirectory();
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < NUM_DOCS; i++) {

View File

@ -18,7 +18,6 @@ package org.apache.lucene.search;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@ -39,8 +38,7 @@ public class BooleanFilterTest extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory, new MockAnalyzer(MockTokenizer.WHITESPACE, false));
//Add series of docs with filterable fields : acces rights, prices, dates and "in-stock" flags

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -53,13 +52,10 @@ public class ChainedFilterTest extends LuceneTestCase {
private QueryWrapperFilter bobFilter;
private QueryWrapperFilter sueFilter;
private Random random;
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory);
Calendar cal = new GregorianCalendar();
cal.clear();
@ -194,7 +190,7 @@ public class ChainedFilterTest extends LuceneTestCase {
*/
public void testWithCachingFilter() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
IndexReader reader = writer.getReader();
writer.close();

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -42,8 +41,7 @@ public class DuplicateFilterTest extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory);
//Add series of docs with filterable fields : url, text and dates flags

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
@ -40,8 +39,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory);
//Add series of docs with misspelt names

View File

@ -52,8 +52,7 @@ public class TermsFilterTest extends LuceneTestCase {
public void testMissingTerms() throws Exception {
String fieldName="field1";
Random random = newRandom();
Directory rd=newDirectory(random);
Directory rd=newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random, rd);
for (int i = 0; i < 100; i++) {
Document doc=new Document();

View File

@ -17,8 +17,6 @@ package org.apache.lucene.search.regex;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.store.Directory;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
@ -42,8 +40,7 @@ public class TestRegexQuery extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory);
Document doc = new Document();
doc.add(new Field(FN, "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.ANALYZED));

View File

@ -18,14 +18,12 @@ package org.apache.lucene.search.regex;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.IndexSearcher;
@ -41,14 +39,12 @@ public class TestSpanRegexQuery extends LuceneTestCase {
Directory indexStoreA;
Directory indexStoreB;
Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
indexStoreA = newDirectory(random);
indexStoreB = newDirectory(random);
indexStoreA = newDirectory();
indexStoreB = newDirectory();
}
@Override
@ -59,8 +55,8 @@ public class TestSpanRegexQuery extends LuceneTestCase {
}
public void testSpanRegex() throws Exception {
Directory directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
// doc.add(new Field("field", "the quick brown fox jumps over the lazy dog",
@ -128,14 +124,14 @@ public class TestSpanRegexQuery extends LuceneTestCase {
Field.Index.ANALYZED_NO_NORMS));
// creating first index writer
IndexWriter writerA = new IndexWriter(indexStoreA, newIndexWriterConfig(random,
IndexWriter writerA = new IndexWriter(indexStoreA, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writerA.addDocument(lDoc);
writerA.optimize();
writerA.close();
// creating second index writer
IndexWriter writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(random,
IndexWriter writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writerB.addDocument(lDoc2);
writerB.optimize();

View File

@ -22,7 +22,6 @@ import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@ -45,8 +44,7 @@ public class TestMoreLikeThis extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory);
// Add series of docs with specific information for MoreLikeThis

View File

@ -18,7 +18,6 @@ package org.apache.lucene.queryParser.complexPhrase;
*/
import java.util.HashSet;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
@ -112,9 +111,8 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
rd = newDirectory(random);
IndexWriter w = new IndexWriter(rd, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
rd = newDirectory();
IndexWriter w = new IndexWriter(rd, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
for (int i = 0; i < docsContent.length; i++) {
Document doc = new Document();
doc.add(new Field("name", docsContent[i].name, Field.Store.YES,

View File

@ -20,7 +20,6 @@ package org.apache.lucene.queryParser.standard;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
@ -318,9 +317,8 @@ public class TestMultiFieldQPHelper extends LuceneTestCase {
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer();
Random random = newRandom();
Directory ramDir = newDirectory(random);
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(new Field("body", "blah the footest blah", Field.Store.NO,
Field.Index.ANALYZED));

View File

@ -320,7 +320,7 @@ public class TestMultiFieldQueryParserWrapper extends LuceneTestCase {
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer();
Directory ramDir = newDirectory(newRandom());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, analyzer, true,
IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();

View File

@ -30,7 +30,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
@ -654,9 +653,8 @@ public class TestQPHelper extends LocalizedTestCase {
}
public void testFarsiRangeCollating() throws Exception {
Random random = newRandom();
Directory ramDir = newDirectory(random);
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
Document doc = new Document();
doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES,
Field.Index.NOT_ANALYZED));
@ -1078,9 +1076,8 @@ public class TestQPHelper extends LocalizedTestCase {
}
public void testLocalDateFormat() throws IOException, QueryNodeException {
Random random = newRandom();
Directory ramDir = newDirectory(random);
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
addDateDoc("a", 2005, 12, 2, 10, 15, 33, iw);
addDateDoc("b", 2005, 12, 4, 22, 15, 00, iw);
iw.close();
@ -1306,9 +1303,8 @@ public class TestQPHelper extends LocalizedTestCase {
}
public void testMultiPhraseQuery() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new CannedAnalyzer()));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new CannedAnalyzer()));
Document doc = new Document();
doc.add(new Field("field", "", Field.Store.NO, Field.Index.ANALYZED));
w.addDocument(doc);

View File

@ -654,7 +654,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {
public void testFarsiRangeCollating() throws Exception {
Directory ramDir = newDirectory(newRandom());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), true,
IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
@ -1063,7 +1063,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {
public void testLocalDateFormat() throws IOException, ParseException {
Directory ramDir = newDirectory(newRandom());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), true,
IndexWriter.MaxFieldLength.LIMITED);
addDateDoc("a", 2005, 12, 2, 10, 15, 33, iw);

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -70,10 +69,9 @@ public class TestCartesian extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
setUpPlotter( 2, 15);

View File

@ -17,7 +17,6 @@
package org.apache.lucene.spatial.tier;
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -44,9 +43,8 @@ public class TestDistance extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
directory = newDirectory(random);
writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
directory = newDirectory();
writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addData(writer);
}

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search.spell;
import java.io.IOException;
import java.util.Iterator;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@ -40,16 +39,14 @@ public class TestLuceneDictionary extends LuceneTestCase {
private Directory store;
private IndexReader indexReader = null;
private Random random;
private LuceneDictionary ld;
private Iterator<String> it;
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
store = newDirectory(random);
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
store = newDirectory();
IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
Document doc;
@ -195,7 +192,7 @@ public class TestLuceneDictionary extends LuceneTestCase {
}
public void testSpellchecker() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SpellChecker sc = new SpellChecker(dir);
indexReader = IndexReader.open(store, true);
sc.indexDictionary(new LuceneDictionary(indexReader, "contents"));

View File

@ -33,7 +33,7 @@ public class TestPlainTextDictionary extends LuceneTestCase {
final String LF = System.getProperty("line.separator");
String input = "oneword" + LF + "twoword" + LF + "threeword";
PlainTextDictionary ptd = new PlainTextDictionary(new StringReader(input));
Directory ramDir = newDirectory(newRandom());
Directory ramDir = newDirectory();
SpellChecker spellChecker = new SpellChecker(ramDir);
spellChecker.indexDictionary(ptd);
String[] similar = spellChecker.suggestSimilar("treeword", 2);

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -46,7 +45,6 @@ import org.apache.lucene.util.LuceneTestCase;
public class TestSpellChecker extends LuceneTestCase {
private SpellCheckerMock spellChecker;
private Directory userindex, spellindex;
private final Random random = newRandom();
private List<IndexSearcher> searchers;
@Override
@ -54,7 +52,7 @@ public class TestSpellChecker extends LuceneTestCase {
super.setUp();
//create a user index
userindex = newDirectory(random);
userindex = newDirectory();
IndexWriter writer = new IndexWriter(userindex, new IndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
@ -68,7 +66,7 @@ public class TestSpellChecker extends LuceneTestCase {
writer.close();
searchers = Collections.synchronizedList(new ArrayList<IndexSearcher>());
// create the spellChecker
spellindex = newDirectory(random);
spellindex = newDirectory();
spellChecker = new SpellCheckerMock(spellindex);
}
@ -124,7 +122,7 @@ public class TestSpellChecker extends LuceneTestCase {
public void testComparator() throws Exception {
IndexReader r = IndexReader.open(userindex, true);
Directory compIdx = newDirectory(random);
Directory compIdx = newDirectory();
SpellChecker compareSP = new SpellCheckerMock(compIdx, new LevensteinDistance(), new SuggestWordFrequencyComparator());
addwords(r, compareSP, "field3");

View File

@ -4,7 +4,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
@ -57,10 +56,9 @@ public class TestParser extends LuceneTestCase {
//initialize the parser
builder=new CorePlusExtensionsParser("contents",analyzer);
Random random = newRandom();
BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt")));
dir=newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, Version.LUCENE_24, analyzer));
dir=newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(Version.LUCENE_24, analyzer));
String line = d.readLine();
while(line!=null)
{

View File

@ -2,7 +2,6 @@ package org.apache.lucene.xmlparser;
import java.io.IOException;
import java.util.Properties;
import java.util.Random;
import java.util.StringTokenizer;
import javax.xml.parsers.ParserConfigurationException;
@ -142,9 +141,8 @@ public class TestQueryTemplateManager extends LuceneTestCase {
//Create an index
Random random = newRandom();
dir=newDirectory(random);
IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
dir=newDirectory();
IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
for (int i = 0; i < docFieldValues.length; i++)
{
w.addDocument(getDocumentFromString(docFieldValues[i]));

View File

@ -20,7 +20,6 @@ package org.apache.lucene.xmlparser.builders;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -61,9 +60,8 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {
String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
Document doc = getDocumentFromString(xml);
Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
Random random = newRandom();
Directory ramDir = newDirectory(random);
IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, null));
Directory ramDir = newDirectory();
IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
writer.commit();
try
{

View File

@ -33,7 +33,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
/**
@ -49,7 +48,7 @@ public class TestDemo extends LuceneTestCase {
Analyzer analyzer = new MockAnalyzer();
// Store the index in memory:
Directory directory = newDirectory(newRandom());
Directory directory = newDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.open("/tmp/testindex");
IndexWriter iwriter = new IndexWriter(directory, new IndexWriterConfig(

View File

@ -600,10 +600,9 @@ public class TestExternalCodecs extends LuceneTestCase {
public void testPerFieldCodec() throws Exception {
final int NUM_DOCS = 173;
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir,
newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(new MyCodecs()));
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(new MyCodecs()));
w.setMergeFactor(3);
Document doc = new Document();

View File

@ -17,7 +17,6 @@ package org.apache.lucene;
* limitations under the License.
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.store.MockDirectoryWrapper;
@ -83,15 +82,14 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
}
public void testSubclassConcurrentMergeScheduler() throws IOException {
Random random = newRandom();
MockDirectoryWrapper dir = newDirectory(random);
MockDirectoryWrapper dir = newDirectory();
dir.failOn(new FailOnlyOnMerge());
Document doc = new Document();
Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
doc.add(idField);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new MyMergeScheduler())
.setMaxBufferedDocs(2).setRAMBufferSizeMB(
IndexWriterConfig.DISABLE_AUTO_FLUSH));

View File

@ -51,7 +51,6 @@ public class TestSearch extends LuceneTestCase {
* single-file formats, even if the results are wrong.
*/
public void testSearch() throws Exception {
Random random = newRandom();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
doTestSearch(random, pw, false);
@ -73,9 +72,9 @@ public class TestSearch extends LuceneTestCase {
private void doTestSearch(Random random, PrintWriter out, boolean useCompoundFile)
throws Exception {
Directory directory = newDirectory(random);
Directory directory = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer);
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
lmp.setUseCompoundFile(useCompoundFile);
lmp.setUseCompoundDocStore(useCompoundFile);

View File

@ -59,7 +59,6 @@ public class TestSearchForDuplicates extends LuceneTestCase {
public void testRun() throws Exception {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
Random random = newRandom();
doTest(random, pw, false);
pw.close();
sw.close();
@ -78,9 +77,9 @@ public class TestSearchForDuplicates extends LuceneTestCase {
private void doTest(Random random, PrintWriter out, boolean useCompoundFiles) throws Exception {
Directory directory = newDirectory(random);
Directory directory = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer);
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
lmp.setUseCompoundFile(useCompoundFiles);
lmp.setUseCompoundDocStore(useCompoundFiles);

View File

@ -19,7 +19,6 @@ package org.apache.lucene.analysis;
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@ -37,8 +36,7 @@ public class TestCachingTokenFilter extends BaseTokenStreamTestCase {
private String[] tokens = new String[] {"term1", "term2", "term3", "term2"};
public void testCaching() throws IOException {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
Document doc = new Document();
TokenStream stream = new TokenStream() {

View File

@ -20,10 +20,8 @@ package org.apache.lucene.analysis;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Random;
import org.apache.lucene.util.Version;
import org.apache.lucene.util._TestUtil;
/**
* Testcase for {@link CharTokenizer} subclasses
@ -36,9 +34,8 @@ public class TestCharTokenizers extends BaseTokenStreamTestCase {
*/
public void testReadSupplementaryChars() throws IOException {
StringBuilder builder = new StringBuilder();
Random newRandom = newRandom();
// create random input
int num = 1024 + newRandom.nextInt(1024);
int num = 1024 + random.nextInt(1024);
num *= RANDOM_MULTIPLIER;
for (int i = 1; i < num; i++) {
builder.append("\ud801\udc1cabc");

View File

@ -1,7 +1,5 @@
package org.apache.lucene.document;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.index.IndexReader;
@ -57,8 +55,7 @@ public class TestBinaryDocument extends LuceneTestCase {
assertEquals(2, doc.fields.size());
/** add the doc to a ram index */
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
writer.addDocument(doc);
@ -97,8 +94,7 @@ public class TestBinaryDocument extends LuceneTestCase {
doc.add(stringFldCompressed);
/** add the doc to a ram index */
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
writer.addDocument(doc);

View File

@ -1,7 +1,5 @@
package org.apache.lucene.document;
import java.util.Random;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
@ -154,8 +152,7 @@ public class TestDocument extends LuceneTestCase {
* @throws Exception on error
*/
public void testGetValuesForIndexedDocument() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
writer.addDocument(makeDocumentWithFields());
IndexReader reader = writer.getReader();
@ -233,8 +230,7 @@ public class TestDocument extends LuceneTestCase {
doc.add(new Field("keyword", "test", Field.Store.YES,
Field.Index.NOT_ANALYZED));
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, dir);
writer.addDocument(doc);
field.setValue("id2");

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.analysis.MockAnalyzer;
@ -34,24 +33,17 @@ import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.PhraseQuery;
public class TestAddIndexes extends LuceneTestCase {
private Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
public void testSimpleCase() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// two auxiliary directories
Directory aux = newDirectory(random);
Directory aux2 = newDirectory(random);
Directory aux = newDirectory();
Directory aux2 = newDirectory();
IndexWriter writer = null;
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.CREATE));
// add 100 documents
@ -60,7 +52,7 @@ public class TestAddIndexes extends LuceneTestCase {
writer.close();
_TestUtil.checkIndex(dir);
writer = newWriter(aux, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writer = newWriter(aux, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
// add 40 documents in separate files
@ -68,14 +60,14 @@ public class TestAddIndexes extends LuceneTestCase {
assertEquals(40, writer.maxDoc());
writer.close();
writer = newWriter(aux2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writer = newWriter(aux2, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
// add 40 documents in compound files
addDocs2(writer, 50);
assertEquals(50, writer.maxDoc());
writer.close();
// test doc count before segments are merged
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
assertEquals(100, writer.maxDoc());
writer.addIndexes(new Directory[] { aux, aux2 });
assertEquals(190, writer.maxDoc());
@ -89,15 +81,15 @@ public class TestAddIndexes extends LuceneTestCase {
verifyNumDocs(dir, 190);
// now add another set in.
Directory aux3 = newDirectory(random);
writer = newWriter(aux3, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory aux3 = newDirectory();
writer = newWriter(aux3, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
// add 40 documents
addDocs(writer, 40);
assertEquals(40, writer.maxDoc());
writer.close();
// test doc count before segments are merged/index is optimized
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
assertEquals(190, writer.maxDoc());
writer.addIndexes(new Directory[] { aux3 });
assertEquals(230, writer.maxDoc());
@ -111,7 +103,7 @@ public class TestAddIndexes extends LuceneTestCase {
verifyTermDocs(dir, new Term("content", "bbb"), 50);
// now optimize it.
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@ -123,12 +115,12 @@ public class TestAddIndexes extends LuceneTestCase {
verifyTermDocs(dir, new Term("content", "bbb"), 50);
// now add a single document
Directory aux4 = newDirectory(random);
writer = newWriter(aux4, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory aux4 = newDirectory();
writer = newWriter(aux4, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocs2(writer, 1);
writer.close();
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
assertEquals(230, writer.maxDoc());
writer.addIndexes(new Directory[] { aux4 });
assertEquals(231, writer.maxDoc());
@ -146,12 +138,12 @@ public class TestAddIndexes extends LuceneTestCase {
public void testWithPendingDeletes() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexWriter writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.addIndexes(new Directory[] {aux});
// Adds 10 docs, then replaces them with another 10
@ -183,12 +175,12 @@ public class TestAddIndexes extends LuceneTestCase {
public void testWithPendingDeletes2() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexWriter writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
// Adds 10 docs, then replaces them with another 10
// docs, so 10 pending deletes:
@ -221,12 +213,12 @@ public class TestAddIndexes extends LuceneTestCase {
public void testWithPendingDeletes3() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexWriter writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
// Adds 10 docs, then replaces them with another 10
// docs, so 10 pending deletes:
@ -261,31 +253,31 @@ public class TestAddIndexes extends LuceneTestCase {
// case 0: add self or exceed maxMergeDocs, expect exception
public void testAddSelf() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
IndexWriter writer = null;
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
// add 100 documents
addDocs(writer, 100);
assertEquals(100, writer.maxDoc());
writer.close();
writer = newWriter(aux, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
writer = newWriter(aux, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
// add 140 documents in separate files
addDocs(writer, 40);
writer.close();
writer = newWriter(aux, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
writer = newWriter(aux, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
addDocs(writer, 100);
writer.close();
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
try {
// cannot add self
writer.addIndexes(new Directory[] { aux, dir });
@ -307,13 +299,13 @@ public class TestAddIndexes extends LuceneTestCase {
// case 1: no tail segments
public void testNoTailSegments() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = newWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
@ -333,13 +325,13 @@ public class TestAddIndexes extends LuceneTestCase {
// case 2: tail segments, invariants hold, no copy
public void testNoCopySegments() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(9));
IndexWriter writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(9));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
addDocs(writer, 2);
@ -357,13 +349,13 @@ public class TestAddIndexes extends LuceneTestCase {
// case 3: tail segments, invariants hold, copy, invariants hold
public void testNoMergeAfterCopy() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = newWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
@ -382,9 +374,9 @@ public class TestAddIndexes extends LuceneTestCase {
// case 4: tail segments, invariants hold, copy, invariants not hold
public void testMergeAfterCopy() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux = newDirectory();
setUpDirs(dir, aux);
@ -395,7 +387,7 @@ public class TestAddIndexes extends LuceneTestCase {
assertEquals(10, reader.numDocs());
reader.close();
IndexWriter writer = newWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = newWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(4));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
@ -411,14 +403,14 @@ public class TestAddIndexes extends LuceneTestCase {
// case 5: tail segments, invariants not hold
public void testMoreMerges() throws IOException {
// main directory
Directory dir = newDirectory(random);
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory(random);
Directory aux2 = newDirectory(random);
Directory aux = newDirectory();
Directory aux2 = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(aux2, newIndexWriterConfig(random,
IndexWriter writer = newWriter(aux2, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
@ -441,7 +433,7 @@ public class TestAddIndexes extends LuceneTestCase {
assertEquals(22, reader.numDocs());
reader.close();
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(6));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(4);
@ -500,14 +492,14 @@ public class TestAddIndexes extends LuceneTestCase {
private void setUpDirs(Directory dir, Directory aux) throws IOException {
IndexWriter writer = null;
writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
writer = newWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(1000));
// add 1000 documents in 1 segment
addDocs(writer, 1000);
assertEquals(1000, writer.maxDoc());
assertEquals(1, writer.getSegmentCount());
writer.close();
writer = newWriter(aux, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
writer = newWriter(aux, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(100));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
@ -515,7 +507,7 @@ public class TestAddIndexes extends LuceneTestCase {
for (int i = 0; i < 3; i++) {
addDocs(writer, 10);
writer.close();
writer = newWriter(aux, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(100));
writer = newWriter(aux, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(100));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false); // use one without a compound file
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
@ -528,12 +520,12 @@ public class TestAddIndexes extends LuceneTestCase {
// LUCENE-1270
public void testHangOnClose() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();
lmp.setUseCompoundFile(false);
lmp.setUseCompoundDocStore(false);
lmp.setMergeFactor(100);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(5).setMergePolicy(lmp));
@ -556,13 +548,13 @@ public class TestAddIndexes extends LuceneTestCase {
writer.addDocument(doc2);
writer.close();
Directory dir2 = newDirectory(random);
Directory dir2 = newDirectory();
lmp = new LogByteSizeMergePolicy();
lmp.setMinMergeMB(0.0001);
lmp.setUseCompoundFile(false);
lmp.setUseCompoundDocStore(false);
lmp.setMergeFactor(4);
writer = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir2, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setMergeScheduler(new SerialMergeScheduler()).setMergePolicy(lmp));
writer.addIndexes(new Directory[] {dir});

View File

@ -185,7 +185,7 @@ public class TestAtomicUpdate extends LuceneTestCase {
FSDirectory.
*/
public void testAtomicUpdates() throws Exception {
MockIndexWriter.RANDOM = newRandom();
MockIndexWriter.RANDOM = random;
Directory directory;
// First in a RAM directory:

View File

@ -148,7 +148,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
/** This test checks that *only* IndexFormatTooOldExceptions are throws when you open and operate on too old indexes! */
public void testUnsupportedOldIndexes() throws Exception {
final Random rnd = newRandom();
for(int i=0;i<unsupportedNames.length;i++) {
unzip(getDataFile("unsupported." + unsupportedNames[i] + ".zip"), unsupportedNames[i]);
@ -168,12 +167,12 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
try {
writer = new IndexWriter(dir, newIndexWriterConfig(rnd,
writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMergeScheduler(new SerialMergeScheduler()) // no threads!
);
// TODO: Make IndexWriter fail on open!
if (rnd.nextBoolean()) {
if (random.nextBoolean()) {
writer.optimize();
} else {
reader = writer.getReader();
@ -220,14 +219,13 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
public void testAddOldIndexes() throws IOException {
Random random = newRandom();
for (String name : oldNames) {
unzip(getDataFile("index." + name + ".zip"), name);
String fullPath = fullDir(name);
Directory dir = FSDirectory.open(new File(fullPath));
Directory targetDir = newDirectory(random);
IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(random,
Directory targetDir = newDirectory();
IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
w.addIndexes(new Directory[] { dir });
w.close();
@ -241,15 +239,14 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
public void testAddOldIndexesReader() throws IOException {
Random random = newRandom();
for (String name : oldNames) {
unzip(getDataFile("index." + name + ".zip"), name);
String fullPath = fullDir(name);
Directory dir = FSDirectory.open(new File(fullPath));
IndexReader reader = IndexReader.open(dir);
Directory targetDir = newDirectory(random);
IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(random,
Directory targetDir = newDirectory();
IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
w.addIndexes(new IndexReader[] { reader });
w.close();
@ -272,7 +269,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
public void testIndexOldIndexNoAdds() throws IOException {
Random random = newRandom();
for(int i=0;i<oldNames.length;i++) {
unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
changeIndexNoAdds(random, oldNames[i]);
@ -281,7 +277,6 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
public void testIndexOldIndex() throws IOException {
Random random = newRandom();
for(int i=0;i<oldNames.length;i++) {
unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
changeIndexWithAdds(random, oldNames[i]);
@ -371,7 +366,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
Directory dir = FSDirectory.open(new File(dirName));
// open writer
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
// add 10 docs
for(int i=0;i<10;i++) {
addDoc(writer, 35+i);
@ -415,7 +410,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
searcher.close();
// optimize
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@ -462,7 +457,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
searcher.close();
// optimize
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@ -484,7 +479,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
dirName = fullDir(dirName);
Directory dir = FSDirectory.open(new File(dirName));
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10);
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(doCFS);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(doCFS);
IndexWriter writer = new IndexWriter(dir, conf);
@ -496,7 +491,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
writer.close();
// open fresh writer so we get no prx file in the added segment
conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10);
conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(doCFS);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(doCFS);
writer = new IndexWriter(dir, conf);
@ -524,7 +519,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
try {
Directory dir = FSDirectory.open(new File(fullDir(outputDir)));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(-1).setRAMBufferSizeMB(16.0));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(-1).setRAMBufferSizeMB(16.0));
((LogMergePolicy) writer.getMergePolicy()).setUseCompoundFile(true);
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
for(int i=0;i<35;i++) {

View File

@ -14,7 +14,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.util.LuceneTestCase;
@ -62,8 +61,6 @@ public class TestByteSlices extends LuceneTestCase {
int[] uptos = new int[NUM_STREAM];
int[] counters = new int[NUM_STREAM];
Random r = newRandom();
ByteSliceReader reader = new ByteSliceReader();
for(int ti=0;ti<100;ti++) {
@ -75,7 +72,7 @@ public class TestByteSlices extends LuceneTestCase {
int num = 10000 * RANDOM_MULTIPLIER;
for (int iter = 0; iter < num; iter++) {
int stream = r.nextInt(NUM_STREAM);
int stream = random.nextInt(NUM_STREAM);
if (VERBOSE)
System.out.println("write stream=" + stream);
@ -87,12 +84,12 @@ public class TestByteSlices extends LuceneTestCase {
}
writer.init(uptos[stream]);
int numValue = r.nextInt(20);
int numValue = random.nextInt(20);
for(int j=0;j<numValue;j++) {
if (VERBOSE)
System.out.println(" write " + (counters[stream]+j));
// write some large (incl. negative) ints:
writer.writeVInt(r.nextInt());
writer.writeVInt(random.nextInt());
writer.writeVInt(counters[stream]+j);
}
counters[stream] += numValue;

View File

@ -22,7 +22,6 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.store.Directory;
@ -34,9 +33,8 @@ import org.apache.lucene.util.Constants;
public class TestCheckIndex extends LuceneTestCase {
public void testDeletedDocs() throws IOException {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
Document doc = new Document();
doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
for(int i=0;i<19;i++) {

View File

@ -20,7 +20,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -62,8 +61,6 @@ import org.apache.lucene.util.Version;
// - skipTo(doc)
public class TestCodecs extends MultiCodecTestCase {
private Random RANDOM;
private static String[] fieldNames = new String[] {"one", "two", "three", "four"};
private final static int NUM_TEST_ITER = 20 * RANDOM_MULTIPLIER;
@ -75,11 +72,11 @@ public class TestCodecs extends MultiCodecTestCase {
// start is inclusive and end is exclusive
public int nextInt(final int start, final int end) {
return start + RANDOM.nextInt(end-start);
return start + random.nextInt(end-start);
}
private int nextInt(final int lim) {
return RANDOM.nextInt(lim);
return random.nextInt(lim);
}
char[] getRandomText() {
@ -260,9 +257,6 @@ public class TestCodecs extends MultiCodecTestCase {
}
public void testFixedPostings() throws Throwable {
RANDOM = this.newRandom();
final int NUM_TERMS = 100;
final TermData[] terms = new TermData[NUM_TERMS];
for(int i=0;i<NUM_TERMS;i++) {
@ -276,7 +270,7 @@ public class TestCodecs extends MultiCodecTestCase {
final FieldData field = new FieldData("field", fieldInfos, terms, true, false);
final FieldData[] fields = new FieldData[] {field};
final Directory dir = newDirectory(RANDOM);
final Directory dir = newDirectory();
this.write(fieldInfos, dir, fields);
final SegmentInfo si = new SegmentInfo(SEGMENT, 10000, dir, false, -1, SEGMENT, false, true, CodecProvider.getDefault().getWriter(null));
si.setHasProx(false);
@ -314,9 +308,6 @@ public class TestCodecs extends MultiCodecTestCase {
}
public void testRandomPostings() throws Throwable {
RANDOM = this.newRandom();
final FieldInfos fieldInfos = new FieldInfos();
final FieldData[] fields = new FieldData[NUM_FIELDS];
@ -326,7 +317,7 @@ public class TestCodecs extends MultiCodecTestCase {
fields[i] = new FieldData(fieldNames[i], fieldInfos, this.makeRandomTerms(omitTF, storePayloads), omitTF, storePayloads);
}
final Directory dir = newDirectory(RANDOM);
final Directory dir = newDirectory();
this.write(fieldInfos, dir, fields);
final SegmentInfo si = new SegmentInfo(SEGMENT, 10000, dir, false, -1, SEGMENT, false, true, CodecProvider.getDefault().getWriter(null));
@ -352,9 +343,8 @@ public class TestCodecs extends MultiCodecTestCase {
}
public void testSepPositionAfterMerge() throws IOException {
Random random = newRandom();
final Directory dir = newDirectory(random);
final IndexWriterConfig config = newIndexWriterConfig(random, Version.LUCENE_31,
final Directory dir = newDirectory();
final IndexWriterConfig config = newIndexWriterConfig(Version.LUCENE_31,
new MockAnalyzer());
config.setCodecProvider(new MockSepCodecs());
final IndexWriter writer = new IndexWriter(dir, config);

View File

@ -25,7 +25,6 @@ import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.util.LuceneTestCase;
import java.io.IOException;
import java.util.Random;
public class TestConcurrentMergeScheduler extends LuceneTestCase {
@ -60,12 +59,11 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
// Make sure running BG merges still work fine even when
// we are hitting exceptions during flushing.
public void testFlushExceptions() throws IOException {
Random random = newRandom();
MockDirectoryWrapper directory = newDirectory(random);
MockDirectoryWrapper directory = newDirectory();
FailOnlyOnFlush failure = new FailOnlyOnFlush();
directory.failOn(failure);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
Document doc = new Document();
Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
doc.add(idField);
@ -106,15 +104,14 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
// Test that deletes committed after a merge started and
// before it finishes, are correctly merged back:
public void testDeleteMerging() throws IOException {
Random random = newRandom();
MockDirectoryWrapper directory = newDirectory(random);
MockDirectoryWrapper directory = newDirectory();
LogDocMergePolicy mp = new LogDocMergePolicy();
// Force degenerate merging so we can get a mix of
// merging of segments with and without deletes at the
// start:
mp.setMinMergeDocs(1000);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMergePolicy(mp));
@ -145,9 +142,8 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
}
public void testNoExtraFiles() throws IOException {
Random random = newRandom();
MockDirectoryWrapper directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,
MockDirectoryWrapper directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2));
@ -163,7 +159,7 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
TestIndexWriter.assertNoUnreferencedFiles(directory, "testNoExtraFiles");
// Reopen
writer = new IndexWriter(directory, newIndexWriterConfig(random,
writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(2));
}
@ -174,13 +170,12 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
}
public void testNoWaitClose() throws IOException {
Random random = newRandom();
MockDirectoryWrapper directory = newDirectory(random);
MockDirectoryWrapper directory = newDirectory();
Document doc = new Document();
Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);
doc.add(idField);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(100);
for(int iter=0;iter<10;iter++) {
@ -209,7 +204,7 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
reader.close();
// Reopen
writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(100);
}
writer.close();

View File

@ -30,13 +30,13 @@ import org.apache.lucene.document.Field;
public class TestCrash extends LuceneTestCase {
private IndexWriter initIndex(Random random, boolean initialCommit) throws IOException {
return initIndex(random, newDirectory(random), initialCommit);
return initIndex(random, newDirectory(), initialCommit);
}
private IndexWriter initIndex(Random random, MockDirectoryWrapper dir, boolean initialCommit) throws IOException {
dir.setLockFactory(NoLockFactory.getNoLockFactory());
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergeScheduler(new ConcurrentMergeScheduler()));
((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();
if (initialCommit) {
@ -65,7 +65,7 @@ public class TestCrash extends LuceneTestCase {
// This test relies on being able to open a reader before any commit
// happened, so we must create an initial commit just to allow that, but
// before any documents were added.
IndexWriter writer = initIndex(newRandom(), true);
IndexWriter writer = initIndex(random, true);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
crash(writer);
IndexReader reader = IndexReader.open(dir, false);
@ -78,7 +78,6 @@ public class TestCrash extends LuceneTestCase {
// This test relies on being able to open a reader before any commit
// happened, so we must create an initial commit just to allow that, but
// before any documents were added.
Random random = newRandom();
IndexWriter writer = initIndex(random, true);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
dir.setPreventDoubleWrite(false);
@ -93,7 +92,6 @@ public class TestCrash extends LuceneTestCase {
}
public void testCrashAfterReopen() throws IOException {
Random random = newRandom();
IndexWriter writer = initIndex(random, false);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
writer.close();
@ -118,7 +116,7 @@ public class TestCrash extends LuceneTestCase {
public void testCrashAfterClose() throws IOException {
IndexWriter writer = initIndex(newRandom(), false);
IndexWriter writer = initIndex(random, false);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
writer.close();
@ -139,7 +137,7 @@ public class TestCrash extends LuceneTestCase {
public void testCrashAfterCloseNoWait() throws IOException {
IndexWriter writer = initIndex(newRandom(), false);
IndexWriter writer = initIndex(random, false);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
writer.close(false);
@ -160,7 +158,7 @@ public class TestCrash extends LuceneTestCase {
public void testCrashReaderDeletes() throws IOException {
IndexWriter writer = initIndex(newRandom(), false);
IndexWriter writer = initIndex(random, false);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
writer.close(false);
@ -183,7 +181,7 @@ public class TestCrash extends LuceneTestCase {
public void testCrashReaderDeletesAfterClose() throws IOException {
IndexWriter writer = initIndex(newRandom(), false);
IndexWriter writer = initIndex(random, false);
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
writer.close(false);

View File

@ -20,7 +20,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.Collection;
@ -197,11 +196,10 @@ public class TestDeletionPolicy extends LuceneTestCase {
final double SECONDS = 2.0;
boolean useCompoundFile = true;
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(dir, SECONDS);
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT,
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setIndexDeletionPolicy(policy);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
@ -217,7 +215,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
// Record last time when writer performed deletes of
// past commits
lastDeleteTime = System.currentTimeMillis();
conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT,
conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setIndexDeletionPolicy(policy);
lmp = (LogMergePolicy) conf.getMergePolicy();
@ -284,8 +282,6 @@ public class TestDeletionPolicy extends LuceneTestCase {
* Test a silly deletion policy that keeps all commits around.
*/
public void testKeepAllDeletionPolicy() throws IOException {
Random random = newRandom();
for(int pass=0;pass<2;pass++) {
boolean useCompoundFile = (pass % 2) != 0;
@ -293,10 +289,10 @@ public class TestDeletionPolicy extends LuceneTestCase {
// Never deletes a commit
KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
policy.dir = dir;
IndexWriterConfig conf = newIndexWriterConfig(random,
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setIndexDeletionPolicy(policy).setMaxBufferedDocs(10)
.setMergeScheduler(new SerialMergeScheduler());
@ -310,7 +306,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
}
writer.close();
conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT,
conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setIndexDeletionPolicy(policy);
lmp = (LogMergePolicy) conf.getMergePolicy();
@ -353,7 +349,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
// Open & close a writer and assert that it
// actually removed something:
int preCount = dir.listAll().length;
writer = new IndexWriter(dir, newIndexWriterConfig(random,
writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setIndexDeletionPolicy(policy));
@ -371,15 +367,13 @@ public class TestDeletionPolicy extends LuceneTestCase {
* then, opens a new IndexWriter on a previous commit
* point. */
public void testOpenPriorSnapshot() throws IOException {
Random random = newRandom();
// Never deletes a commit
KeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
policy.dir = dir;
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setIndexDeletionPolicy(policy).setMaxBufferedDocs(2));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -400,7 +394,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
assertTrue(lastCommit != null);
// Now add 1 doc and optimize
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(policy));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(policy));
addDoc(writer);
assertEquals(11, writer.numDocs());
writer.optimize();
@ -409,7 +403,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
assertEquals(6, IndexReader.listCommits(dir).size());
// Now open writer on the commit just before optimize:
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setIndexDeletionPolicy(policy).setIndexCommit(lastCommit));
assertEquals(10, writer.numDocs());
@ -422,7 +416,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
assertEquals(11, r.numDocs());
r.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setIndexDeletionPolicy(policy).setIndexCommit(lastCommit));
assertEquals(10, writer.numDocs());
// Commits the rollback:
@ -439,7 +433,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
r.close();
// Reoptimize
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(policy));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(policy));
writer.optimize();
writer.close();
@ -450,7 +444,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
// Now open writer on the commit just before optimize,
// but this time keeping only the last commit:
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexCommit(lastCommit));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexCommit(lastCommit));
assertEquals(10, writer.numDocs());
// Reader still sees optimized index, because writer
@ -477,17 +471,15 @@ public class TestDeletionPolicy extends LuceneTestCase {
* you know there are no readers.
*/
public void testKeepNoneOnInitDeletionPolicy() throws IOException {
Random random = newRandom();
for(int pass=0;pass<2;pass++) {
boolean useCompoundFile = (pass % 2) != 0;
KeepNoneOnInitDeletionPolicy policy = new KeepNoneOnInitDeletionPolicy();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(random,
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
.setMaxBufferedDocs(10);
@ -500,7 +492,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
}
writer.close();
conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
lmp = (LogMergePolicy) conf.getMergePolicy();
lmp.setUseCompoundFile(useCompoundFile);
@ -527,19 +519,18 @@ public class TestDeletionPolicy extends LuceneTestCase {
* Test a deletion policy that keeps last N commits.
*/
public void testKeepLastNDeletionPolicy() throws IOException {
Random random = newRandom();
final int N = 5;
for(int pass=0;pass<2;pass++) {
boolean useCompoundFile = (pass % 2) != 0;
Directory dir = newDirectory(random);
Directory dir = newDirectory();
KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
for(int j=0;j<N+1;j++) {
IndexWriterConfig conf = newIndexWriterConfig(random,
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
.setMaxBufferedDocs(10);
@ -589,8 +580,6 @@ public class TestDeletionPolicy extends LuceneTestCase {
* around, with reader doing deletes.
*/
public void testKeepLastNDeletionPolicyWithReader() throws IOException {
Random random = newRandom();
final int N = 10;
for(int pass=0;pass<2;pass++) {
@ -599,8 +588,8 @@ public class TestDeletionPolicy extends LuceneTestCase {
KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
Directory dir = newDirectory(random);
IndexWriterConfig conf = newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();
@ -612,7 +601,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
Query query = new TermQuery(searchTerm);
for(int i=0;i<N+1;i++) {
conf = newIndexWriterConfig(random,
conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
lmp = (LogMergePolicy) conf.getMergePolicy();
@ -634,7 +623,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
reader.close();
searcher.close();
}
conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy);
lmp = (LogMergePolicy) conf.getMergePolicy();
lmp.setUseCompoundFile(useCompoundFile);
@ -698,7 +687,6 @@ public class TestDeletionPolicy extends LuceneTestCase {
* around, through creates.
*/
public void testKeepLastNDeletionPolicyWithCreates() throws IOException {
Random random = newRandom();
final int N = 10;
@ -708,8 +696,8 @@ public class TestDeletionPolicy extends LuceneTestCase {
KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
Directory dir = newDirectory(random);
IndexWriterConfig conf = newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)
.setMaxBufferedDocs(10);
@ -723,7 +711,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
for(int i=0;i<N+1;i++) {
conf = newIndexWriterConfig(random,
conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.APPEND).setIndexDeletionPolicy(policy)
.setMaxBufferedDocs(10);
@ -746,7 +734,7 @@ public class TestDeletionPolicy extends LuceneTestCase {
reader.close();
searcher.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random,
writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy));
// This will not commit: there are no changes

View File

@ -35,8 +35,6 @@ public class TestDirectoryReader extends LuceneTestCase {
private Document doc2;
protected SegmentReader [] readers = new SegmentReader[2];
protected SegmentInfos sis;
private Random random;
public TestDirectoryReader(String s) {
super(s);
@ -45,8 +43,7 @@ public class TestDirectoryReader extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
dir = newDirectory();
doc1 = new Document();
doc2 = new Document();
DocHelper.setupDoc(doc1);
@ -136,9 +133,9 @@ public class TestDirectoryReader extends LuceneTestCase {
}
public void testIsCurrent() throws IOException {
Directory ramDir1=newDirectory(random);
Directory ramDir1=newDirectory();
addDoc(random, ramDir1, "test foo", true);
Directory ramDir2=newDirectory(random);
Directory ramDir2=newDirectory();
addDoc(random, ramDir2, "test blah", true);
IndexReader[] readers = new IndexReader[]{IndexReader.open(ramDir1, false), IndexReader.open(ramDir2, false)};
MultiReader mr = new MultiReader(readers);
@ -159,11 +156,11 @@ public class TestDirectoryReader extends LuceneTestCase {
}
public void testMultiTermDocs() throws IOException {
Directory ramDir1=newDirectory(random);
Directory ramDir1=newDirectory();
addDoc(random, ramDir1, "test foo", true);
Directory ramDir2=newDirectory(random);
Directory ramDir2=newDirectory();
addDoc(random, ramDir2, "test blah", true);
Directory ramDir3=newDirectory(random);
Directory ramDir3=newDirectory();
addDoc(random, ramDir3, "test wow", true);
IndexReader[] readers1 = new IndexReader[]{IndexReader.open(ramDir1, false), IndexReader.open(ramDir3, false)};
@ -204,7 +201,7 @@ public class TestDirectoryReader extends LuceneTestCase {
}
private void addDoc(Random random, Directory ramDir1, String s, boolean create) throws IOException {
IndexWriter iw = new IndexWriter(ramDir1, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(ramDir1, newIndexWriterConfig(
TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
create ? OpenMode.CREATE : OpenMode.APPEND));

View File

@ -110,10 +110,9 @@ public class TestDoc extends LuceneTestCase {
public void testIndexAndMerge() throws Exception {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw, true);
Random random = newRandom();
Directory directory = FSDirectory.open(indexDir);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(-1));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -144,7 +143,7 @@ public class TestDoc extends LuceneTestCase {
out = new PrintWriter(sw, true);
directory = FSDirectory.open(indexDir);
writer = new IndexWriter(directory, newIndexWriterConfig(random,
writer = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(-1));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);

View File

@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.io.Reader;
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
@ -43,7 +42,6 @@ import org.apache.lucene.util.BytesRef;
public class TestDocumentWriter extends LuceneTestCase {
private Directory dir;
private Random random;
public TestDocumentWriter(String s) {
super(s);
@ -52,8 +50,7 @@ public class TestDocumentWriter extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
dir = newDirectory();
}
@Override
@ -69,7 +66,7 @@ public class TestDocumentWriter extends LuceneTestCase {
public void testAddDocument() throws Exception {
Document testDoc = new Document();
DocHelper.setupDoc(testDoc);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.addDocument(testDoc);
writer.commit();
SegmentInfo info = writer.newestSegment();
@ -127,7 +124,7 @@ public class TestDocumentWriter extends LuceneTestCase {
}
};
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(new Field("repeated", "repeated one", Field.Store.YES, Field.Index.ANALYZED));
@ -192,7 +189,7 @@ public class TestDocumentWriter extends LuceneTestCase {
}
};
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
doc.add(new Field("f1", "a 5 a a", Field.Store.YES, Field.Index.ANALYZED));
@ -218,7 +215,7 @@ public class TestDocumentWriter extends LuceneTestCase {
public void testPreAnalyzedField() throws IOException {
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
@ -278,7 +275,7 @@ public class TestDocumentWriter extends LuceneTestCase {
doc.add(new Field("f2", "v1", Store.YES, Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
doc.add(new Field("f2", "v2", Store.YES, Index.NOT_ANALYZED, TermVector.NO));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.addDocument(doc);
writer.close();
@ -313,7 +310,7 @@ public class TestDocumentWriter extends LuceneTestCase {
doc.add(f);
doc.add(new Field("f2", "v2", Store.YES, Index.NO));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.addDocument(doc);
writer.optimize(); // be sure to have a single segment

View File

@ -47,7 +47,7 @@ public class TestFieldInfos extends LuceneTestCase {
fieldInfos.add(testDoc);
//Since the complement is stored as well in the fields map
assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor
Directory dir = newDirectory(newRandom());
Directory dir = newDirectory();
String name = "testFile";
IndexOutput output = dir.createOutput(name);
assertTrue(output != null);

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.apache.lucene.analysis.MockAnalyzer;
@ -47,7 +46,6 @@ public class TestFieldsReader extends LuceneTestCase {
private Directory dir;
private Document testDoc = new Document();
private FieldInfos fieldInfos = null;
private Random random;
private final static String TEST_SEGMENT_NAME = "_0";
public TestFieldsReader(String s) {
@ -60,9 +58,8 @@ public class TestFieldsReader extends LuceneTestCase {
fieldInfos = new FieldInfos();
DocHelper.setupDoc(testDoc);
fieldInfos.add(testDoc);
random = newRandom();
dir = newDirectory(random);
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer());
dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer());
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(false);
IndexWriter writer = new IndexWriter(dir, conf);
@ -302,7 +299,7 @@ public class TestFieldsReader extends LuceneTestCase {
FSDirectory tmpDir = FSDirectory.open(file);
assertTrue(tmpDir != null);
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE);
IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE);
((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);
IndexWriter writer = new IndexWriter(tmpDir, conf);
writer.addDocument(testDoc);
@ -482,7 +479,7 @@ public class TestFieldsReader extends LuceneTestCase {
try {
Directory dir = new FaultyFSDirectory(indexDir);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
for(int i=0;i<2;i++)
writer.addDocument(testDoc);

View File

@ -30,7 +30,6 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Bits;
import java.io.IOException;
import java.util.Random;
public class TestFilterIndexReader extends LuceneTestCase {
@ -130,9 +129,8 @@ public class TestFilterIndexReader extends LuceneTestCase {
* @throws Exception on error
*/
public void testFilterIndexReader() throws Exception {
Random random = newRandom();
Directory directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d1 = new Document();
d1.add(new Field("default","one two", Field.Store.YES, Field.Index.ANALYZED));
@ -149,8 +147,8 @@ public class TestFilterIndexReader extends LuceneTestCase {
writer.close();
//IndexReader reader = new TestReader(IndexReader.open(directory, true));
Directory target = newDirectory(random);
writer = new IndexWriter(target, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory target = newDirectory();
writer = new IndexWriter(target, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexReader reader = new TestReader(IndexReader.open(directory, true));
writer.addIndexes(reader);
writer.close();

View File

@ -17,12 +17,7 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.io.*;
import java.util.*;
import org.apache.lucene.store.*;
import org.apache.lucene.index.codecs.*;
import org.apache.lucene.index.codecs.standard.*;
import org.apache.lucene.search.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.document.*;
import org.apache.lucene.util.*;
@ -31,7 +26,7 @@ public class TestFlex extends LuceneTestCase {
// Test non-flex API emulated on flex index
public void testNonFlex() throws Exception {
Directory d = newDirectory(newRandom());
Directory d = newDirectory();
final int DOC_COUNT = 177;
@ -65,9 +60,8 @@ public class TestFlex extends LuceneTestCase {
}
public void testTermOrd() throws Exception {
Random random = newRandom();
Directory d = newDirectory(random);
IndexWriter w = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
Directory d = newDirectory();
IndexWriter w = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
doc.add(new Field("f", "a b c", Field.Store.NO, Field.Index.ANALYZED));

View File

@ -32,7 +32,7 @@ public class TestIndexCommit extends LuceneTestCaseJ4 {
@Test
public void testEqualsHashCode() throws Exception {
// LUCENE-2417: equals and hashCode() impl was inconsistent
final Directory dir = newDirectory(newRandom());
final Directory dir = newDirectory();
IndexCommit ic1 = new IndexCommit() {
@Override public String getSegmentsFileName() { return "a"; }

View File

@ -38,10 +38,9 @@ import java.util.*;
public class TestIndexFileDeleter extends LuceneTestCase {
public void testDeleteLeftoverFiles() throws IOException {
Random random = newRandom();
MockDirectoryWrapper dir = newDirectory(random);
MockDirectoryWrapper dir = newDirectory();
dir.setPreventDoubleWrite(false);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -147,7 +146,7 @@ public class TestIndexFileDeleter extends LuceneTestCase {
// Open & close a writer: it should delete the above 4
// files and nothing more:
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.close();
String[] files2 = dir.listAll();

View File

@ -27,7 +27,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
@ -71,26 +70,18 @@ public class TestIndexReader extends LuceneTestCase
// TestRunner.run (new TestIndexReader("testFilesOpenClose"));
}
private Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
public TestIndexReader(String name) {
super(name);
}
public void testCommitUserData() throws Exception {
Directory d = newDirectory(random);
Directory d = newDirectory();
Map<String,String> commitUserData = new HashMap<String,String>();
commitUserData.put("foo", "fighters");
// set up writer
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2));
for(int i=0;i<27;i++)
@ -113,7 +104,7 @@ public class TestIndexReader extends LuceneTestCase
assertTrue(c.equals(r.getIndexCommit()));
// Change the index
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(2));
for(int i=0;i<7;i++)
@ -125,7 +116,7 @@ public class TestIndexReader extends LuceneTestCase
assertFalse(r2.getIndexCommit().isOptimized());
r3.close();
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.APPEND));
writer.optimize();
@ -139,8 +130,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testIsCurrent() throws Exception {
Directory d = newDirectory(random);
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
Directory d = newDirectory();
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
writer.close();
@ -148,13 +139,13 @@ public class TestIndexReader extends LuceneTestCase
IndexReader reader = IndexReader.open(d, false);
assertTrue(reader.isCurrent());
// modify index by adding another document:
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
addDocumentWithFields(writer);
writer.close();
assertFalse(reader.isCurrent());
// re-create index:
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
addDocumentWithFields(writer);
writer.close();
@ -168,9 +159,9 @@ public class TestIndexReader extends LuceneTestCase
* @throws Exception on error
*/
public void testGetFieldNames() throws Exception {
Directory d = newDirectory(random);
Directory d = newDirectory();
// set up writer
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
writer.close();
@ -183,7 +174,7 @@ public class TestIndexReader extends LuceneTestCase
assertTrue(fieldNames.contains("unstored"));
reader.close();
// add more documents
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
// want to get some more segments here
int mergeFactor = ((LogMergePolicy) writer.getConfig().getMergePolicy()).getMergeFactor();
@ -260,9 +251,9 @@ public class TestIndexReader extends LuceneTestCase
}
public void testTermVectors() throws Exception {
Directory d = newDirectory(random);
Directory d = newDirectory();
// set up writer
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
// want to get some more segments here
// new termvector fields
@ -314,14 +305,14 @@ public class TestIndexReader extends LuceneTestCase
}
public void testBasicDelete() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = null;
IndexReader reader = null;
Term searchTerm = new Term("content", "aaa");
// add 100 documents with term : aaa
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 100; i++) {
addDoc(writer, searchTerm.text());
}
@ -358,10 +349,10 @@ public class TestIndexReader extends LuceneTestCase
}
public void testBinaryFields() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
byte[] bin = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 10; i++) {
addDoc(writer, "document number " + (i + 1));
@ -370,7 +361,7 @@ public class TestIndexReader extends LuceneTestCase
addDocumentWithTermVectorFields(writer);
}
writer.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
Document doc = new Document();
doc.add(new Field("bin1", bin));
doc.add(new Field("junk", "junk text", Field.Store.NO, Field.Index.ANALYZED));
@ -407,7 +398,7 @@ public class TestIndexReader extends LuceneTestCase
// force optimize
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
reader = IndexReader.open(dir, false);
@ -429,14 +420,14 @@ public class TestIndexReader extends LuceneTestCase
// Make sure attempts to make changes after reader is
// closed throws IOException:
public void testChangesAfterClose() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = null;
IndexReader reader = null;
Term searchTerm = new Term("content", "aaa");
// add 11 documents with term : aaa
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 11; i++) {
addDoc(writer, searchTerm.text());
}
@ -473,12 +464,12 @@ public class TestIndexReader extends LuceneTestCase
// Make sure we get lock obtain failed exception with 2 writers:
public void testLockObtainFailed() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
Term searchTerm = new Term("content", "aaa");
// add 11 documents with term : aaa
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.commit();
for (int i = 0; i < 11; i++) {
addDoc(writer, searchTerm.text());
@ -523,7 +514,7 @@ public class TestIndexReader extends LuceneTestCase
Term searchTerm = new Term("content", "aaa");
// add 1 documents with term : aaa
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDoc(writer, searchTerm.text());
writer.close();
@ -561,13 +552,13 @@ public class TestIndexReader extends LuceneTestCase
// Make sure you can set norms & commit, and there are
// no extra norms files left:
public void testWritingNormsNoReader() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = null;
IndexReader reader = null;
Term searchTerm = new Term("content", "aaa");
// add 1 documents with term : aaa
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);
addDoc(writer, searchTerm.text());
@ -615,13 +606,13 @@ public class TestIndexReader extends LuceneTestCase
private void deleteReaderWriterConflict(boolean optimize) throws IOException {
//Directory dir = new RAMDirectory();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
Term searchTerm = new Term("content", "aaa");
Term searchTerm2 = new Term("content", "bbb");
// add 100 documents with term : aaa
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
for (int i = 0; i < 100; i++) {
addDoc(writer, searchTerm.text());
}
@ -636,7 +627,7 @@ public class TestIndexReader extends LuceneTestCase
assertTermDocsCount("first reader", reader, searchTerm2, 0);
// add 100 documents with term : bbb
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
for (int i = 0; i < 100; i++) {
addDoc(writer, searchTerm2.text());
}
@ -698,7 +689,7 @@ public class TestIndexReader extends LuceneTestCase
// Create initial data set
File dirFile = _TestUtil.getTempDir("TestIndexReader.testFilesOpenClose");
Directory dir = FSDirectory.open(dirFile);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDoc(writer, "test");
writer.close();
dir.close();
@ -708,7 +699,7 @@ public class TestIndexReader extends LuceneTestCase
dir = FSDirectory.open(dirFile);
// Now create the data set again, just as before
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
addDoc(writer, "test");
writer.close();
dir.close();
@ -726,9 +717,9 @@ public class TestIndexReader extends LuceneTestCase
public void testLastModified() throws Exception {
for(int i=0;i<2;i++) {
final Directory dir = newDirectory(random);
final Directory dir = newDirectory();
assertFalse(IndexReader.indexExists(dir));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
addDocumentWithFields(writer);
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
writer.close();
@ -745,7 +736,7 @@ public class TestIndexReader extends LuceneTestCase
// incremented:
Thread.sleep(1000);
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
addDocumentWithFields(writer);
writer.close();
reader = IndexReader.open(dir, false);
@ -756,9 +747,9 @@ public class TestIndexReader extends LuceneTestCase
}
public void testVersion() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
assertFalse(IndexReader.indexExists(dir));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
assertTrue(IndexWriter.isLocked(dir)); // writer open, so dir is locked
writer.close();
@ -769,7 +760,7 @@ public class TestIndexReader extends LuceneTestCase
reader.close();
// modify index and check version has been
// incremented:
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
addDocumentWithFields(writer);
writer.close();
reader = IndexReader.open(dir, false);
@ -779,11 +770,11 @@ public class TestIndexReader extends LuceneTestCase
}
public void testLock() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
writer.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
IndexReader reader = IndexReader.open(dir, false);
try {
reader.deleteDocument(0);
@ -803,8 +794,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testUndeleteAll() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
addDocumentWithFields(writer);
writer.close();
@ -820,8 +811,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testUndeleteAllAfterClose() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
addDocumentWithFields(writer);
writer.close();
@ -837,8 +828,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testUndeleteAllAfterCloseThenReopen() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
addDocumentWithFields(writer);
writer.close();
@ -874,8 +865,8 @@ public class TestIndexReader extends LuceneTestCase
int END_COUNT = 144;
// First build up a starting index:
MockDirectoryWrapper startDir = newDirectory(random);
IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
MockDirectoryWrapper startDir = newDirectory();
IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
for(int i=0;i<157;i++) {
Document d = new Document();
d.add(new Field("id", Integer.toString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
@ -1048,8 +1039,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testDocsOutOfOrderJIRA140() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
for(int i=0;i<11;i++) {
addDoc(writer, "aaa");
}
@ -1067,7 +1058,7 @@ public class TestIndexReader extends LuceneTestCase
}
reader.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
// We must add more docs to get a new segment written
for(int i=0;i<11;i++) {
@ -1088,8 +1079,8 @@ public class TestIndexReader extends LuceneTestCase
public void testExceptionReleaseWriteLockJIRA768() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
addDoc(writer, "aaa");
writer.close();
@ -1143,7 +1134,7 @@ public class TestIndexReader extends LuceneTestCase
}
public void testMultiReaderDeletes() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random, dir);
Document doc = new Document();
doc.add(new Field("f", "doctor", Field.Store.NO, Field.Index.NOT_ANALYZED));
@ -1173,7 +1164,7 @@ public class TestIndexReader extends LuceneTestCase
}
private void deleteReaderReaderConflict(boolean optimize) throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
Term searchTerm1 = new Term("content", "aaa");
Term searchTerm2 = new Term("content", "bbb");
@ -1182,7 +1173,7 @@ public class TestIndexReader extends LuceneTestCase
// add 100 documents with term : aaa
// add 100 documents with term : bbb
// add 100 documents with term : ccc
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));
for (int i = 0; i < 100; i++) {
addDoc(writer, searchTerm1.text());
addDoc(writer, searchTerm2.text());
@ -1410,10 +1401,10 @@ public class TestIndexReader extends LuceneTestCase
public void testGetIndexCommit() throws IOException {
Directory d = newDirectory(random);
Directory d = newDirectory();
// set up writer
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -1431,7 +1422,7 @@ public class TestIndexReader extends LuceneTestCase
assertTrue(c.equals(r.getIndexCommit()));
// Change the index
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(2));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -1444,7 +1435,7 @@ public class TestIndexReader extends LuceneTestCase
assertFalse(r2.getIndexCommit().isOptimized());
r2.close();
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.APPEND));
writer.optimize();
@ -1459,8 +1450,8 @@ public class TestIndexReader extends LuceneTestCase
}
public void testReadOnly() throws Throwable {
Directory d = newDirectory(random);
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
Directory d = newDirectory();
IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
addDocumentWithFields(writer);
writer.commit();
@ -1475,7 +1466,7 @@ public class TestIndexReader extends LuceneTestCase
// expected
}
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.APPEND));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -1495,7 +1486,7 @@ public class TestIndexReader extends LuceneTestCase
// expected
}
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.APPEND));
writer.optimize();
@ -1516,7 +1507,7 @@ public class TestIndexReader extends LuceneTestCase
}
// Make sure write lock isn't held
writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.APPEND));
writer.close();
@ -1528,8 +1519,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1474
public void testIndexReader() throws Exception {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.addDocument(createDocument("a"));
writer.addDocument(createDocument("b"));
@ -1546,9 +1537,9 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1647
public void testIndexReaderUnDeleteAll() throws Exception {
MockDirectoryWrapper dir = newDirectory(random);
MockDirectoryWrapper dir = newDirectory();
dir.setPreventDoubleWrite(false);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.addDocument(createDocument("a"));
writer.addDocument(createDocument("b"));
@ -1588,9 +1579,9 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1509
public void testNoDupCommitFileNames() throws Throwable {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2));
writer.addDocument(createDocument("a"));
@ -1614,8 +1605,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1579: Ensure that on a cloned reader, segments
// reuse the doc values arrays in FieldCache
public void testFieldCacheReuseAfterClone() throws Exception {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
writer.addDocument(doc);
@ -1645,8 +1636,8 @@ public class TestIndexReader extends LuceneTestCase
// shared segments reuse the doc values arrays in
// FieldCache
public void testFieldCacheReuseAfterReopen() throws Exception {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
@ -1678,8 +1669,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1579: Make sure all SegmentReaders are new when
// reopen switches readOnly
public void testReopenChangeReadonly() throws Exception {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(-1));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(-1));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
Document doc = new Document();
doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
@ -1720,8 +1711,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1586: getUniqueTermCount
public void testUniqueTermCount() throws Exception {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
doc.add(new Field("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
@ -1753,8 +1744,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-1609: don't load terms index
public void testNoTermsIndex() throws Throwable {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Document doc = new Document();
doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
doc.add(new Field("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
@ -1771,7 +1762,7 @@ public class TestIndexReader extends LuceneTestCase
}
assertEquals(-1, ((SegmentReader) r.getSequentialSubReaders()[0]).getTermInfosIndexDivisor());
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
writer.addDocument(doc);
writer.close();
@ -1795,8 +1786,8 @@ public class TestIndexReader extends LuceneTestCase
// LUCENE-2046
public void testPrepareCommitIsCurrent() throws Throwable {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.commit();
Document doc = new Document();

View File

@ -17,8 +17,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.index.SegmentReader.Norm;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.analysis.MockAnalyzer;
@ -35,16 +33,9 @@ import org.apache.lucene.util.Bits;
* implemented properly
*/
public class TestIndexReaderClone extends LuceneTestCase {
Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
public void testCloneReadOnlySegmentReader() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader reader = IndexReader.open(dir1, false);
@ -63,7 +54,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1, clone to non-readOnly
// reader2, make sure we can change reader2
public void testCloneNoChangesStillReadOnly() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader r1 = IndexReader.open(dir1, false);
@ -79,7 +70,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1, clone to non-readOnly
// reader2, make sure we can change reader1
public void testCloneWriteToOrig() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader r1 = IndexReader.open(dir1, false);
@ -95,7 +86,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1, clone to non-readOnly
// reader2, make sure we can change reader2
public void testCloneWriteToClone() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader r1 = IndexReader.open(dir1, false);
@ -118,7 +109,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// SegmentReader, add docs, reopen to multireader, then do
// delete
public void testReopenSegmentReaderToMultiReader() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader reader1 = IndexReader.open(dir1, false);
@ -136,7 +127,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1, clone to readOnly reader2
public void testCloneWriteableToReadOnly() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader = IndexReader.open(dir1, false);
@ -158,7 +149,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1, reopen to readOnly reader2
public void testReopenWriteableToReadOnly() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader = IndexReader.open(dir1, false);
@ -179,7 +170,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open readOnly reader1, clone to non-readOnly reader2
public void testCloneReadOnlyToWriteable() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader1 = IndexReader.open(dir1, true);
@ -202,11 +193,11 @@ public class TestIndexReaderClone extends LuceneTestCase {
// open non-readOnly reader1 on multi-segment index, then
// optimize the index, then clone to readOnly reader2
public void testReadOnlyCloneAfterOptimize() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader1 = IndexReader.open(dir1, false);
IndexWriter w = new IndexWriter(dir1, newIndexWriterConfig(random,
IndexWriter w = new IndexWriter(dir1, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
w.optimize();
w.close();
@ -229,7 +220,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testCloneReadOnlyDirectoryReader() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader = IndexReader.open(dir1, false);
@ -253,9 +244,9 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testParallelReader() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir2, true);
IndexReader r1 = IndexReader.open(dir1, false);
IndexReader r2 = IndexReader.open(dir2, false);
@ -304,9 +295,9 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testMixedReaders() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir2, true);
IndexReader r1 = IndexReader.open(dir1, false);
IndexReader r2 = IndexReader.open(dir2, false);
@ -319,7 +310,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testSegmentReaderUndeleteall() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);
origSegmentReader.deleteDocument(10);
@ -332,7 +323,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testSegmentReaderCloseReferencing() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);
origSegmentReader.deleteDocument(1);
@ -351,7 +342,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testSegmentReaderDelDocsReferenceCounting() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader origReader = IndexReader.open(dir1, false);
@ -415,7 +406,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// LUCENE-1648
public void testCloneWithDeletes() throws Throwable {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader origReader = IndexReader.open(dir1, false);
origReader.deleteDocument(1);
@ -432,7 +423,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
// LUCENE-1648
public void testCloneWithSetNorm() throws Throwable {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader orig = IndexReader.open(dir1, false);
orig.setNorm(1, "field1", 17.0f);
@ -461,7 +452,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testCloneSubreaders() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, true);
IndexReader reader = IndexReader.open(dir1, false);
@ -481,7 +472,7 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testLucene1516Bug() throws Exception {
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader r1 = IndexReader.open(dir1, false);
r1.incRef();
@ -498,8 +489,8 @@ public class TestIndexReaderClone extends LuceneTestCase {
}
public void testCloseStoredFields() throws Exception {
final Directory dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,
final Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
((LogMergePolicy) w.getConfig().getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) w.getConfig().getMergePolicy()).setUseCompoundDocStore(false);

View File

@ -83,7 +83,6 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
*/
public void testNorms() throws IOException {
// test with a single index: index1
Random random = newRandom();
File indexDir1 = new File(TEMP_DIR, "lucenetestindex1");
Directory dir1 = FSDirectory.open(indexDir1);
IndexWriter.unlock(dir1);
@ -114,7 +113,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
Directory dir3 = FSDirectory.open(indexDir3);
createIndex(random, dir3);
IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
.setMaxBufferedDocs(5));
((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
@ -133,7 +132,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
doTestNorms(random, dir3);
// now with optimize
iw = new IndexWriter(dir3, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
iw = new IndexWriter(dir3, newIndexWriterConfig( TEST_VERSION_CURRENT,
anlzr).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(5));
((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
iw.optimize();
@ -165,8 +164,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
}
public void testNormsClose() throws IOException {
Random random = newRandom();
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
SegmentReader reader1 = SegmentReader.getOnlySegmentReader(dir1);
reader1.norms("field1");
@ -182,8 +180,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
}
public void testNormsRefCounting() throws IOException {
Random random = newRandom();
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
TestIndexReaderReopen.createIndex(random, dir1, false);
IndexReader reader1 = IndexReader.open(dir1, false);
@ -236,7 +233,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
}
private void createIndex(Random random, Directory dir) throws IOException {
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.CREATE)
.setMaxBufferedDocs(5).setSimilarity(similarityOne));
LogMergePolicy lmp = (LogMergePolicy) iw.getConfig().getMergePolicy();
@ -289,7 +286,7 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {
private void addDocs(Random random, Directory dir, int ndocs, boolean compound)
throws IOException {
IndexWriterConfig conf = newIndexWriterConfig(random,
IndexWriterConfig conf = newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
.setMaxBufferedDocs(5).setSimilarity(similarityOne);
LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();

View File

@ -45,14 +45,14 @@ import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BitVector;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.LuceneTestCaseJ4;
public class TestIndexReaderReopen extends LuceneTestCase {
private File indexDir;
public void testReopen() throws Exception {
Random random = newRandom();
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
createIndex(random, dir1, false);
performDefaultTests(new TestReopen() {
@ -70,7 +70,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
});
dir1.close();
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
createIndex(random, dir2, true);
performDefaultTests(new TestReopen() {
@ -90,10 +90,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testParallelReaderReopen() throws Exception {
Random random = newRandom();
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
createIndex(random, dir1, true);
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
createIndex(random, dir2, true);
performDefaultTests(new TestReopen() {
@ -116,9 +115,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {
dir1.close();
dir2.close();
final Directory dir3 = newDirectory(random);
final Directory dir3 = newDirectory();
createIndex(random, dir3, true);
final Directory dir4 = newDirectory(random);
final Directory dir4 = newDirectory();
createIndex(random, dir4, true);
performTestsWithExceptionInReopen(new TestReopen() {
@ -152,29 +151,27 @@ public class TestIndexReaderReopen extends LuceneTestCase {
// try this once with reopen once recreate, on both RAMDir and FSDir.
public void testCommitReopenFS () throws IOException {
Directory dir = FSDirectory.open(indexDir);
doTestReopenWithCommit(newRandom(), dir, true);
doTestReopenWithCommit(random, dir, true);
dir.close();
}
public void testCommitRecreateFS () throws IOException {
Directory dir = FSDirectory.open(indexDir);
doTestReopenWithCommit(newRandom(), dir, false);
doTestReopenWithCommit(random, dir, false);
dir.close();
}
public void testCommitReopenRAM () throws IOException {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
doTestReopenWithCommit(random, dir, true);
dir.close();
}
public void testCommitRecreateRAM () throws IOException {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
doTestReopenWithCommit(random, dir, false);
dir.close();
}
private void doTestReopenWithCommit (Random random, Directory dir, boolean withReopen) throws IOException {
IndexWriter iwriter = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter iwriter = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(
OpenMode.CREATE).setMergeScheduler(new SerialMergeScheduler()));
iwriter.commit();
@ -218,11 +215,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testMultiReaderReopen() throws Exception {
Random random = newRandom();
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
createIndex(random, dir1, true);
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
createIndex(random, dir2, true);
performDefaultTests(new TestReopen() {
@ -245,10 +241,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {
dir1.close();
dir2.close();
final Directory dir3 = newDirectory(random);
final Directory dir3 = newDirectory();
createIndex(random, dir3, true);
final Directory dir4 = newDirectory(random);
final Directory dir4 = newDirectory();
createIndex(random, dir4, true);
performTestsWithExceptionInReopen(new TestReopen() {
@ -275,16 +271,15 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testMixedReaders() throws Exception {
Random random = newRandom();
final Directory dir1 = newDirectory(random);
final Directory dir1 = newDirectory();
createIndex(random, dir1, true);
final Directory dir2 = newDirectory(random);
final Directory dir2 = newDirectory();
createIndex(random, dir2, true);
final Directory dir3 = newDirectory(random);
final Directory dir3 = newDirectory();
createIndex(random, dir3, false);
final Directory dir4 = newDirectory(random);
final Directory dir4 = newDirectory();
createIndex(random, dir4, true);
final Directory dir5 = newDirectory(random);
final Directory dir5 = newDirectory();
createIndex(random, dir5, false);
performDefaultTests(new TestReopen() {
@ -363,9 +358,8 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testReferenceCounting() throws IOException {
Random random = newRandom();
for (int mode = 0; mode < 4; mode++) {
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
createIndex(random, dir1, true);
IndexReader reader0 = IndexReader.open(dir1, false);
@ -469,11 +463,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {
public void testReferenceCountingMultiReader() throws IOException {
Random random = newRandom();
for (int mode = 0; mode <=1; mode++) {
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
createIndex(random, dir1, false);
Directory dir2 = newDirectory(random);
Directory dir2 = newDirectory();
createIndex(random, dir2, true);
IndexReader reader1 = IndexReader.open(dir1, false);
@ -541,11 +534,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testReferenceCountingParallelReader() throws IOException {
Random random = newRandom();
for (int mode = 0; mode <=1; mode++) {
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
createIndex(random, dir1, false);
Directory dir2 = newDirectory(random);
Directory dir2 = newDirectory();
createIndex(random, dir2, true);
IndexReader reader1 = IndexReader.open(dir1, false);
@ -617,8 +609,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testNormsRefCounting() throws IOException {
Random random = newRandom();
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
createIndex(random, dir1, false);
IndexReader reader1 = IndexReader.open(dir1, false);
@ -708,10 +699,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testThreadSafety() throws Exception {
Random random = newRandom();
final Directory dir = newDirectory(random);
final Directory dir = newDirectory();
final int n = 30 * RANDOM_MULTIPLIER;
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < n; i++) {
writer.addDocument(createDocument(i, 3));
@ -957,7 +947,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
public static void createIndex(Random random, Directory dir, boolean multiSegment) throws IOException {
IndexWriter.unlock(dir);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter w = new IndexWriter(dir, LuceneTestCaseJ4.newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMergePolicy(new LogDocMergePolicy()));
@ -1109,8 +1099,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testCloseOrig() throws Throwable {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
createIndex(random, dir, false);
IndexReader r1 = IndexReader.open(dir, false);
IndexReader r2 = IndexReader.open(dir, false);
@ -1131,8 +1120,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testDeletes() throws Throwable {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
createIndex(random, dir, false); // Create an index with a bunch of docs (1 segment)
modifyIndex(0, dir); // Get delete bitVector on 1st segment
@ -1166,8 +1154,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testDeletes2() throws Throwable {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
createIndex(random, dir, false);
// Get delete bitVector
modifyIndex(0, dir);
@ -1203,9 +1190,8 @@ public class TestIndexReaderReopen extends LuceneTestCase {
}
public void testReopenOnCommit() throws Throwable {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(new KeepAllCommits()).setMaxBufferedDocs(-1));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
for(int i=0;i<4;i++) {

File diff suppressed because it is too large Load Diff

View File

@ -263,7 +263,7 @@ public class TestIndexWriterConfig extends LuceneTestCaseJ4 {
// iw.getConfig().getXYZ(), he'll get the same value he passed to
// iw.setXYZ().
IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer());
Directory dir = newDirectory(newRandom());
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, conf);
writer.setSimilarity(new MySimilarity());

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@ -34,13 +33,6 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
public class TestIndexWriterDelete extends LuceneTestCase {
Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
// test the simple case
public void testSimpleCase() throws IOException {
@ -50,8 +42,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
"Venice has lots of canals" };
String[] text = { "Amsterdam", "Venice" };
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(1));
for (int i = 0; i < keywords.length; i++) {
@ -85,8 +77,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test when delete terms only apply to disk segments
public void testNonRAMDelete() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2)
.setMaxBufferedDeleteTerms(2));
@ -119,8 +111,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
}
public void testMaxBufferedDeletes() throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(1));
writer.deleteDocuments(new Term("foobar", "1"));
writer.deleteDocuments(new Term("foobar", "1"));
@ -133,8 +125,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test when delete terms only apply to ram segments
public void testRAMDeletes() throws IOException {
for(int t=0;t<2;t++) {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(4)
.setMaxBufferedDeleteTerms(4));
@ -174,8 +166,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test when delete terms apply to both disk and ram segments
public void testBothDeletes() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(100)
.setMaxBufferedDeleteTerms(100));
@ -208,8 +200,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test that batched delete terms are flushed together
public void testBatchDeletes() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2)
.setMaxBufferedDeleteTerms(2));
@ -251,8 +243,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test deleteAll()
public void testDeleteAll() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2)
.setMaxBufferedDeleteTerms(2));
@ -297,8 +289,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test rollback of deleteAll()
public void testDeleteAllRollback() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2)
.setMaxBufferedDeleteTerms(2));
@ -334,8 +326,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
// test deleteAll() w/ near real-time reader
public void testDeleteAllNRT() throws IOException {
Directory dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2)
.setMaxBufferedDeleteTerms(2));
@ -424,10 +416,10 @@ public class TestIndexWriterDelete extends LuceneTestCase {
int END_COUNT = 144;
// First build up a starting index:
MockDirectoryWrapper startDir = newDirectory(random);
MockDirectoryWrapper startDir = newDirectory();
// TODO: find the resource leak that only occurs sometimes here.
startDir.setNoDeleteOpenFile(false);
IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
for (int i = 0; i < 157; i++) {
Document d = new Document();
d.add(new Field("id", Integer.toString(i), Field.Store.YES,
@ -450,7 +442,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {
MockDirectoryWrapper dir = new MockDirectoryWrapper(new RAMDirectory(startDir));
dir.setPreventDoubleWrite(false);
IndexWriter modifier = new IndexWriter(dir,
newIndexWriterConfig(random,
newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false))
.setMaxBufferedDocs(1000)
.setMaxBufferedDeleteTerms(1000)
@ -663,8 +655,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
"Venice has lots of canals" };
String[] text = { "Amsterdam", "Venice" };
MockDirectoryWrapper dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,
MockDirectoryWrapper dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(2).setReaderPooling(false));
LogMergePolicy lmp = (LogMergePolicy) modifier.getConfig().getMergePolicy();
lmp.setUseCompoundFile(true);
@ -773,8 +765,8 @@ public class TestIndexWriterDelete extends LuceneTestCase {
"Venice has lots of canals" };
String[] text = { "Amsterdam", "Venice" };
MockDirectoryWrapper dir = newDirectory(random);
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
MockDirectoryWrapper dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));
modifier.commit();
dir.failOn(failure.reset());
@ -801,7 +793,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {
}
public void testDeleteNullQuery() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter modifier = new IndexWriter(dir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), IndexWriter.MaxFieldLength.UNLIMITED);
for (int i = 0; i < 5; i++) {

View File

@ -129,10 +129,9 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
}
public void testRandomExceptions() throws Throwable {
Random random = newRandom();
MockDirectoryWrapper dir = newDirectory(random);
MockDirectoryWrapper dir = newDirectory();
MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer())
.setRAMBufferSizeMB(0.1).setMergeScheduler(new ConcurrentMergeScheduler()));
((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();
//writer.setMaxBufferedDocs(10);
@ -170,9 +169,8 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
}
public void testRandomExceptionsThreads() throws Throwable {
Random random = newRandom();
MockDirectoryWrapper dir = newDirectory(random);
MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
MockDirectoryWrapper dir = newDirectory();
MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer())
.setRAMBufferSizeMB(0.2).setMergeScheduler(new ConcurrentMergeScheduler()));
((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();
//writer.setMaxBufferedDocs(10);

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -30,19 +29,12 @@ import org.apache.lucene.util._TestUtil;
import org.apache.lucene.util.LuceneTestCase;
public class TestIndexWriterMergePolicy extends LuceneTestCase {
private Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
// Test the normal case
public void testNormalCase() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));
@ -57,9 +49,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test to see if there is over merge
public void testNoOverMerge() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));
@ -79,12 +71,12 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test the case where flush is forced after every addDoc
public void testForceFlush() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
LogDocMergePolicy mp = new LogDocMergePolicy();
mp.setMinMergeDocs(100);
mp.setMergeFactor(10);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergePolicy(mp));
@ -94,7 +86,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
mp = new LogDocMergePolicy();
mp.setMergeFactor(10);
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(mp));
mp.setMinMergeDocs(100);
@ -107,9 +99,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test the case where mergeFactor changes
public void testMergeFactorChange() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));
@ -133,9 +125,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test the case where both mergeFactor and maxBufferedDocs change
public void testMaxBufferedDocsChange() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(101).setMergePolicy(new LogDocMergePolicy()));
@ -148,7 +140,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
}
writer.close();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(101).setMergePolicy(
new LogDocMergePolicy()));
@ -157,7 +149,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
writer.close();
LogDocMergePolicy ldmp = new LogDocMergePolicy();
ldmp.setMergeFactor(10);
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp).setMergeScheduler(new ConcurrentMergeScheduler()));
@ -182,11 +174,11 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
// Test the case where a merge results in no doc at all
public void testMergeDocCount0() throws IOException {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
LogDocMergePolicy ldmp = new LogDocMergePolicy();
ldmp.setMergeFactor(100);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(10).setMergePolicy(ldmp));
@ -202,7 +194,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {
ldmp = new LogDocMergePolicy();
ldmp.setMergeFactor(5);
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT,
new MockAnalyzer()).setOpenMode(
OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp).setMergeScheduler(new ConcurrentMergeScheduler()));

View File

@ -34,11 +34,10 @@ public class TestIndexWriterMerging extends LuceneTestCase
* change the index order of documents.
*/
public void testLucene() throws IOException {
Random random = newRandom();
int num=100;
Directory indexA = newDirectory(random);
Directory indexB = newDirectory(random);
Directory indexA = newDirectory();
Directory indexB = newDirectory();
fillIndex(random, indexA, 0, num);
boolean fail = verifyIndex(indexA, 0);
@ -54,9 +53,9 @@ public class TestIndexWriterMerging extends LuceneTestCase
fail("Index b is invalid");
}
Directory merged = newDirectory(random);
Directory merged = newDirectory();
IndexWriter writer = new IndexWriter(merged, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter writer = new IndexWriter(merged, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
writer.addIndexes(new Directory[]{indexA, indexB});
@ -95,7 +94,7 @@ public class TestIndexWriterMerging extends LuceneTestCase
private void fillIndex(Random random, Directory dir, int start, int numDocs) throws IOException {
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT,
new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(2));

View File

@ -38,6 +38,7 @@ import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCaseJ4;
import org.apache.lucene.util._TestUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.ThreadInterruptedException;
@ -45,13 +46,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public class TestIndexWriterReader extends LuceneTestCase {
static PrintStream infoStream;
private Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
public static int count(Term t, IndexReader r) throws IOException {
int count = 0;
@ -71,8 +65,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testUpdateDocument() throws Exception {
boolean optimize = true;
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
// create the index
createIndexNoClose(!optimize, "index1", writer);
@ -106,7 +100,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
assertEquals(0, count(new Term("id", id10), r3));
assertEquals(1, count(new Term("id", Integer.toString(8000)), r3));
writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
writer.addDocument(doc);
@ -132,16 +126,16 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testAddIndexes() throws Exception {
boolean optimize = false;
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
// create the index
createIndexNoClose(!optimize, "index1", writer);
writer.flush(false, true, true);
// create a 2nd index
Directory dir2 = newDirectory(random);
IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir2 = newDirectory();
IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer2.setInfoStream(infoStream);
createIndexNoClose(!optimize, "index2", writer2);
writer2.close();
@ -178,13 +172,13 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testAddIndexes2() throws Exception {
boolean optimize = false;
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
// create a 2nd index
Directory dir2 = newDirectory(random);
IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir2 = newDirectory();
IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer2.setInfoStream(infoStream);
createIndexNoClose(!optimize, "index2", writer2);
writer2.close();
@ -212,8 +206,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testDeleteFromIndexWriter() throws Exception {
boolean optimize = true;
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setReaderTermsIndexDivisor(2));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setReaderTermsIndexDivisor(2));
writer.setInfoStream(infoStream);
// create the index
createIndexNoClose(!optimize, "index1", writer);
@ -251,7 +245,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
writer.close();
// reopen the writer to verify the delete made it to the directory
writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
IndexReader w2r1 = writer.getReader();
assertEquals(0, count(new Term("id", id10), w2r1));
@ -264,8 +258,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
final int numIter = 2;
int numDirs = 3;
Directory mainDir = newDirectory(random);
IndexWriter mainWriter = new IndexWriter(mainDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory mainDir = newDirectory();
IndexWriter mainWriter = new IndexWriter(mainDir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
mainWriter.setInfoStream(infoStream);
AddDirectoriesThreads addDirThreads = new AddDirectoriesThreads(numIter, mainWriter);
addDirThreads.launchThreads(numDirs);
@ -307,8 +301,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
public AddDirectoriesThreads(int numDirs, IndexWriter mainWriter) throws Throwable {
this.numDirs = numDirs;
this.mainWriter = mainWriter;
addDir = newDirectory(random);
IndexWriter writer = new IndexWriter(addDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
addDir = newDirectory();
IndexWriter writer = new IndexWriter(addDir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));
for (int i = 0; i < NUM_INIT_DOCS; i++) {
Document doc = createDocument(i, "addindex", 4);
writer.addDocument(doc);
@ -413,8 +407,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
* IW.getReader
*/
public void doTestIndexWriterReopenSegment(boolean optimize) throws Exception {
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
IndexReader r1 = writer.getReader();
assertEquals(0, r1.maxDoc());
@ -451,7 +445,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
writer.close();
// test whether the changes made it to the directory
writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexReader w2r1 = writer.getReader();
// insure the deletes were actually flushed to the directory
assertEquals(200, w2r1.maxDoc());
@ -490,7 +484,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
public static void createIndex(Random random, Directory dir1, String indexName,
boolean multiSegment) throws IOException {
IndexWriter w = new IndexWriter(dir1, newIndexWriterConfig(random,
IndexWriter w = new IndexWriter(dir1, LuceneTestCaseJ4.newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMergePolicy(new LogDocMergePolicy()));
for (int i = 0; i < 100; i++) {
@ -524,10 +518,10 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testMergeWarmer() throws Exception {
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
// Enroll warmer
MyWarmer warmer = new MyWarmer();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2).setMergedSegmentWarmer(warmer).setMergeScheduler(new ConcurrentMergeScheduler()));
writer.setInfoStream(infoStream);
@ -559,8 +553,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
}
public void testAfterCommit() throws Exception {
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new ConcurrentMergeScheduler()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new ConcurrentMergeScheduler()));
writer.commit();
writer.setInfoStream(infoStream);
@ -592,8 +586,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
// Make sure reader remains usable even if IndexWriter closes
public void testAfterClose() throws Exception {
Directory dir1 = newDirectory(random);
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
// create the index
@ -621,8 +615,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
// Stress test reopen during addIndexes
public void testDuringAddIndexes() throws Exception {
Directory dir1 = newDirectory(random);
final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
@ -699,8 +693,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
// Stress test reopen during add/delete
public void testDuringAddDelete() throws Exception {
Directory dir1 = newDirectory(random);
final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
writer.setInfoStream(infoStream);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
@ -779,8 +773,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
}
public void testExpungeDeletes() throws Throwable {
Directory dir = newDirectory(random);
final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
@ -803,8 +797,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
}
public void testDeletesNumDocs() throws Throwable {
Directory dir = newDirectory(random);
final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));
Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
@ -833,8 +827,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
public void testEmptyIndex() throws Exception {
// Ensures that getReader works on an empty index, which hasn't been committed yet.
Directory dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexReader r = w.getReader();
assertEquals(0, r.numDocs());
r.close();
@ -843,8 +837,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
}
public void testSegmentWarmer() throws Exception {
Directory dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2).setReaderPooling(true));
((LogMergePolicy) w.getMergePolicy()).setMergeFactor(10);
w.setMergedSegmentWarmer(new IndexWriter.IndexReaderWarmer() {

View File

@ -22,14 +22,12 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.util.*;
import org.apache.lucene.analysis.*;
import org.apache.lucene.store.*;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.IOException;
import java.util.Random;
public class TestIsCurrent extends LuceneTestCaseJ4 {
@ -37,17 +35,13 @@ public class TestIsCurrent extends LuceneTestCaseJ4 {
private Directory directory;
private Random rand;
@Override
public void setUp() throws Exception {
super.setUp();
rand = newRandom();
// initialize directory
directory = newDirectory(rand);
writer = new RandomIndexWriter(rand, directory);
directory = newDirectory();
writer = new RandomIndexWriter(random, directory);
// write document
Document doc = new Document();

View File

@ -67,10 +67,9 @@ public class TestLazyBug extends LuceneTestCase {
};
private Directory makeIndex() throws Exception {
Random r = newRandom();
Directory dir = newDirectory(r);
Directory dir = newDirectory();
try {
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(r,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();
lmp.setUseCompoundFile(false);
@ -81,7 +80,7 @@ public class TestLazyBug extends LuceneTestCase {
for (int f = 1; f <= NUM_FIELDS; f++ ) {
doc.add(new Field("f"+f,
data[f % data.length]
+ '#' + data[r.nextInt(data.length)],
+ '#' + data[random.nextInt(data.length)],
Field.Store.YES,
Field.Index.ANALYZED));
}

View File

@ -68,7 +68,7 @@ public class TestLazyProxSkipping extends LuceneTestCase {
int numDocs = 500;
Directory directory = new SeekCountingDirectory(new RAMDirectory());
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);
for (int i = 0; i < numDocs; i++) {
@ -120,15 +120,13 @@ public class TestLazyProxSkipping extends LuceneTestCase {
public void testLazySkipping() throws IOException {
// test whether only the minimum amount of seeks() are performed
Random random = newRandom();
performTest(random, 5);
performTest(random, 10);
}
public void testSeek() throws IOException {
Random random = newRandom();
Directory directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
for (int i = 0; i < 10; i++) {
Document doc = new Document();
doc.add(new Field(this.field, "a b", Field.Store.YES, Field.Index.ANALYZED));

View File

@ -27,36 +27,34 @@ public class TestMultiFields extends LuceneTestCase {
public void testRandom() throws Exception {
Random r = newRandom();
int num = 2 * RANDOM_MULTIPLIER;
for (int iter = 0; iter < num; iter++) {
Directory dir = newDirectory(r);
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(r, TEST_VERSION_CURRENT, new MockAnalyzer()).setMergePolicy(NoMergePolicy.COMPOUND_FILES));
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMergePolicy(NoMergePolicy.COMPOUND_FILES));
Map<BytesRef,List<Integer>> docs = new HashMap<BytesRef,List<Integer>>();
Set<Integer> deleted = new HashSet<Integer>();
List<BytesRef> terms = new ArrayList<BytesRef>();
int numDocs = _TestUtil.nextInt(r, 1, 100 * RANDOM_MULTIPLIER);
int numDocs = _TestUtil.nextInt(random, 1, 100 * RANDOM_MULTIPLIER);
Document doc = new Document();
Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
doc.add(f);
Field id = new Field("id", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
doc.add(id);
boolean onlyUniqueTerms = r.nextBoolean();
boolean onlyUniqueTerms = random.nextBoolean();
Set<BytesRef> uniqueTerms = new HashSet<BytesRef>();
for(int i=0;i<numDocs;i++) {
if (!onlyUniqueTerms && r.nextBoolean() && terms.size() > 0) {
if (!onlyUniqueTerms && random.nextBoolean() && terms.size() > 0) {
// re-use existing term
BytesRef term = terms.get(r.nextInt(terms.size()));
BytesRef term = terms.get(random.nextInt(terms.size()));
docs.get(term).add(i);
f.setValue(term.utf8ToString());
} else {
String s = _TestUtil.randomUnicodeString(r, 10);
String s = _TestUtil.randomUnicodeString(random, 10);
BytesRef term = new BytesRef(s);
if (!docs.containsKey(term)) {
docs.put(term, new ArrayList<Integer>());
@ -68,11 +66,11 @@ public class TestMultiFields extends LuceneTestCase {
}
id.setValue(""+i);
w.addDocument(doc);
if (r.nextInt(4) == 1) {
if (random.nextInt(4) == 1) {
w.commit();
}
if (i > 0 && r.nextInt(20) == 1) {
int delID = r.nextInt(i);
if (i > 0 && random.nextInt(20) == 1) {
int delID = random.nextInt(i);
deleted.add(delID);
w.deleteDocuments(new Term("id", ""+delID));
}
@ -98,7 +96,7 @@ public class TestMultiFields extends LuceneTestCase {
Terms terms2 = MultiFields.getTerms(reader, "field");
for(int i=0;i<100;i++) {
BytesRef term = terms.get(r.nextInt(terms.size()));
BytesRef term = terms.get(random.nextInt(terms.size()));
DocsEnum docsEnum = terms2.docs(delDocs, term, null);
assertNotNull(docsEnum);
@ -131,9 +129,8 @@ public class TestMultiFields extends LuceneTestCase {
*/
public void testSeparateEnums() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d = new Document();
d.add(new Field("f", "j", Field.Store.NO, Field.Index.NOT_ANALYZED));
w.addDocument(d);

View File

@ -62,7 +62,7 @@ public class TestMultiLevelSkipList extends LuceneTestCase {
public void testSimpleSkip() throws IOException {
Directory dir = new CountingRAMDirectory(new RAMDirectory());
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new PayloadAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new PayloadAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
Term term = new Term("test", "a");
for (int i = 0; i < 5000; i++) {
Document d1 = new Document();

View File

@ -30,8 +30,8 @@ public class TestNRTReaderWithThreads extends LuceneTestCase {
AtomicInteger seq = new AtomicInteger(1);
public void testIndexing() throws Exception {
Directory mainDir = newDirectory(random);
IndexWriter writer = new IndexWriter(mainDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));
Directory mainDir = newDirectory();
IndexWriter writer = new IndexWriter(mainDir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);

View File

@ -17,19 +17,14 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
public class TestNewestSegment extends LuceneTestCase {
public void testNewestSegment() throws Exception {
Random random = newRandom();
Directory directory = newDirectory(random);
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory directory = newDirectory();
IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
assertNull(writer.newestSegment());
writer.close();
directory.close();

View File

@ -73,9 +73,8 @@ public class TestNoDeletionPolicy extends LuceneTestCaseJ4 {
@Test
public void testAllCommitsRemain() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE));
for (int i = 0; i < 10; i++) {

View File

@ -74,8 +74,7 @@ public class TestNorms extends LuceneTestCase {
* Including optimize.
*/
public void testNorms() throws IOException {
Random random = newRandom();
Directory dir1 = newDirectory(random);
Directory dir1 = newDirectory();
norms = new ArrayList<Float>();
modifiedNorms = new ArrayList<Float>();
@ -92,16 +91,16 @@ public class TestNorms extends LuceneTestCase {
modifiedNorms = new ArrayList<Float>();
numDocNorms = 0;
Directory dir2 = newDirectory(random);
Directory dir2 = newDirectory();
createIndex(random, dir2);
doTestNorms(random, dir2);
// add index1 and index2 to a third index: index3
Directory dir3 = newDirectory(random);
Directory dir3 = newDirectory();
createIndex(random, dir3);
IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
.setMaxBufferedDocs(5));
((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
@ -120,7 +119,7 @@ public class TestNorms extends LuceneTestCase {
doTestNorms(random, dir3);
// now with optimize
iw = new IndexWriter(dir3, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
iw = new IndexWriter(dir3, newIndexWriterConfig( TEST_VERSION_CURRENT,
anlzr).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(5));
((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
iw.optimize();
@ -146,7 +145,7 @@ public class TestNorms extends LuceneTestCase {
}
private void createIndex(Random random, Directory dir) throws IOException {
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.CREATE)
.setMaxBufferedDocs(5).setSimilarity(similarityOne));
LogMergePolicy lmp = (LogMergePolicy) iw.getConfig().getMergePolicy();
@ -191,7 +190,7 @@ public class TestNorms extends LuceneTestCase {
}
private void addDocs(Random random, Directory dir, int ndocs, boolean compound) throws IOException {
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
.setMaxBufferedDocs(5).setSimilarity(similarityOne));
LogMergePolicy lmp = (LogMergePolicy) iw.getConfig().getMergePolicy();

View File

@ -19,7 +19,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Collection;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@ -34,13 +33,6 @@ import org.apache.lucene.search.Explanation.IDFExplanation;
public class TestOmitTf extends LuceneTestCase {
private Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
public static class SimpleSimilarity extends Similarity {
@Override public float lengthNorm(String field, int numTerms) { return 1.0f; }
@ -66,9 +58,9 @@ public class TestOmitTf extends LuceneTestCase {
// Tests whether the DocumentWriter correctly enable the
// omitTermFreqAndPositions bit in the FieldInfo
public void testOmitTermFreqAndPositions() throws Exception {
Directory ram = newDirectory(random);
Directory ram = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig( TEST_VERSION_CURRENT, analyzer));
Document d = new Document();
// this field will have Tf
@ -113,9 +105,9 @@ public class TestOmitTf extends LuceneTestCase {
// Tests whether merging of docs that have different
// omitTermFreqAndPositions for the same field works
public void testMixedMerge() throws Exception {
Directory ram = newDirectory(random);
Directory ram = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(
TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(3));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
Document d = new Document();
@ -166,9 +158,9 @@ public class TestOmitTf extends LuceneTestCase {
// field X, then adding docs that do omitTermFreqAndPositions for that same
// field,
public void testMixedRAM() throws Exception {
Directory ram = newDirectory(random);
Directory ram = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(
TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(10));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
Document d = new Document();
@ -214,9 +206,9 @@ public class TestOmitTf extends LuceneTestCase {
// Verifies no *.prx exists when all fields omit term freq:
public void testNoPrxFile() throws Throwable {
Directory ram = newDirectory(random);
Directory ram = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(
TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(3));
LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();
lmp.setMergeFactor(2);
@ -247,9 +239,9 @@ public class TestOmitTf extends LuceneTestCase {
// Test scores with one field with Term Freqs and one without, otherwise with equal content
public void testBasic() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
Analyzer analyzer = new MockAnalyzer();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(2)
.setSimilarity(new SimpleSimilarity()));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);

View File

@ -39,13 +39,11 @@ public class TestParallelReader extends LuceneTestCase {
private IndexSearcher parallel;
private IndexSearcher single;
private Random random;
private Directory dir, dir1, dir2;
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
single = single(random);
parallel = parallel(random);
}
@ -122,8 +120,8 @@ public class TestParallelReader extends LuceneTestCase {
Directory dir1 = getDir1(random);
// one document only:
Directory dir2 = newDirectory(random);
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir2 = newDirectory();
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d3 = new Document();
d3.add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
w2.addDocument(d3);
@ -176,14 +174,14 @@ public class TestParallelReader extends LuceneTestCase {
Directory dir2 = getDir2(random);
// add another document to ensure that the indexes are not optimized
IndexWriter modifier = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter modifier = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
((LogMergePolicy) modifier.getMergePolicy()).setMergeFactor(10);
Document d = new Document();
d.add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
modifier.addDocument(d);
modifier.close();
modifier = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
modifier = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
((LogMergePolicy) modifier.getMergePolicy()).setMergeFactor(10);
d = new Document();
d.add(new Field("f2", "v2", Field.Store.YES, Field.Index.ANALYZED));
@ -197,7 +195,7 @@ public class TestParallelReader extends LuceneTestCase {
assertFalse(pr.isOptimized());
pr.close();
modifier = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
modifier = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
modifier.optimize();
modifier.close();
@ -209,7 +207,7 @@ public class TestParallelReader extends LuceneTestCase {
pr.close();
modifier = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
modifier = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
modifier.optimize();
modifier.close();
@ -240,8 +238,8 @@ public class TestParallelReader extends LuceneTestCase {
// Fields 1-4 indexed together:
private IndexSearcher single(Random random) throws IOException {
dir = newDirectory(random);
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d1 = new Document();
d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
d1.add(new Field("f2", "v1", Field.Store.YES, Field.Index.ANALYZED));
@ -270,8 +268,8 @@ public class TestParallelReader extends LuceneTestCase {
}
private Directory getDir1(Random random) throws IOException {
Directory dir1 = newDirectory(random);
IndexWriter w1 = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir1 = newDirectory();
IndexWriter w1 = new IndexWriter(dir1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d1 = new Document();
d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));
d1.add(new Field("f2", "v1", Field.Store.YES, Field.Index.ANALYZED));
@ -285,8 +283,8 @@ public class TestParallelReader extends LuceneTestCase {
}
private Directory getDir2(Random random) throws IOException {
Directory dir2 = newDirectory(random);
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir2 = newDirectory();
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document d3 = new Document();
d3.add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));
d3.add(new Field("f4", "v1", Field.Store.YES, Field.Index.ANALYZED));

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
@ -46,16 +45,15 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {
* @throws IOException
*/
public void testEmptyIndex() throws IOException {
Random random = newRandom();
Directory rd1 = newDirectory(random);
IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory rd1 = newDirectory();
IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
iw.close();
Directory rd2 = newDirectory(random, rd1);
Directory rd2 = newDirectory(rd1);
Directory rdOut = newDirectory(random);
Directory rdOut = newDirectory();
IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
ParallelReader pr = new ParallelReader();
pr.add(IndexReader.open(rd1,true));
pr.add(IndexReader.open(rd2,true));
@ -77,10 +75,9 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {
* any exception.
*/
public void testEmptyIndexWithVectors() throws IOException {
Random random = newRandom();
Directory rd1 = newDirectory(random);
Directory rd1 = newDirectory();
{
IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
doc.add(new Field("test", "", Store.NO, Index.ANALYZED,
TermVector.YES));
@ -94,22 +91,22 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {
ir.deleteDocument(0);
ir.close();
iw = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
iw = new IndexWriter(rd1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
iw.optimize();
iw.close();
}
Directory rd2 = newDirectory(random);
Directory rd2 = newDirectory();
{
IndexWriter iw = new IndexWriter(rd2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter iw = new IndexWriter(rd2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
iw.addDocument(doc);
iw.close();
}
Directory rdOut = newDirectory(random);
Directory rdOut = newDirectory();
IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
ParallelReader pr = new ParallelReader();
pr.add(IndexReader.open(rd1,true));
pr.add(IndexReader.open(rd2,true));

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.analysis.MockAnalyzer;
@ -39,9 +38,8 @@ public class TestParallelTermEnum extends LuceneTestCase {
protected void setUp() throws Exception {
super.setUp();
Document doc;
Random random = newRandom();
rd1 = newDirectory(random);
IndexWriter iw1 = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
rd1 = newDirectory();
IndexWriter iw1 = new IndexWriter(rd1, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
doc = new Document();
doc.add(new Field("field1", "the quick brown fox jumps", Store.YES,
@ -52,8 +50,8 @@ public class TestParallelTermEnum extends LuceneTestCase {
iw1.addDocument(doc);
iw1.close();
rd2 = newDirectory(random);
IndexWriter iw2 = new IndexWriter(rd2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
rd2 = newDirectory();
IndexWriter iw2 = new IndexWriter(rd2, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
doc = new Document();
doc.add(new Field("field0", "", Store.NO, Index.ANALYZED));

View File

@ -119,13 +119,13 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {
private static final int NUM_DOCS = 10;
private IndexWriterConfig getConfig(Random random) {
return newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false));
return newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false));
}
private void populateDirs(Random random, Directory[] dirs, boolean multipleCommits)
throws IOException {
for (int i = 0; i < dirs.length; i++) {
dirs[i] = newDirectory(random);
dirs[i] = newDirectory();
populateDocs(random, dirs[i], multipleCommits);
verifyPayloadExists(dirs[i], "p", new BytesRef("p1"), NUM_DOCS);
verifyPayloadExists(dirs[i], "p", new BytesRef("p2"), NUM_DOCS);
@ -178,7 +178,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {
Directory[] dirs = new Directory[2];
populateDirs(random, dirs, multipleCommits);
Directory dir = newDirectory(random);
Directory dir = newDirectory();
if (!addToEmptyIndex) {
populateDocs(random, dir, multipleCommits);
verifyPayloadExists(dir, "p", new BytesRef("p1"), NUM_DOCS);
@ -218,7 +218,6 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {
@Test
public void testAddIndexes() throws Exception {
Random random = newRandom();
// addIndexes - single commit in each
doTest(random, true, 0, false);
@ -228,7 +227,6 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {
@Test
public void testAddIndexesIntoExisting() throws Exception {
Random random = newRandom();
// addIndexes - single commit in each
doTest(random, false, NUM_DOCS, false);
@ -238,8 +236,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {
@Test
public void testRegularMerges() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
populateDocs(random, dir, true);
verifyPayloadExists(dir, "p", new BytesRef("p1"), NUM_DOCS);
verifyPayloadExists(dir, "p", new BytesRef("p2"), NUM_DOCS);

View File

@ -50,7 +50,6 @@ public class TestPayloads extends LuceneTestCase {
// Simple tests to test the Payload class
public void testPayload() throws Exception {
rnd = newRandom();
byte[] testData = "This is a test!".getBytes();
Payload payload = new Payload(testData);
assertEquals("Wrong payload length.", testData.length, payload.length());
@ -99,10 +98,9 @@ public class TestPayloads extends LuceneTestCase {
// Tests whether the DocumentWriter and SegmentMerger correctly enable the
// payload bit in the FieldInfo
public void testPayloadFieldBit() throws Exception {
rnd = newRandom();
Directory ram = newDirectory(rnd);
Directory ram = newDirectory();
PayloadAnalyzer analyzer = new PayloadAnalyzer();
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(rnd, TEST_VERSION_CURRENT, analyzer));
IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig( TEST_VERSION_CURRENT, analyzer));
Document d = new Document();
// this field won't have any payloads
d.add(new Field("f1", "This field has no payloads", Field.Store.NO, Field.Index.ANALYZED));
@ -129,7 +127,7 @@ public class TestPayloads extends LuceneTestCase {
// now we add another document which has payloads for field f3 and verify if the SegmentMerger
// enabled payloads for that field
writer = new IndexWriter(ram, newIndexWriterConfig(rnd, TEST_VERSION_CURRENT,
writer = new IndexWriter(ram, newIndexWriterConfig( TEST_VERSION_CURRENT,
analyzer).setOpenMode(OpenMode.CREATE));
d = new Document();
d.add(new Field("f1", "This field has no payloads", Field.Store.NO, Field.Index.ANALYZED));
@ -157,15 +155,14 @@ public class TestPayloads extends LuceneTestCase {
// Tests if payloads are correctly stored and loaded using both RamDirectory and FSDirectory
public void testPayloadsEncoding() throws Exception {
rnd = newRandom();
// first perform the test using a RAMDirectory
Directory dir = newDirectory(rnd);
performTest(rnd, dir);
Directory dir = newDirectory();
performTest(random, dir);
dir.close();
// now use a FSDirectory and repeat same test
File dirName = _TestUtil.getTempDir("test_payloads");
dir = FSDirectory.open(dirName);
performTest(rnd, dir);
performTest(random, dir);
_TestUtil.rmDir(dirName);
dir.close();
}
@ -174,7 +171,7 @@ public class TestPayloads extends LuceneTestCase {
// different tests to verify the payload encoding
private void performTest(Random random, Directory dir) throws Exception {
PayloadAnalyzer analyzer = new PayloadAnalyzer();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, analyzer)
.setOpenMode(OpenMode.CREATE));
@ -315,7 +312,7 @@ public class TestPayloads extends LuceneTestCase {
// test long payload
analyzer = new PayloadAnalyzer();
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT,
analyzer).setOpenMode(OpenMode.CREATE));
String singleTerm = "lucene";
@ -349,10 +346,8 @@ public class TestPayloads extends LuceneTestCase {
}
private Random rnd;
private void generateRandomData(byte[] data) {
rnd.nextBytes(data);
random.nextBytes(data);
}
private byte[] generateRandomData(int n) {
@ -485,13 +480,12 @@ public class TestPayloads extends LuceneTestCase {
}
public void testThreadSafety() throws Exception {
rnd = newRandom();
final int numThreads = 5;
final int numDocs = 50 * RANDOM_MULTIPLIER;
final ByteArrayPool pool = new ByteArrayPool(numThreads, 5);
Directory dir = newDirectory(rnd);
final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(rnd,
Directory dir = newDirectory();
final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
final String field = "test";

View File

@ -39,7 +39,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
@Override
public void setUp() throws Exception {
super.setUp();
snapshotDir = newDirectory(random);
snapshotDir = newDirectory();
}
@After
@ -52,7 +52,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
@Override
protected SnapshotDeletionPolicy getDeletionPolicy() throws IOException {
snapshotDir.close();
snapshotDir = newDirectory(random);
snapshotDir = newDirectory();
return new PersistentSnapshotDeletionPolicy(
new KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.CREATE,
TEST_VERSION_CURRENT);
@ -73,7 +73,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
@Test
public void testExistingSnapshots() throws Exception {
int numSnapshots = 3;
Directory dir = newDirectory(random);
Directory dir = newDirectory();
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, psdp));
prepareIndexAndSnapshots(psdp, writer, numSnapshots, "snapshot");
@ -137,7 +137,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
@Test
public void testSnapshotRelease() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, psdp));
prepareIndexAndSnapshots(psdp, writer, 1, "snapshot");
@ -160,7 +160,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo
// prevents reading the snapshots information. This test checks that the
// static read method works.
int numSnapshots = 1;
Directory dir = newDirectory(random);
Directory dir = newDirectory();
PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, psdp));
prepareIndexAndSnapshots(psdp, writer, numSnapshots, "snapshot");

View File

@ -17,8 +17,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -31,8 +29,7 @@ public class TestRollback extends LuceneTestCase {
// LUCENE-2536
public void testRollbackIntegrityWithBufferFlush() throws Exception {
Random random = newRandom();
Directory dir = newDirectory(random);
Directory dir = newDirectory();
RandomIndexWriter rw = new RandomIndexWriter(random, dir);
for (int i = 0; i < 5; i++) {
Document doc = new Document();
@ -42,7 +39,7 @@ public class TestRollback extends LuceneTestCase {
rw.close();
// If buffer size is small enough to cause a flush, errors ensue...
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setOpenMode(IndexWriterConfig.OpenMode.APPEND));
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setOpenMode(IndexWriterConfig.OpenMode.APPEND));
Term pkTerm = new Term("pk", "");
for (int i = 0; i < 3; i++) {

View File

@ -26,7 +26,6 @@ import org.apache.lucene.util.BytesRef;
import java.io.IOException;
import java.util.Collection;
import java.util.Random;
public class TestSegmentMerger extends LuceneTestCase {
//The variables for the new merged segment
@ -49,10 +48,9 @@ public class TestSegmentMerger extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
Random random = newRandom();
mergedDir = newDirectory(random);
merge1Dir = newDirectory(random);
merge2Dir = newDirectory(random);
mergedDir = newDirectory();
merge1Dir = newDirectory();
merge2Dir = newDirectory();
DocHelper.setupDoc(doc1);
SegmentInfo info1 = DocHelper.writeDoc(merge1Dir, doc1);
DocHelper.setupDoc(doc2);

View File

@ -43,7 +43,7 @@ public class TestSegmentReader extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
dir = newDirectory(newRandom());
dir = newDirectory();
DocHelper.setupDoc(testDoc);
SegmentInfo info = DocHelper.writeDoc(dir, testDoc);
reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);

View File

@ -25,13 +25,11 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.util.BytesRef;
import java.io.IOException;
import java.util.Random;
public class TestSegmentTermDocs extends LuceneTestCase {
private Document testDoc = new Document();
private Directory dir;
private SegmentInfo info;
private Random random;
public TestSegmentTermDocs(String s) {
super(s);
@ -40,8 +38,7 @@ public class TestSegmentTermDocs extends LuceneTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
dir = newDirectory();
DocHelper.setupDoc(testDoc);
info = DocHelper.writeDoc(dir, testDoc);
}
@ -111,8 +108,8 @@ public class TestSegmentTermDocs extends LuceneTestCase {
}
public void testSkipTo(int indexDivisor) throws IOException {
Directory dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
Term ta = new Term("content","aaa");
for(int i = 0; i < 10; i++)

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
@ -33,13 +32,11 @@ import org.apache.lucene.store.Directory;
public class TestSegmentTermEnum extends LuceneTestCase {
Directory dir;
Random random;
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
dir = newDirectory(random);
dir = newDirectory();
}
@Override
@ -51,7 +48,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {
public void testTermEnum() throws IOException {
IndexWriter writer = null;
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()));
// ADD 100 documents with term : aaa
// add 100 documents with terms: aaa bbb
@ -67,7 +64,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {
verifyDocFreq();
// merge segments by optimizing the index
writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));
writer.optimize();
writer.close();
@ -77,7 +74,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {
public void testPrevTermAtEnd() throws IOException
{
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));
addDoc(writer, "aaa bbb");
writer.close();
SegmentReader reader = SegmentReader.getOnlySegmentReader(dir);

View File

@ -22,7 +22,6 @@ import org.apache.lucene.index.SnapshotDeletionPolicy;
import org.apache.lucene.util.LuceneTestCaseJ4;
import org.apache.lucene.util.ThreadInterruptedException;
import org.apache.lucene.util._TestUtil;
import org.junit.Before;
import org.junit.Test;
//
@ -31,18 +30,10 @@ import org.junit.Test;
//
public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
protected Random random;
public static final String INDEX_PATH = "test.snapshots";
@Before
@Override
public void setUp() throws Exception {
super.setUp();
random = newRandom();
}
protected IndexWriterConfig getConfig(Random random, IndexDeletionPolicy dp) {
IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer());
IndexWriterConfig conf = newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer());
if (dp != null) {
conf.setIndexDeletionPolicy(dp);
}
@ -101,7 +92,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
_TestUtil.rmDir(dir);
}
Directory dir2 = newDirectory(random);
Directory dir2 = newDirectory();
runTest(random, dir2);
dir2.close();
}
@ -111,7 +102,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
final long stopTime = System.currentTimeMillis() + 1000;
SnapshotDeletionPolicy dp = getDeletionPolicy();
final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(dp)
.setMaxBufferedDocs(2));
writer.commit();
@ -239,7 +230,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
SnapshotDeletionPolicy sdp = getDeletionPolicy();
// Create 3 snapshots: snapshot0, snapshot1, snapshot2
Directory dir = newDirectory(random);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");
writer.close();
@ -269,7 +260,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
@Test
public void testMultiThreadedSnapshotting() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
final SnapshotDeletionPolicy sdp = getDeletionPolicy();
final IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
@ -314,7 +305,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
@Test
public void testRollbackToOldSnapshot() throws Exception {
int numSnapshots = 2;
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");
@ -336,7 +327,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
@Test
public void testReleaseSnapshot() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
prepareIndexAndSnapshots(sdp, writer, 1, "snapshot");
@ -368,7 +359,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
// Tests the ability to construct a SDP from existing snapshots, and
// asserts that those snapshots/commit points are protected.
int numSnapshots = 3;
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");
@ -386,7 +377,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
@Test
public void testSnapshotLastCommitTwice() throws Exception {
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
writer.addDocument(new Document());
@ -415,7 +406,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {
public void testMissingCommits() throws Exception {
// Tests the behavior of SDP when commits that are given at ctor are missing
// on onInit().
Directory dir = newDirectory(random);
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
writer.addDocument(new Document());

View File

@ -23,12 +23,9 @@ import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.*;
import java.util.Random;
import java.io.File;
public class TestStressIndexing extends MultiCodecTestCase {
private Random RANDOM;
private static abstract class TimedThread extends Thread {
volatile boolean failed;
int count;
@ -82,7 +79,7 @@ public class TestStressIndexing extends MultiCodecTestCase {
// Add 10 docs:
for(int j=0; j<10; j++) {
Document d = new Document();
int n = RANDOM.nextInt();
int n = random.nextInt();
d.add(new Field("id", Integer.toString(nextID++), Field.Store.YES, Field.Index.NOT_ANALYZED));
d.add(new Field("contents", English.intToEnglish(n), Field.Store.NO, Field.Index.ANALYZED));
writer.addDocument(d);
@ -118,7 +115,7 @@ public class TestStressIndexing extends MultiCodecTestCase {
stress test.
*/
public void runStressTest(Directory directory, MergeScheduler mergeScheduler) throws Exception {
IndexWriter modifier = new IndexWriter(directory, newIndexWriterConfig(RANDOM,
IndexWriter modifier = new IndexWriter(directory, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(10).setMergeScheduler(
mergeScheduler));
@ -166,10 +163,8 @@ public class TestStressIndexing extends MultiCodecTestCase {
FSDirectory.
*/
public void testStressIndexAndSearching() throws Exception {
RANDOM = newRandom();
// With ConcurrentMergeScheduler, in RAMDir
Directory directory = newDirectory(RANDOM);
Directory directory = newDirectory();
runStressTest(directory, new ConcurrentMergeScheduler());
directory.close();

View File

@ -44,8 +44,6 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
static int maxBufferedDocs=3;
static int seed=0;
Random r;
public class MockIndexWriter extends IndexWriter {
public MockIndexWriter(Directory dir, IndexWriterConfig conf) throws IOException {
@ -55,36 +53,34 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
@Override
boolean testPoint(String name) {
// if (name.equals("startCommit")) {
if (r.nextInt(4) == 2)
if (random.nextInt(4) == 2)
Thread.yield();
return true;
}
}
public void testRandomIWReader() throws Throwable {
r = newRandom();
Directory dir = newDirectory(r);
Directory dir = newDirectory();
// TODO: verify equals using IW.getReader
DocsAndWriter dw = indexRandomIWReader(5, 3, 100, dir);
IndexReader reader = dw.writer.getReader();
dw.writer.commit();
verifyEquals(r, reader, dir, "id");
verifyEquals(random, reader, dir, "id");
reader.close();
dw.writer.close();
dir.close();
}
public void testRandom() throws Throwable {
r = newRandom();
Directory dir1 = newDirectory(r);
Directory dir1 = newDirectory();
// dir1 = FSDirectory.open("foofoofoo");
Directory dir2 = newDirectory(r);
Directory dir2 = newDirectory();
// mergeFactor=2; maxBufferedDocs=2; Map docs = indexRandom(1, 3, 2, dir1);
int maxThreadStates = 1+r.nextInt(10);
boolean doReaderPooling = r.nextBoolean();
int maxThreadStates = 1+random.nextInt(10);
boolean doReaderPooling = random.nextBoolean();
Map<String,Document> docs = indexRandom(5, 3, 100, dir1, maxThreadStates, doReaderPooling);
indexSerial(r, docs, dir2);
indexSerial(random, docs, dir2);
// verifying verify
// verifyEquals(dir1, dir1, "id");
@ -98,25 +94,23 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
public void testMultiConfig() throws Throwable {
// test lots of smaller different params together
r = newRandom();
int num = 3 * RANDOM_MULTIPLIER;
for (int i = 0; i < num; i++) { // increase iterations for better testing
sameFieldOrder=r.nextBoolean();
mergeFactor=r.nextInt(3)+2;
maxBufferedDocs=r.nextInt(3)+2;
int maxThreadStates = 1+r.nextInt(10);
boolean doReaderPooling = r.nextBoolean();
sameFieldOrder=random.nextBoolean();
mergeFactor=random.nextInt(3)+2;
maxBufferedDocs=random.nextInt(3)+2;
int maxThreadStates = 1+random.nextInt(10);
boolean doReaderPooling = random.nextBoolean();
seed++;
int nThreads=r.nextInt(5)+1;
int iter=r.nextInt(5)+1;
int range=r.nextInt(20)+1;
Directory dir1 = newDirectory(r);
Directory dir2 = newDirectory(r);
int nThreads=random.nextInt(5)+1;
int iter=random.nextInt(5)+1;
int range=random.nextInt(20)+1;
Directory dir1 = newDirectory();
Directory dir2 = newDirectory();
Map<String,Document> docs = indexRandom(nThreads, iter, range, dir1, maxThreadStates, doReaderPooling);
//System.out.println("TEST: index serial");
indexSerial(r, docs, dir2);
indexSerial(random, docs, dir2);
//System.out.println("TEST: verify");
verifyEquals(dir1, dir2, "id");
dir1.close();
@ -144,7 +138,7 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
public DocsAndWriter indexRandomIWReader(int nThreads, int iterations, int range, Directory dir) throws IOException, InterruptedException {
Map<String,Document> docs = new HashMap<String,Document>();
IndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(r,
IndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setRAMBufferSizeMB(
0.1).setMaxBufferedDocs(maxBufferedDocs));
w.commit();
@ -197,7 +191,7 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
boolean doReaderPooling) throws IOException, InterruptedException {
Map<String,Document> docs = new HashMap<String,Document>();
for(int iter=0;iter<3;iter++) {
IndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(r,
IndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE)
.setRAMBufferSizeMB(0.1).setMaxBufferedDocs(maxBufferedDocs).setMaxThreadStates(maxThreadStates)
.setReaderPooling(doReaderPooling));
@ -242,7 +236,7 @@ public class TestStressIndexing2 extends MultiCodecTestCase {
public static void indexSerial(Random random, Map<String,Document> docs, Directory dir) throws IOException {
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
IndexWriter w = new IndexWriter(dir, LuceneTestCaseJ4.newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));
// index all docs in a single thread
Iterator<Document> iter = docs.values().iterator();

View File

@ -22,7 +22,6 @@ import java.io.Reader;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.SortedSet;
import org.apache.lucene.analysis.Analyzer;
@ -94,9 +93,8 @@ public class TestTermVectorsReader extends LuceneTestCase {
}
Arrays.sort(tokens);
Random random = newRandom();
dir = newDirectory(random);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MyAnalyzer()).setMaxBufferedDocs(-1));
dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MyAnalyzer()).setMaxBufferedDocs(-1));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);

Some files were not shown because too many files have changed in this diff Show More