From 0e928f593cc2dc0f333b27823870eb964ca22cbe Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 14 Apr 2011 19:38:18 +0000 Subject: [PATCH] more verbosity in Test2B (merged from 3.x) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1092462 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/_TestUtil.java | 35 ++++++++++++------- .../org/apache/lucene/index/Test2BTerms.java | 26 ++++++++++++-- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java b/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java index e3ef5764a8f..19609d03ef7 100644 --- a/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java +++ b/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java @@ -34,8 +34,6 @@ import java.util.HashMap; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.junit.Assert; - import org.apache.lucene.document.Document; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.CheckIndex; @@ -188,22 +186,35 @@ public class _TestUtil { return ""; } final char[] buffer = new char[end]; - for (int i = 0; i < end; i++) { - int t = r.nextInt(5); + randomFixedLengthUnicodeString(r, buffer, 0, buffer.length); + return new String(buffer, 0, end); + } - if (0 == t && i < end - 1) { + /** + * Fills provided char[] with valid random unicode code + * unit sequence. + */ + public static void randomFixedLengthUnicodeString(Random random, char[] chars, int offset, int length) { + int i = offset; + final int end = offset + length; + while(i < end) { + final int t = random.nextInt(5); + if (0 == t && i < length - 1) { // Make a surrogate pair // High surrogate - buffer[i++] = (char) nextInt(r, 0xd800, 0xdbff); + chars[i++] = (char) nextInt(random, 0xd800, 0xdbff); // Low surrogate - buffer[i] = (char) nextInt(r, 0xdc00, 0xdfff); + chars[i++] = (char) nextInt(random, 0xdc00, 0xdfff); + } else if (t <= 1) { + chars[i++] = (char) random.nextInt(0x80); + } else if (2 == t) { + chars[i++] = (char) nextInt(random, 0x80, 0x800); + } else if (3 == t) { + chars[i++] = (char) nextInt(random, 0x800, 0xd7ff); + } else if (4 == t) { + chars[i++] = (char) nextInt(random, 0xe000, 0xffff); } - else if (t <= 1) buffer[i] = (char) r.nextInt(0x80); - else if (2 == t) buffer[i] = (char) nextInt(r, 0x80, 0x800); - else if (3 == t) buffer[i] = (char) nextInt(r, 0x800, 0xd7ff); - else if (4 == t) buffer[i] = (char) nextInt(r, 0xe000, 0xffff); } - return new String(buffer, 0, end); } private static final int[] blockStarts = { diff --git a/lucene/src/test/org/apache/lucene/index/Test2BTerms.java b/lucene/src/test/org/apache/lucene/index/Test2BTerms.java index 42f4f46cea0..25cf0c4d987 100644 --- a/lucene/src/test/org/apache/lucene/index/Test2BTerms.java +++ b/lucene/src/test/org/apache/lucene/index/Test2BTerms.java @@ -26,6 +26,7 @@ import org.apache.lucene.document.*; import org.apache.lucene.index.codecs.CodecProvider; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -77,6 +78,7 @@ public class Test2BTerms extends LuceneTestCase { tokenCount++; if (--nextSave == 0) { savedTerms.add(new BytesRef(bytes)); + System.out.println("TEST: save term=" + bytes); nextSave = _TestUtil.nextInt(random, 500000, 1000000); } return true; @@ -153,13 +155,16 @@ public class Test2BTerms extends LuceneTestCase { Directory dir = newFSDirectory(_TestUtil.getTempDir("2BTerms")); //Directory dir = newFSDirectory(new File("/p/lucene/indices/2bindex")); + if (true) { + IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)) .setMaxBufferedDocs(IndexWriterConfig.DISABLE_AUTO_FLUSH) .setRAMBufferSizeMB(256.0) .setMergeScheduler(new ConcurrentMergeScheduler()) - .setMergePolicy(newLogMergePolicy(false, 10))); + .setMergePolicy(newLogMergePolicy(false, 10)) + .setOpenMode(IndexWriterConfig.OpenMode.CREATE)); MergePolicy mp = w.getConfig().getMergePolicy(); if (mp instanceof LogByteSizeMergePolicy) { @@ -211,6 +216,7 @@ public class Test2BTerms extends LuceneTestCase { assertTrue("count " + tc + " is not > " + Integer.MAX_VALUE, tc > Integer.MAX_VALUE); dir.close(); + System.out.println("TEST: done!"); } private List findTerms(IndexReader r) throws IOException { @@ -234,15 +240,29 @@ public class Test2BTerms extends LuceneTestCase { IndexSearcher s = new IndexSearcher(r); Collections.shuffle(terms); TermsEnum termsEnum = MultiFields.getTerms(r, "field").iterator(); + boolean failed = false; for(int iter=0;iter<10*terms.size();iter++) { final BytesRef term = terms.get(random.nextInt(terms.size())); System.out.println("TEST: search " + term); final long t0 = System.currentTimeMillis(); - assertTrue(s.search(new TermQuery(new Term("field", term)), 1).totalHits > 0); + final int count = s.search(new TermQuery(new Term("field", term)), 1).totalHits; + if (count <= 0) { + System.out.println(" FAILED: count=" + count); + failed = true; + } final long t1 = System.currentTimeMillis(); System.out.println(" took " + (t1-t0) + " millis"); - assertEquals(TermsEnum.SeekStatus.FOUND, termsEnum.seek(term)); + TermsEnum.SeekStatus result = termsEnum.seek(term); + if (result != TermsEnum.SeekStatus.FOUND) { + if (result == TermsEnum.SeekStatus.END) { + System.out.println(" FAILED: got END"); + } else { + System.out.println(" FAILED: wrong term: got " + termsEnum.term()); + } + failed = true; + } } + assertFalse(failed); } }