Skip to content

Commit

Permalink
Add test that proves you can write a ByteReference using its iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Oct 11, 2023
1 parent bd4d45a commit 1c203cc
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,20 @@ public void testIndexOf() throws IOException {
final byte missing = randomValueOtherThanMany(map::containsKey, ESTestCase::randomByte);
assertEquals(-1, bytesReference.indexOf(missing, randomIntBetween(0, Math.max(0, size - 1))));
}

public void testWriteWithIterator() throws IOException {
final int length = randomIntBetween(1014, 1024 * 1024);
final byte[] bytes = new byte[length];
random().nextBytes(bytes);
final BytesReference bytesReference = randomBytesReference(length);
final BytesRefIterator iterator = bytesReference.iterator();
BytesRef bytesRef;
int offset = 0;
while ((bytesRef = iterator.next()) != null) {
final int len = Math.min(bytesRef.length, length - offset);
System.arraycopy(bytes, offset, bytesRef.bytes, bytesRef.offset, len);
offset += len;
}
assertArrayEquals(bytes, BytesReference.toBytes(bytesReference));
}
}

0 comments on commit 1c203cc

Please sign in to comment.