private BytesReference getRandomizedPagedBytesReference(int length) {
// we know bytes stream output always creates a paged bytes reference, we use it to create randomized content
ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(length, bigarrays);
try {
for (int i = 0; i < length; i++) {
out.writeByte((byte) getRandom().nextInt(1 << 8));
}
} catch (IOException e) {
fail("should not happen " + e.getMessage());
}
assertThat(out.size(), Matchers.equalTo(length));