private void getAndVerifyView(LogSegment segment, long writeStartOffset, int offset, byte[] dataInSegment,
      long expectedRefCount) throws IOException {
    Random random = new Random();
    Pair<File, FileChannel> view = segment.getView();
    assertNotNull("File object received in view is null", view.getFirst());
    assertNotNull("FileChannel object received in view is null", view.getSecond());
    assertEquals("Ref count is not as expected", expectedRefCount, segment.refCount());
    int sizeToRead = random.nextInt(dataInSegment.length - offset + 1);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[sizeToRead]);
    view.getSecond().read(buffer, writeStartOffset + offset);
    assertArrayEquals("Data read from file does not match data written",
        Arrays.copyOfRange(dataInSegment, offset, offset + sizeToRead), buffer.array());
  }
Gets a view of the given {@code segment} and verifies the ref count and the data obtained from the view against
{@code expectedRefCount} and {@code dataInSegment} respectively.
@param segment the {@link LogSegment} to get a view from.
@param writeStartOffset the offset at which write was started on the segment.
@param offset the offset for which a view is required.
@param dataInSegment the entire data in the {@link LogSegment}.
@param expectedRefCount the expected return value of {@link LogSegment#refCount()} once the view is obtained from
                        the {@code segment}
@throws IOException
ambry-store/src/test/java/com/github/ambry/store/LogSegmentTest.java