You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/10/23 11:27:34 UTC
svn commit: r1633779 - in /lucene/dev/branches/lucene_solr_4_10: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/index/
lucene/core/src/test/org/apache/lucene/
lucene/core/src/test/org/apache/lucene/index/ lucene/test-framework/
lucene/t...
Author: mikemccand
Date: Thu Oct 23 09:27:33 2014
New Revision: 1633779
URL: http://svn.apache.org/r1633779
Log:
LUCENE-6019: detect when DocValuesType illegally changes; add -Dtests.asserts=true|false
Modified:
lucene/dev/branches/lucene_solr_4_10/ (props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/ (props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/common-build.xml (contents, props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/core/ (props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/SegmentDocValues.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumer.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/TestAssertions.java
lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/ (props changed)
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java
lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleAssertionsRequired.java
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt Thu Oct 23 09:27:33 2014
@@ -11,6 +11,11 @@ Bug fixes
work across multi-valued fields. Previously some cases across multi-valued
fields would happily create a corrupt index. (Dawid Weiss, Robert Muir)
+* LUCENE-6019: Detect when DocValuesType illegally changes for the
+ same field name. Also added -Dtests.asserts=true|false so we can
+ run tests with and without assertions. (Simon Willnauer, Robert
+ Muir, Mike McCandless).
+
======================= Lucene 4.10.1 ======================
Bug fixes
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/common-build.xml?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/common-build.xml (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/common-build.xml Thu Oct 23 09:27:33 2014
@@ -130,13 +130,17 @@
<property name="tests.monster" value="false" />
<property name="tests.slow" value="true" />
<property name="tests.cleanthreads.sysprop" value="perMethod"/>
- <property name="tests.asserts.gracious" value="false"/>
<property name="tests.verbose" value="false"/>
<property name="tests.infostream" value="${tests.verbose}"/>
<property name="tests.filterstacks" value="true"/>
<property name="tests.luceneMatchVersion" value="${version.base}"/>
+ <property name="tests.asserts" value="true" />
- <condition property="tests.heapsize" value="768M">
+ <condition property="tests.asserts.args" value="-ea -esa" else="">
+ <istrue value="${tests.asserts}"/>
+ </condition>
+
+ <condition property="tests.heapsize" value="768M" else="512M">
<isset property="run.clover"/>
</condition>
<property name="tests.heapsize" value="512M"/>
@@ -968,16 +972,11 @@
<classpath refid="@{junit.classpath}"/>
<classpath refid="clover.classpath" />
- <!-- Assertions. -->
- <assertions>
- <enable package="org.apache.lucene"/>
- <enable package="org.apache.solr"/>
- </assertions>
-
<!-- JVM arguments and system properties. -->
<jvmarg line="${args}"/>
<jvmarg line="${tests.heapdump.args}"/>
<jvmarg line="${tests.clover.args}"/>
+ <jvmarg line="${tests.asserts.args}"/>
<!-- set the number of times tests should run -->
<sysproperty key="tests.iters" value="${tests.iters}"/>
@@ -1015,7 +1014,7 @@
<sysproperty key="tests.slow" value="@{tests.slow}"/>
<!-- set whether tests framework should not require java assertions enabled -->
- <sysproperty key="tests.asserts.gracious" value="${tests.asserts.gracious}"/>
+ <sysproperty key="tests.asserts" value="${tests.asserts}"/>
<!-- TODO: create propertyset for test properties, so each project can have its own set -->
<sysproperty key="tests.multiplier" value="@{tests.multiplier}"/>
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java Thu Oct 23 09:27:33 2014
@@ -403,12 +403,12 @@ final class DefaultIndexingChain extends
boolean hasDocValues = fp.fieldInfo.hasDocValues();
- // This will throw an exc if the caller tried to
- // change the DV type for the field:
- fp.fieldInfo.setDocValuesType(dvType);
if (hasDocValues == false) {
+ // This will throw an exc if the caller tried to
+ // change the DV type for the field:
fieldInfos.globalFieldNumbers.setDocValuesType(fp.fieldInfo.number, fp.fieldInfo.name, dvType);
}
+ fp.fieldInfo.setDocValuesType(dvType);
int docID = docState.docID;
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java Thu Oct 23 09:27:33 2014
@@ -77,9 +77,8 @@ class DocumentsWriterPerThread {
this.infoStream = infoStream;
}
- // Only called by asserts
- public boolean testPoint(String name) {
- return docWriter.testPoint(name);
+ public void testPoint(String name) {
+ docWriter.testPoint(name);
}
public void clear() {
@@ -202,11 +201,10 @@ class DocumentsWriterPerThread {
return retval;
}
- final boolean testPoint(String message) {
+ final void testPoint(String message) {
if (infoStream.isEnabled("TP")) {
infoStream.message("TP", message);
}
- return true;
}
/** Anything that will add N docs to the index should reserve first to
@@ -220,7 +218,7 @@ class DocumentsWriterPerThread {
}
public void updateDocument(Iterable<? extends IndexableField> doc, Analyzer analyzer, Term delTerm) throws IOException {
- assert testPoint("DocumentsWriterPerThread addDocument start");
+ testPoint("DocumentsWriterPerThread addDocument start");
assert deleteQueue != null;
docState.doc = doc;
docState.analyzer = analyzer;
@@ -258,7 +256,7 @@ class DocumentsWriterPerThread {
}
public int updateDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer analyzer, Term delTerm) throws IOException {
- assert testPoint("DocumentsWriterPerThread addDocuments start");
+ testPoint("DocumentsWriterPerThread addDocuments start");
assert deleteQueue != null;
docState.analyzer = analyzer;
if (INFO_VERBOSE && infoStream.isEnabled("DWPT")) {
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java Thu Oct 23 09:27:33 2014
@@ -70,9 +70,9 @@ final class DocumentsWriterStallControl
if (stalled) { // react on the first wakeup call!
// don't loop here, higher level logic will re-stall!
try {
- assert incWaiters();
+ incWaiters();
wait();
- assert decrWaiters();
+ decrWaiters();
} catch (InterruptedException e) {
throw new ThreadInterruptedException(e);
}
@@ -86,17 +86,16 @@ final class DocumentsWriterStallControl
}
- private boolean incWaiters() {
+ private void incWaiters() {
numWaiting++;
assert waiting.put(Thread.currentThread(), Boolean.TRUE) == null;
-
- return numWaiting > 0;
+ assert numWaiting > 0;
}
- private boolean decrWaiters() {
+ private void decrWaiters() {
numWaiting--;
assert waiting.remove(Thread.currentThread()) != null;
- return numWaiting >= 0;
+ assert numWaiting >= 0;
}
synchronized boolean hasBlocked() { // for tests
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java Thu Oct 23 09:27:33 2014
@@ -220,11 +220,17 @@ public class FieldInfos implements Itera
return fieldNumber.intValue();
}
- // used by assert
- synchronized boolean containsConsistent(Integer number, String name, DocValuesType dvType) {
- return name.equals(numberToName.get(number))
- && number.equals(nameToNumber.get(name)) &&
- (dvType == null || docValuesType.get(name) == null || dvType == docValuesType.get(name));
+ synchronized void verifyConsistent(Integer number, String name, DocValuesType dvType) {
+ if (name.equals(numberToName.get(number)) == false) {
+ throw new IllegalArgumentException("field number " + number + " is already mapped to field name \"" + numberToName.get(number) + "\", not \"" + name + "\"");
+ }
+ if (number.equals(nameToNumber.get(name)) == false) {
+ throw new IllegalArgumentException("field name \"" + name + "\" is already mapped to field number \"" + nameToNumber.get(name) + "\", not \"" + number + "\"");
+ }
+ DocValuesType currentDVType = docValuesType.get(name);
+ if (dvType != null && currentDVType != null && dvType != currentDVType) {
+ throw new IllegalArgumentException("cannot change DocValues type from " + currentDVType + " to " + dvType + " for field \"" + name + "\"");
+ }
}
/**
@@ -248,7 +254,7 @@ public class FieldInfos implements Itera
}
synchronized void setDocValuesType(int number, String name, DocValuesType dvType) {
- assert containsConsistent(number, name, dvType);
+ verifyConsistent(number, name, dvType);
docValuesType.put(name, dvType);
}
}
@@ -304,20 +310,22 @@ public class FieldInfos implements Itera
final int fieldNumber = globalFieldNumbers.addOrGet(name, preferredFieldNumber, docValues);
fi = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads, indexOptions, docValues, normType, -1, null);
assert !byName.containsKey(fi.name);
- assert globalFieldNumbers.containsConsistent(Integer.valueOf(fi.number), fi.name, fi.getDocValuesType());
+ globalFieldNumbers.verifyConsistent(Integer.valueOf(fi.number), fi.name, fi.getDocValuesType());
byName.put(fi.name, fi);
} else {
fi.update(isIndexed, storeTermVector, omitNorms, storePayloads, indexOptions);
if (docValues != null) {
- // only pay the synchronization cost if fi does not already have a DVType
+ // Only pay the synchronization cost if fi does not already have a DVType
boolean updateGlobal = !fi.hasDocValues();
- fi.setDocValuesType(docValues); // this will also perform the consistency check.
if (updateGlobal) {
- // must also update docValuesType map so it's
- // aware of this field's DocValueType
+ // Must also update docValuesType map so it's
+ // aware of this field's DocValueType. This will throw IllegalArgumentException if
+ // an illegal type change was attempted.
globalFieldNumbers.setDocValuesType(fi.number, name, docValues);
}
+
+ fi.setDocValuesType(docValues); // this will also perform the consistency check.
}
if (!fi.omitsNorms() && normType != null) {
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java Thu Oct 23 09:27:33 2014
@@ -107,8 +107,6 @@ final class FreqProxTermsWriterPerField
void newTerm(final int termID) {
// First time we're seeing this term since the last
// flush
- assert docState.testPoint("FreqProxTermsWriterPerField.newTerm start");
-
final FreqProxPostingsArray postings = freqProxPostingsArray;
postings.lastDocIDs[termID] = docState.docID;
@@ -133,9 +131,6 @@ final class FreqProxTermsWriterPerField
@Override
void addTerm(final int termID) {
-
- assert docState.testPoint("FreqProxTermsWriterPerField.addTerm start");
-
final FreqProxPostingsArray postings = freqProxPostingsArray;
assert !hasFreq || postings.termFreqs[termID] > 0;
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java Thu Oct 23 09:27:33 2014
@@ -2126,7 +2126,7 @@ public class IndexWriter implements Clos
infoStream.message("IW", "rollback: infos=" + segString(segmentInfos));
}
- assert testPoint("rollback before checkpoint");
+ testPoint("rollback before checkpoint");
// Ask deleter to locate unreferenced files & remove
// them:
@@ -2925,7 +2925,7 @@ public class IndexWriter implements Clos
}
doBeforeFlush();
- assert testPoint("startDoFlush");
+ testPoint("startDoFlush");
SegmentInfos toCommit = null;
boolean anySegmentsFlushed = false;
@@ -3211,7 +3211,7 @@ public class IndexWriter implements Clos
}
doBeforeFlush();
- assert testPoint("startDoFlush");
+ testPoint("startDoFlush");
boolean success = false;
try {
@@ -3303,9 +3303,7 @@ public class IndexWriter implements Clos
// for testing only
DocumentsWriter getDocsWriter() {
- boolean test = false;
- assert test = true;
- return test ? docWriter : null;
+ return docWriter;
}
/** Expert: Return the number of documents currently
@@ -3390,7 +3388,7 @@ public class IndexWriter implements Clos
*/
synchronized private ReadersAndUpdates commitMergedDeletesAndUpdates(MergePolicy.OneMerge merge, MergeState mergeState) throws IOException {
- assert testPoint("startCommitMergeDeletes");
+ testPoint("startCommitMergeDeletes");
final List<SegmentCommitInfo> sourceSegments = merge.segments;
@@ -3575,7 +3573,7 @@ public class IndexWriter implements Clos
synchronized private boolean commitMerge(MergePolicy.OneMerge merge, MergeState mergeState) throws IOException {
- assert testPoint("startCommitMerge");
+ testPoint("startCommitMerge");
if (tragedy != null) {
throw new IllegalStateException("this writer hit an unrecoverable error; cannot complete merge", tragedy);
@@ -3919,7 +3917,7 @@ public class IndexWriter implements Clos
synchronized private void _mergeInit(MergePolicy.OneMerge merge) throws IOException {
- assert testPoint("startMergeInit");
+ testPoint("startMergeInit");
assert merge.registerDone;
assert merge.maxNumSegments == -1 || merge.maxNumSegments > 0;
@@ -4158,9 +4156,9 @@ public class IndexWriter implements Clos
// we pass merge.getMergeReaders() instead of merge.readers to allow the
// OneMerge to return a view over the actual segments to merge
final SegmentMerger merger = new SegmentMerger(merge.getMergeReaders(),
- merge.info.info, infoStream, dirWrapper, config.getTermIndexInterval(),
- checkAbort, globalFieldNumberMap,
- context, config.getCheckIntegrityAtMerge());
+ merge.info.info, infoStream, dirWrapper, config.getTermIndexInterval(),
+ checkAbort, globalFieldNumberMap,
+ context, config.getCheckIntegrityAtMerge());
merge.checkAborted(directory);
@@ -4452,7 +4450,7 @@ public class IndexWriter implements Clos
* it. */
private void startCommit(final SegmentInfos toSync) throws IOException {
- assert testPoint("startStartCommit");
+ testPoint("startStartCommit");
assert pendingCommit == null;
if (tragedy != null) {
@@ -4488,13 +4486,13 @@ public class IndexWriter implements Clos
assert filesExist(toSync);
}
- assert testPoint("midStartCommit");
+ testPoint("midStartCommit");
boolean pendingCommitSet = false;
try {
- assert testPoint("midStartCommit2");
+ testPoint("midStartCommit2");
synchronized(this) {
@@ -4532,7 +4530,7 @@ public class IndexWriter implements Clos
infoStream.message("IW", "done all syncs: " + filesToSync);
}
- assert testPoint("midStartCommitSuccess");
+ testPoint("midStartCommitSuccess");
} finally {
synchronized(this) {
@@ -4556,7 +4554,7 @@ public class IndexWriter implements Clos
} catch (OutOfMemoryError oom) {
tragicEvent(oom, "startCommit");
}
- assert testPoint("finishStartCommit");
+ testPoint("finishStartCommit");
}
/**
@@ -4633,7 +4631,7 @@ public class IndexWriter implements Clos
IOUtils.reThrowUnchecked(tragedy);
}
- // Used only by assert for testing. Current points:
+ // Used for testing. Current points:
// startDoFlush
// startCommitMerge
// startStartCommit
@@ -4644,11 +4642,10 @@ public class IndexWriter implements Clos
// startCommitMergeDeletes
// startMergeInit
// DocumentsWriter.ThreadState.init start
- private final boolean testPoint(String message) {
+ private final void testPoint(String message) {
if (infoStream.isEnabled("TP")) {
infoStream.message("TP", message);
}
- return true;
}
synchronized boolean nrtIsCurrent(SegmentInfos infos) {
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/SegmentDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/SegmentDocValues.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/SegmentDocValues.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/SegmentDocValues.java Thu Oct 23 09:27:33 2014
@@ -1,17 +1,5 @@
package org.apache.lucene.index;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.lucene.codecs.DocValuesFormat;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.RefCount;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -29,6 +17,18 @@ import org.apache.lucene.util.RefCount;
* limitations under the License.
*/
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.codecs.DocValuesFormat;
+import org.apache.lucene.codecs.DocValuesProducer;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.RefCount;
+
/**
* Manages the {@link DocValuesProducer} held by {@link SegmentReader} and
* keeps track of their reference counting.
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumer.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumer.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumer.java Thu Oct 23 09:27:33 2014
@@ -93,8 +93,6 @@ final class TermVectorsConsumer extends
@Override
void finishDocument() throws IOException {
- assert docWriter.testPoint("TermVectorsTermsWriter.finishDocument start");
-
if (!hasVectors) {
return;
}
@@ -119,7 +117,6 @@ final class TermVectorsConsumer extends
super.reset();
resetFields();
- assert docWriter.testPoint("TermVectorsTermsWriter.finishDocument end");
}
@Override
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java Thu Oct 23 09:27:33 2014
@@ -63,8 +63,6 @@ final class TermVectorsConsumerPerField
doVectors = false;
- assert docState.testPoint("TermVectorsTermsWriterPerField.finish start");
-
final int numPostings = bytesHash.size();
final BytesRef flushTerm = termsWriter.flushTerm;
@@ -226,7 +224,6 @@ final class TermVectorsConsumerPerField
@Override
void newTerm(final int termID) {
- assert docState.testPoint("TermVectorsTermsWriterPerField.newTerm start");
TermVectorsPostingsArray postings = termVectorsPostingsArray;
postings.freqs[termID] = 1;
@@ -238,7 +235,6 @@ final class TermVectorsConsumerPerField
@Override
void addTerm(final int termID) {
- assert docState.testPoint("TermVectorsTermsWriterPerField.addTerm start");
TermVectorsPostingsArray postings = termVectorsPostingsArray;
postings.freqs[termID]++;
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/TestAssertions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/TestAssertions.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/TestAssertions.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/TestAssertions.java Thu Oct 23 09:27:33 2014
@@ -17,8 +17,8 @@ package org.apache.lucene;
* limitations under the License.
*/
-import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.util.LuceneTestCase;
/**
* validate that assertions are enabled during tests
@@ -43,13 +43,13 @@ public class TestAssertions extends Luce
public void testTokenStreams() {
new TestTokenStream1();
new TestTokenStream2();
- boolean doFail = false;
try {
new TestTokenStream3();
- doFail = true;
+ if (assertsAreEnabled) {
+ fail("TestTokenStream3 should fail assertion");
+ }
} catch (AssertionError e) {
// expected
}
- assertFalse("TestTokenStream3 should fail assertion", doFail);
}
}
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java Thu Oct 23 09:27:33 2014
@@ -234,6 +234,7 @@ public class TestDocValuesIndexing exten
doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
try {
w.addDocument(doc);
+ fail("didn't hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
@@ -256,6 +257,7 @@ public class TestDocValuesIndexing exten
doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
try {
w.addDocument(doc);
+ fail("didn't hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
@@ -424,6 +426,7 @@ public class TestDocValuesIndexing exten
doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
try {
w.addDocument(doc);
+ fail("did not get expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
@@ -460,9 +463,83 @@ public class TestDocValuesIndexing exten
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
w = new IndexWriter(dir, iwc);
doc = new Document();
+ w.addDocument(doc);
+ w.close();
+ dir.close();
+ }
+
+ public void testMixedTypesAfterReopenAppend1() throws Exception {
+ Directory dir = newDirectory();
+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+ Document doc = new Document();
+ doc.add(new NumericDocValuesField("foo", 0));
+ w.addDocument(doc);
+ w.close();
+
+ w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+ doc = new Document();
doc.add(new SortedDocValuesField("foo", new BytesRef("hello")));
+ try {
+ w.addDocument(doc);
+ fail("did not get expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ w.close();
+ dir.close();
+ }
+
+ public void testMixedTypesAfterReopenAppend2() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))) ;
+ Document doc = new Document();
+ doc.add(new SortedSetDocValuesField("foo", new BytesRef("foo")));
w.addDocument(doc);
w.close();
+
+ doc = new Document();
+ w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+ doc.add(new StringField("foo", "bar", Field.Store.NO));
+ doc.add(new BinaryDocValuesField("foo", new BytesRef("foo")));
+ try {
+ // NOTE: this case follows a different code path inside
+ // DefaultIndexingChain/FieldInfos, because the field (foo)
+ // is first added without DocValues:
+ w.addDocument(doc);
+ fail("did not get expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ w.forceMerge(1);
+ w.close();
+ dir.close();
+ }
+
+ public void testMixedTypesAfterReopenAppend3() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random()))) ;
+ Document doc = new Document();
+ doc.add(new SortedSetDocValuesField("foo", new BytesRef("foo")));
+ w.addDocument(doc);
+ w.close();
+
+ doc = new Document();
+ w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+ doc.add(new StringField("foo", "bar", Field.Store.NO));
+ doc.add(new BinaryDocValuesField("foo", new BytesRef("foo")));
+ try {
+ // NOTE: this case follows a different code path inside
+ // DefaultIndexingChain/FieldInfos, because the field (foo)
+ // is first added without DocValues:
+ w.addDocument(doc);
+ fail("did not get expected exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ // Also add another document so there is a segment to write here:
+ w.addDocument(new Document());
+ w.forceMerge(1);
+ w.close();
dir.close();
}
@@ -532,6 +609,7 @@ public class TestDocValuesIndexing exten
try {
w.addIndexes(new Directory[] {dir2});
+ fail("didn't hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
@@ -539,6 +617,7 @@ public class TestDocValuesIndexing exten
IndexReader r = DirectoryReader.open(dir2);
try {
w.addIndexes(new IndexReader[] {r});
+ fail("didn't hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
@@ -823,5 +902,4 @@ public class TestDocValuesIndexing exten
dir.close();
}
-
}
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java Thu Oct 23 09:27:33 2014
@@ -55,7 +55,7 @@ public class RandomIndexWriter implement
public static IndexWriter mockIndexWriter(Directory dir, IndexWriterConfig conf, Random r) throws IOException {
// Randomly calls Thread.yield so we mixup thread scheduling
final Random random = new Random(r.nextLong());
- return mockIndexWriter(dir, conf, new TestPoint() {
+ return mockIndexWriter(dir, conf, new TestPoint() {
@Override
public void apply(String message) {
if (random.nextInt(4) == 2)
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Thu Oct 23 09:27:33 2014
@@ -814,7 +814,7 @@ public class MockDirectoryWrapper extend
extras += "\n\nThese files we had previously tried to delete, but couldn't: " + pendingDeletions;
}
- assert false : "unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles) + extras;
+ throw new RuntimeException("unreferenced files: before delete:\n " + Arrays.toString(startFiles) + "\n after delete:\n " + Arrays.toString(endFiles) + extras);
}
DirectoryReader ir1 = DirectoryReader.open(this);
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Thu Oct 23 09:27:33 2014
@@ -396,6 +396,8 @@ public abstract class LuceneTestCase ext
*/
public static final int RANDOM_MULTIPLIER = systemPropertyAsInt("tests.multiplier", 1);
+ public static final boolean TEST_ASSERTS_ENABLED = systemPropertyAsBoolean("tests.asserts", true);
+
/** TODO: javadoc? */
public static final String DEFAULT_LINE_DOCS_FILE = "europarl.lines.txt.gz";
@@ -2690,4 +2692,13 @@ public abstract class LuceneTestCase ext
}
}
}
+
+ /** True if assertions (-ea) are enabled (at least for this class). */
+ public static final boolean assertsAreEnabled;
+
+ static {
+ boolean enabled = false;
+ assert enabled = true; // Intentional side-effect!!!
+ assertsAreEnabled = enabled;
+ }
}
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java Thu Oct 23 09:27:33 2014
@@ -177,6 +177,12 @@ public final class RunListenerPrintRepro
}
}
+ if (LuceneTestCase.assertsAreEnabled) {
+ addVmOpt(b, "tests.asserts", "true");
+ } else {
+ addVmOpt(b, "tests.asserts", "false");
+ }
+
addVmOpt(b, "tests.file.encoding", System.getProperty("file.encoding"));
System.err.println(b.toString());
Modified: lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleAssertionsRequired.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleAssertionsRequired.java?rev=1633779&r1=1633778&r2=1633779&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleAssertionsRequired.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleAssertionsRequired.java Thu Oct 23 09:27:33 2014
@@ -31,11 +31,22 @@ public class TestRuleAssertionsRequired
@Override
public void evaluate() throws Throwable {
try {
- assert false;
- String msg = "Test class requires enabled assertions, enable globally (-ea)" +
- " or for Solr/Lucene subpackages only: " + description.getClassName();
- System.err.println(msg);
- throw new Exception(msg);
+ // Make sure -ea matches -Dtests.asserts, to catch accidental mis-use:
+ if (LuceneTestCase.assertsAreEnabled != LuceneTestCase.TEST_ASSERTS_ENABLED) {
+ String msg = "Assertions mismatch: ";
+ if (LuceneTestCase.assertsAreEnabled) {
+ msg += "-ea was specified";
+ } else {
+ msg += "-ea was not specified";
+ }
+ if (LuceneTestCase.TEST_ASSERTS_ENABLED) {
+ msg += " but -Dtests.asserts=true";
+ } else {
+ msg += " but -Dtests.asserts=false";
+ }
+ System.err.println(msg);
+ throw new Exception(msg);
+ }
} catch (AssertionError e) {
// Ok, enabled.
}