mirror of https://github.com/apache/lucene.git
live setters will be tested or die
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1593383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
930a6d4e04
commit
31a05cebdd
|
@ -105,10 +105,12 @@ public class RandomIndexWriter implements Closeable {
|
|||
* @see IndexWriter#addDocument(org.apache.lucene.index.IndexDocument)
|
||||
*/
|
||||
public <T extends IndexableField> void addDocument(final IndexDocument doc) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
addDocument(doc, w.getAnalyzer());
|
||||
}
|
||||
|
||||
public <T extends IndexableField> void addDocument(final IndexDocument doc, Analyzer a) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
if (r.nextInt(5) == 3) {
|
||||
// TODO: maybe, we should simply buffer up added docs
|
||||
// (but we need to clone them), and only when
|
||||
|
@ -150,6 +152,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
private void maybeCommit() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
if (docCount++ == flushAt) {
|
||||
if (LuceneTestCase.VERBOSE) {
|
||||
System.out.println("RIW.add/updateDocument: now doing a commit at docCount=" + docCount);
|
||||
|
@ -164,11 +167,13 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
public void addDocuments(Iterable<? extends IndexDocument> docs) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.addDocuments(docs);
|
||||
maybeCommit();
|
||||
}
|
||||
|
||||
public void updateDocuments(Term delTerm, Iterable<? extends IndexDocument> docs) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.updateDocuments(delTerm, docs);
|
||||
maybeCommit();
|
||||
}
|
||||
|
@ -178,6 +183,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
* @see IndexWriter#updateDocument(Term, org.apache.lucene.index.IndexDocument)
|
||||
*/
|
||||
public <T extends IndexableField> void updateDocument(Term t, final IndexDocument doc) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
if (r.nextInt(5) == 3) {
|
||||
w.updateDocuments(t, new Iterable<IndexDocument>() {
|
||||
|
||||
|
@ -214,30 +220,37 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
public void addIndexes(Directory... dirs) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.addIndexes(dirs);
|
||||
}
|
||||
|
||||
public void addIndexes(IndexReader... readers) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.addIndexes(readers);
|
||||
}
|
||||
|
||||
public void updateNumericDocValue(Term term, String field, Long value) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.updateNumericDocValue(term, field, value);
|
||||
}
|
||||
|
||||
public void updateBinaryDocValue(Term term, String field, BytesRef value) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.updateBinaryDocValue(term, field, value);
|
||||
}
|
||||
|
||||
public void deleteDocuments(Term term) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.deleteDocuments(term);
|
||||
}
|
||||
|
||||
public void deleteDocuments(Query q) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.deleteDocuments(q);
|
||||
}
|
||||
|
||||
public void commit() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.commit();
|
||||
}
|
||||
|
||||
|
@ -254,6 +267,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
public DirectoryReader getReader() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
return getReader(true);
|
||||
}
|
||||
|
||||
|
@ -261,10 +275,12 @@ public class RandomIndexWriter implements Closeable {
|
|||
private boolean doRandomForceMergeAssert = true;
|
||||
|
||||
public void forceMergeDeletes(boolean doWait) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.forceMergeDeletes(doWait);
|
||||
}
|
||||
|
||||
public void forceMergeDeletes() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.forceMergeDeletes();
|
||||
}
|
||||
|
||||
|
@ -298,6 +314,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
}
|
||||
|
||||
public DirectoryReader getReader(boolean applyDeletions) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
getReaderCalled = true;
|
||||
if (r.nextInt(20) == 2) {
|
||||
doRandomForceMerge();
|
||||
|
@ -329,6 +346,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
// if someone isn't using getReader() API, we want to be sure to
|
||||
// forceMerge since presumably they might open a reader on the dir.
|
||||
if (getReaderCalled == false && r.nextInt(8) == 2) {
|
||||
|
@ -342,6 +360,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
* @see IndexWriter#shutdown()
|
||||
*/
|
||||
public void shutdown() throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
// if someone isn't using getReader() API, we want to be sure to
|
||||
// forceMerge since presumably they might open a reader on the dir.
|
||||
if (getReaderCalled == false && r.nextInt(8) == 2) {
|
||||
|
@ -358,6 +377,7 @@ public class RandomIndexWriter implements Closeable {
|
|||
* @see IndexWriter#forceMerge(int)
|
||||
*/
|
||||
public void forceMerge(int maxSegmentCount) throws IOException {
|
||||
LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig());
|
||||
w.forceMerge(maxSegmentCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ import org.apache.lucene.index.Fields;
|
|||
import org.apache.lucene.index.IndexReader.ReaderClosedListener;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.LiveIndexWriterConfig;
|
||||
import org.apache.lucene.index.LogByteSizeMergePolicy;
|
||||
import org.apache.lucene.index.LogDocMergePolicy;
|
||||
import org.apache.lucene.index.LogMergePolicy;
|
||||
|
@ -1030,6 +1031,60 @@ public abstract class LuceneTestCase extends Assert {
|
|||
logmp.setMergeFactor(mergeFactor);
|
||||
return logmp;
|
||||
}
|
||||
|
||||
// if you want it in LiveIndexWriterConfig: it must and will be tested here.
|
||||
public static void maybeChangeLiveIndexWriterConfig(Random r, LiveIndexWriterConfig c) {
|
||||
if (rarely(r)) {
|
||||
// change flush parameters:
|
||||
// this is complicated because the api requires you "invoke setters in a magical order!"
|
||||
boolean flushByRam = r.nextBoolean();
|
||||
if (flushByRam) {
|
||||
c.setRAMBufferSizeMB(TestUtil.nextInt(r, 1, 10));
|
||||
c.setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH);
|
||||
} else {
|
||||
if (rarely(r)) {
|
||||
// crazy value
|
||||
c.setMaxBufferedDocs(TestUtil.nextInt(r, 2, 15));
|
||||
} else {
|
||||
// reasonable value
|
||||
c.setMaxBufferedDocs(TestUtil.nextInt(r, 16, 1000));
|
||||
}
|
||||
c.setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
if (rarely(r)) {
|
||||
// change buffered deletes parameters
|
||||
boolean limitBufferedDeletes = r.nextBoolean();
|
||||
if (limitBufferedDeletes) {
|
||||
c.setMaxBufferedDeleteTerms(TestUtil.nextInt(r, 1, 1000));
|
||||
} else {
|
||||
c.setMaxBufferedDeleteTerms(IndexWriterConfig.DISABLE_AUTO_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
if (rarely(r)) {
|
||||
// change warmer parameters
|
||||
if (r.nextBoolean()) {
|
||||
c.setMergedSegmentWarmer(new SimpleMergedSegmentWarmer(c.getInfoStream()));
|
||||
} else {
|
||||
c.setMergedSegmentWarmer(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (rarely(r)) {
|
||||
// change CFS flush parameters
|
||||
c.setUseCompoundFile(r.nextBoolean());
|
||||
}
|
||||
|
||||
if (rarely(r)) {
|
||||
// change merge integrity check parameters
|
||||
c.setCheckIntegrityAtMerge(r.nextBoolean());
|
||||
}
|
||||
|
||||
// TODO: mergepolicy, mergescheduler, etc have mutable state on indexwriter
|
||||
// every setter must be tested
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new Directory instance. Use this when the test does not
|
||||
|
|
Loading…
Reference in New Issue