From fffdb569d099fca2e160f94d2a8fe1c9371b4d47 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 16 Apr 2012 03:52:31 +0000 Subject: [PATCH] close the linefiledocs always git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1326473 13f79535-47bb-0310-9956-ffa450edef68 --- .../analysis/BaseTokenStreamTestCase.java | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java index 6978b77506b..5aaea7185e1 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java @@ -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; @@ -454,42 +455,46 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase { private static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect) throws IOException { final LineFileDocs docs = new LineFileDocs(random); - - 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) { - - // 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)); + + 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) { + + // 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); + } + + 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); } - } 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); } + } finally { + IOUtils.closeWhileHandlingException(docs); } }