mirror of https://github.com/apache/lucene.git
close the linefiledocs always
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1326473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
776e1b4a98
commit
fffdb569d0
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
|||
import org.apache.lucene.analysis.tokenattributes.*;
|
||||
import org.apache.lucene.util.Attribute;
|
||||
import org.apache.lucene.util.AttributeImpl;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.LineFileDocs;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
@ -455,41 +456,45 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
|||
|
||||
final LineFileDocs docs = new LineFileDocs(random);
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
String text;
|
||||
try {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
String text;
|
||||
|
||||
if (random.nextInt(10) == 7) {
|
||||
// real data from linedocs
|
||||
text = docs.nextDoc().get("body");
|
||||
if (text.length() > maxWordLength) {
|
||||
if (random.nextInt(10) == 7) {
|
||||
// real data from linedocs
|
||||
text = docs.nextDoc().get("body");
|
||||
if (text.length() > maxWordLength) {
|
||||
|
||||
// Take a random slice from the text...:
|
||||
int startPos = random.nextInt(text.length() - maxWordLength);
|
||||
if (startPos > 0 && Character.isLowSurrogate(text.charAt(startPos))) {
|
||||
// Take care not to split up a surrogate pair:
|
||||
startPos--;
|
||||
assert Character.isHighSurrogate(text.charAt(startPos));
|
||||
// Take a random slice from the text...:
|
||||
int startPos = random.nextInt(text.length() - maxWordLength);
|
||||
if (startPos > 0 && Character.isLowSurrogate(text.charAt(startPos))) {
|
||||
// Take care not to split up a surrogate pair:
|
||||
startPos--;
|
||||
assert Character.isHighSurrogate(text.charAt(startPos));
|
||||
}
|
||||
int endPos = startPos + maxWordLength - 1;
|
||||
if (Character.isHighSurrogate(text.charAt(endPos))) {
|
||||
// Take care not to split up a surrogate pair:
|
||||
endPos--;
|
||||
}
|
||||
text = text.substring(startPos, 1+endPos);
|
||||
}
|
||||
int endPos = startPos + maxWordLength - 1;
|
||||
if (Character.isHighSurrogate(text.charAt(endPos))) {
|
||||
// Take care not to split up a surrogate pair:
|
||||
endPos--;
|
||||
}
|
||||
text = text.substring(startPos, 1+endPos);
|
||||
} else {
|
||||
// synthetic
|
||||
text = randomAnalysisString(random, maxWordLength, simple);
|
||||
}
|
||||
} else {
|
||||
// synthetic
|
||||
text = randomAnalysisString(random, maxWordLength, simple);
|
||||
}
|
||||
|
||||
try {
|
||||
checkAnalysisConsistency(random, a, useCharFilter, text, offsetsAreCorrect);
|
||||
} catch (Throwable t) {
|
||||
// TODO: really we should pass a random seed to
|
||||
// checkAnalysisConsistency then print it here too:
|
||||
System.err.println("TEST FAIL: useCharFilter=" + useCharFilter + " text='" + escape(text) + "'");
|
||||
Rethrow.rethrow(t);
|
||||
try {
|
||||
checkAnalysisConsistency(random, a, useCharFilter, text, offsetsAreCorrect);
|
||||
} catch (Throwable t) {
|
||||
// TODO: really we should pass a random seed to
|
||||
// checkAnalysisConsistency then print it here too:
|
||||
System.err.println("TEST FAIL: useCharFilter=" + useCharFilter + " text='" + escape(text) + "'");
|
||||
Rethrow.rethrow(t);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeWhileHandlingException(docs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue