[TEST] fix test to account for internal empyt reference optimization

This commit is contained in:
Simon Willnauer 2016-07-05 11:23:26 +02:00
parent a4ec0ac22f
commit d08812d839
1 changed files with 9 additions and 2 deletions

View File

@ -462,9 +462,16 @@ public abstract class AbstractBytesReferenceTestCase extends ESTestCase {
// get a BytesRef from a slice
int sliceOffset = randomIntBetween(0, pbr.length());
int sliceLength = randomIntBetween(0, pbr.length() - sliceOffset);
BytesRef sliceRef = pbr.slice(sliceOffset, sliceLength).toBytesRef();
// note that these are only true if we have <= than a page, otherwise offset/length are shifted
assertEquals(sliceOffset, sliceRef.offset);
if (sliceLength == 0 && sliceOffset != sliceRef.offset) {
// some impls optimize this to an empty instance then the offset will be 0
assertEquals(0, sliceRef.offset);
} else {
// note that these are only true if we have <= than a page, otherwise offset/length are shifted
assertEquals(sliceOffset, sliceRef.offset);
}
assertEquals(sliceLength, sliceRef.length);
}