mirror of https://github.com/apache/lucene.git
LUCENE-3841: add direct test for prefix-coded byte[] spanning two pages
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1300753 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24bce3e8b7
commit
e943c4b76e
|
@ -214,8 +214,6 @@ public final class PagedBytes {
|
||||||
// VarDerefBytesImpl.finishInternal does its own
|
// VarDerefBytesImpl.finishInternal does its own
|
||||||
// prefix + byte[] writing which can span two blocks,
|
// prefix + byte[] writing which can span two blocks,
|
||||||
// so we support that here on decode:
|
// so we support that here on decode:
|
||||||
// we could some day relax that and span two blocks:
|
|
||||||
|
|
||||||
if (blockSize - offset >= length) {
|
if (blockSize - offset >= length) {
|
||||||
// Within block
|
// Within block
|
||||||
b.offset = offset;
|
b.offset = offset;
|
||||||
|
|
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue