Apache Lucene open-source search software
LUCENE-3841: add direct test for prefix-coded byte[] spanning two pages
Michael McCandlesse943c4b76e58
diff --git a/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java b/lucene/core/src/java/org/apache/lucene/util/PagedBytes.javaindex 9d09abf72ce..bdf2939ffbc 100644--- a/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java+++ b/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java@@ -214,8 +214,6 @@ public final class PagedBytes {// VarDerefBytesImpl.finishInternal does its own// prefix + byte[] writing which can span two blocks,// so we support that here on decode:- // we could some day relax that and span two blocks:-if (blockSize - offset >= length) {// Within blockb.offset = offset;diff --git a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.javaindex df8fa2f8966..01d065e6075 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestPagedBytes.java@@ -107,4 +107,27 @@ public class TestPagedBytes extends LuceneTestCase {}}}++ // LUCENE-3841: even though+ // copyUsingLengthPrefix will never span two blocks, make+ // sure if caller writes their own prefix followed by the+ // bytes, it still works:+ public void testLengthPrefixAcrossTwoBlocks() throws Exception {+ final PagedBytes p = new PagedBytes(10);+ final DataOutput out = p.getDataOutput();+ final byte[] bytes1 = new byte[1000];+ random.nextBytes(bytes1);+ out.writeBytes(bytes1, 0, bytes1.length);+ out.writeByte((byte) 40);+ final byte[] bytes2 = new byte[40];+ random.nextBytes(bytes2);+ out.writeBytes(bytes2, 0, bytes2.length);++ final PagedBytes.Reader reader = p.freeze(random.nextBoolean());+ BytesRef answer = reader.fillSliceWithPrefix(new BytesRef(), 1000);+ assertEquals(40, answer.length);+ for(int i=0;i<40;i++) {+ assertEquals(bytes2[i], answer.bytes[answer.offset + i]);+ }+ }}