Skip to content

Commit

Permalink
LUCENE-3851: fix test bug; add asserts
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1297518 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mikemccand committed Mar 6, 2012
1 parent 11e3cc5 commit 936fa2c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Direct16(short[] values) {
}

public long get(final int index) {
assert index >= 0 && index < size();
return 0xFFFFL & values[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Direct32(int[] values) {
}

public long get(final int index) {
assert index >= 0 && index < size();
return 0xFFFFFFFFL & values[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public Direct64(long[] values) {
}

public long get(final int index) {
assert index >= 0 && index < size();
return values[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public Direct8(byte[] values) {
}

public long get(final int index) {
assert index >= 0 && index < size();
return 0xFFL & values[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private void updateCached() {
* @return the value at the given index.
*/
public long get(final int index) {
assert index >= 0 && index < size();
final long majorBitPos = (long)index * bitsPerValue;
final int elementPos = (int)(majorBitPos >>> BLOCK_BITS); // / BLOCK_SIZE
final int bitPos = (int)(majorBitPos & MOD_MASK); // % BLOCK_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private void updateCached() {
* @return the value at the given index.
*/
public long get(final int index) {
assert index >= 0 && index < size();
final long majorBitPos = (long)index * bitsPerValue;
final int elementPos = (int)(majorBitPos >>> BLOCK_BITS); // / BLOCK_SIZE
final int bitPos = (int)(majorBitPos & MOD_MASK); // % BLOCK_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@

import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.FieldInfosReader;
import org.apache.lucene.codecs.lucene3x.Lucene3xPostingsFormat;
import org.apache.lucene.codecs.lucene3x.PreFlexRWCodec;
import org.apache.lucene.codecs.lucene3x.SegmentTermEnum;
import org.apache.lucene.codecs.lucene3x.TermInfosReaderIndex;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.CorruptIndexException;
Expand Down Expand Up @@ -86,8 +81,8 @@ public static void beforeClass() throws Exception {
directory = newDirectory();

config.setCodec(new PreFlexRWCodec());
// turn off compound file, this test will open some index files directly.
LogMergePolicy mp = newLogMergePolicy();
// turn off compound file, this test will open some index files directly.
mp.setUseCompoundFile(false);
config.setMergePolicy(mp);

Expand Down Expand Up @@ -182,9 +177,16 @@ private Term findTermThatWouldBeAtIndex(SegmentTermEnum termEnum, int index) thr
int termPosition = index * termIndexInterval * indexDivisor;
for (int i = 0; i < termPosition; i++) {
// TODO: this test just uses random terms, so this is always possible
assumeTrue("ran out of terms.", termEnum.next());
assumeTrue("ran out of terms", termEnum.next());
}
return termEnum.term();
final Term term = termEnum.term();
// An indexed term is only written when the term after
// it exists, so, if the number of terms is 0 mod
// termIndexInterval, the last index term will not be
// written; so we require a term after this term
// as well:
assumeTrue("ran out of terms", termEnum.next());
return term;
}

private static void populate(Directory directory, IndexWriterConfig config) throws CorruptIndexException, LockObtainFailedException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ assert compareToLastTerm(fieldNumber, term) < 0 ||
assert ti.freqPointer >= lastTi.freqPointer: "freqPointer out of order (" + ti.freqPointer + " < " + lastTi.freqPointer + ")";
assert ti.proxPointer >= lastTi.proxPointer: "proxPointer out of order (" + ti.proxPointer + " < " + lastTi.proxPointer + ")";

if (!isIndex && size % indexInterval == 0)
if (!isIndex && size % indexInterval == 0) {
other.add(lastFieldNumber, lastTerm, lastTi); // add an index term

}
writeTerm(fieldNumber, term); // write term

output.writeVInt(ti.docFreq); // write doc freq
Expand Down

0 comments on commit 936fa2c

Please sign in to comment.