From bf36270469d9f02472110c0d0ac8a3fdf62962cf Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sun, 27 Jan 2013 19:53:12 +0000 Subject: [PATCH] add two more tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1439161 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/TestDemoDocValue.java | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java index 19ad07ea9fe..e9e855253d0 100644 --- a/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java +++ b/lucene/core/src/test/org/apache/lucene/TestDemoDocValue.java @@ -813,8 +813,6 @@ public class TestDemoDocValue extends LuceneTestCase { directory.close(); } - // nocommit: test exactly 32766, also add field-level check so you get exc faster - // same for sorted bytes public void testTooLargeBytes() throws IOException { Analyzer analyzer = new MockAnalyzer(random()); @@ -861,4 +859,59 @@ public class TestDemoDocValue extends LuceneTestCase { iwriter.close(); directory.close(); } + + public void testVeryLargeButLegalBytes() throws IOException { + Analyzer analyzer = new MockAnalyzer(random()); + + Directory directory = newDirectory(); + // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1 + IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer); + iwc.setMergePolicy(newLogMergePolicy()); + IndexWriter iwriter = new IndexWriter(directory, iwc); + Document doc = new Document(); + byte bytes[] = new byte[32766]; + BytesRef b = new BytesRef(bytes); + random().nextBytes(bytes); + doc.add(new BinaryDocValuesField("dv", b)); + iwriter.addDocument(doc); + iwriter.close(); + + // Now search the index: + IndexReader ireader = DirectoryReader.open(directory); // read-only=true + assert ireader.leaves().size() == 1; + BinaryDocValues dv = ireader.leaves().get(0).reader().getBinaryDocValues("dv"); + BytesRef scratch = new BytesRef(); + dv.get(0, scratch); + assertEquals(new BytesRef(bytes), scratch); + + ireader.close(); + directory.close(); + } + + public void testVeryLargeButLegalSortedBytes() throws IOException { + Analyzer analyzer = new MockAnalyzer(random()); + + Directory directory = newDirectory(); + // we don't use RandomIndexWriter because it might add more docvalues than we expect !!!!1 + IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer); + iwc.setMergePolicy(newLogMergePolicy()); + IndexWriter iwriter = new IndexWriter(directory, iwc); + Document doc = new Document(); + byte bytes[] = new byte[32766]; + BytesRef b = new BytesRef(bytes); + random().nextBytes(bytes); + doc.add(new SortedDocValuesField("dv", b)); + iwriter.addDocument(doc); + iwriter.close(); + + // Now search the index: + IndexReader ireader = DirectoryReader.open(directory); // read-only=true + assert ireader.leaves().size() == 1; + BinaryDocValues dv = ireader.leaves().get(0).reader().getSortedDocValues("dv"); + BytesRef scratch = new BytesRef(); + dv.get(0, scratch); + assertEquals(new BytesRef(bytes), scratch); + ireader.close(); + directory.close(); + } }