LUCENE-5595: try to improve test efficiency

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1643803 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-12-08 13:08:21 +00:00
parent f75d3c5dc4
commit e631a3f943
2 changed files with 24 additions and 22 deletions

View File

@ -19,6 +19,7 @@ package org.apache.lucene.analysis.icu;
import java.io.IOException;
import java.io.Reader;
import java.util.Objects;
import org.apache.lucene.analysis.charfilter.BaseCharFilter;
@ -29,8 +30,6 @@ import com.ibm.icu.text.Normalizer2;
*/
public final class ICUNormalizer2CharFilter extends BaseCharFilter {
private static final int IO_BUFFER_SIZE = 128;
private final Normalizer2 normalizer;
private final StringBuilder inputBuffer = new StringBuilder();
private final StringBuilder resultBuffer = new StringBuilder();
@ -55,11 +54,14 @@ public final class ICUNormalizer2CharFilter extends BaseCharFilter {
* @param normalizer normalizer to use
*/
public ICUNormalizer2CharFilter(Reader in, Normalizer2 normalizer) {
super(in);
if (normalizer == null) {
throw new NullPointerException("normalizer == null");
this(in, normalizer, 128);
}
this.normalizer = normalizer;
// for testing ONLY
ICUNormalizer2CharFilter(Reader in, Normalizer2 normalizer, int bufferSize) {
super(in);
this.normalizer = Objects.requireNonNull(normalizer);
this.tmpBuffer = new char[bufferSize];
}
@Override
@ -92,7 +94,7 @@ public final class ICUNormalizer2CharFilter extends BaseCharFilter {
return -1;
}
private final char[] tmpBuffer = new char[IO_BUFFER_SIZE];
private final char[] tmpBuffer;
private int readInputToBuffer() throws IOException {
final int len = input.read(tmpBuffer);

View File

@ -105,7 +105,7 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
);
}
public void doTestMode(final Normalizer2 normalizer, int maxLength, int iterations) throws IOException {
public void doTestMode(final Normalizer2 normalizer, int maxLength, int iterations, int bufferSize) throws IOException {
Analyzer a = new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName) {
@ -114,7 +114,7 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
@Override
protected Reader initReader(String fieldName, Reader reader) {
return new ICUNormalizer2CharFilter(reader, normalizer);
return new ICUNormalizer2CharFilter(reader, normalizer, bufferSize);
}
};
@ -132,43 +132,43 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
}
public void testNFC() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000);
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000, 128);
}
public void testNFCHuge() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE), 8192, RANDOM_MULTIPLIER*100);
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.COMPOSE), 256, RANDOM_MULTIPLIER*500, 16);
}
public void testNFD() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.DECOMPOSE), 20, RANDOM_MULTIPLIER*1000);
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.DECOMPOSE), 20, RANDOM_MULTIPLIER*1000, 128);
}
public void testNFDHuge() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.DECOMPOSE), 8192, RANDOM_MULTIPLIER*100);
doTestMode(Normalizer2.getInstance(null, "nfc", Normalizer2.Mode.DECOMPOSE), 256, RANDOM_MULTIPLIER*500, 16);
}
public void testNFKC() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000);
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000, 128);
}
public void testNFKCHuge() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE), 8192, RANDOM_MULTIPLIER*100);
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.COMPOSE), 256, RANDOM_MULTIPLIER*500, 16);
}
public void testNFKD() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.DECOMPOSE), 20, RANDOM_MULTIPLIER*1000);
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.DECOMPOSE), 20, RANDOM_MULTIPLIER*1000, 128);
}
public void testNFKDHuge() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.DECOMPOSE), 8192, RANDOM_MULTIPLIER*100);
doTestMode(Normalizer2.getInstance(null, "nfkc", Normalizer2.Mode.DECOMPOSE), 256, RANDOM_MULTIPLIER*500, 16);
}
public void testNFKC_CF() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc_cf", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000);
doTestMode(Normalizer2.getInstance(null, "nfkc_cf", Normalizer2.Mode.COMPOSE), 20, RANDOM_MULTIPLIER*1000, 128);
}
public void testNFKC_CFHuge() throws Exception {
doTestMode(Normalizer2.getInstance(null, "nfkc_cf", Normalizer2.Mode.COMPOSE), 8192, RANDOM_MULTIPLIER*100);
doTestMode(Normalizer2.getInstance(null, "nfkc_cf", Normalizer2.Mode.COMPOSE), 256, RANDOM_MULTIPLIER*500, 16);
}
public void testRandomStrings() throws IOException {
@ -186,7 +186,7 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
};
checkRandomData(random(), a, 1000*RANDOM_MULTIPLIER);
// huge strings
checkRandomData(random(), a, 100*RANDOM_MULTIPLIER, 8192);
checkRandomData(random(), a, 25*RANDOM_MULTIPLIER, 8192);
// nfkd
a = new Analyzer() {
@ -202,7 +202,7 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
};
checkRandomData(random(), a, 1000*RANDOM_MULTIPLIER);
// huge strings
checkRandomData(random(), a, 100*RANDOM_MULTIPLIER, 8192);
checkRandomData(random(), a, 25*RANDOM_MULTIPLIER, 8192);
}
public void testCuriousString() throws Exception {
@ -408,7 +408,7 @@ public class TestICUNormalizer2CharFilter extends BaseTokenStreamTestCase {
return new ICUNormalizer2CharFilter(reader, Normalizer2.getInstance(null, "nfkc_cf", Normalizer2.Mode.COMPOSE));
}
};
for (int i = 0; i < 1000; i++) {
for (int i = 0; i < 25; i++) {
checkAnalysisConsistency(random(), a, false, text);
}
}