private void assertReadBytesWorkingCorrectly(Directory dir, String fileName,
final int contentFileSizeExpected, final int arrayLengthToRead) throws IOException {
IndexInput indexInput = dir.openInput(fileName);
AssertJUnit.assertEquals(contentFileSizeExpected, indexInput.length());
RepeatableLongByteSequence bytesGenerator = new RepeatableLongByteSequence();
byte[] readBytes = new byte[arrayLengthToRead];
byte[] expectedBytes = new byte[arrayLengthToRead];
long toRead = contentFileSizeExpected;
while (toRead > 0) {
// the condition is satisfied when the file is close to the end
if (toRead < arrayLengthToRead) {
readBytes = new byte[(int) toRead];
expectedBytes = new byte[(int) toRead];
}
int nextBytesToRead = (int) Math.min(toRead, arrayLengthToRead);
bytesGenerator.nextBytes(expectedBytes);
indexInput.readBytes(readBytes, 0, nextBytesToRead);
assert Arrays.equals(expectedBytes, readBytes);
toRead = toRead - nextBytesToRead;