@Test
  public void testResolvedByteRange() throws Exception {
    // 0-0 (0th byte)
    ByteRange range = ByteRanges.fromOffsetRange(0, 0);
    assertRangeResolutionFailure(range, 0);
    assertRangeResolutionFailure(range, -1);
    assertRangeResolutionSuccess(range, 2, 0, 0);

    // 0- (bytes after/including 0)
    range = ByteRanges.fromStartOffset(0);
    assertRangeResolutionFailure(range, 0);
    assertRangeResolutionFailure(range, -1);
    assertRangeResolutionSuccess(range, 20, 0, 19);

    // 15- (bytes after/including 15)
    range = ByteRanges.fromStartOffset(15);
    assertRangeResolutionFailure(range, 15);
    assertRangeResolutionFailure(range, -1);
    assertRangeResolutionSuccess(range, 20, 15, 19);
    assertRangeResolutionSuccess(range, 16, 15, 15);

    // -20 (last 20 bytes)
    range = ByteRanges.fromLastNBytes(20);
    assertRangeResolutionFailure(range, -1);
    assertRangeResolutionSuccess(range, 0, 0, -1);
    assertRangeResolutionSuccess(range, 19, 0, 18);
    assertRangeResolutionSuccess(range, 20, 0, 19);
    assertRangeResolutionSuccess(range, 30, 10, 29);

    // 22-44 (bytes 22 through 44, inclusive)
    range = ByteRanges.fromOffsetRange(22, 44);
    assertRangeResolutionSuccess(range, 44, 22, 43);
    assertRangeResolutionSuccess(range, 45, 22, 44);

    // {MAX_LONG-50}- (bytes after/including MAX_LONG-50)
    range = ByteRanges.fromStartOffset(Long.MAX_VALUE - 50);
    assertRangeResolutionFailure(range, 0);
    assertRangeResolutionFailure(range, -1);
    assertRangeResolutionFailure(range, 20);
    assertRangeResolutionSuccess(range, Long.MAX_VALUE, Long.MAX_VALUE - 50, Long.MAX_VALUE - 1);

    // Last 0 bytes
    range = ByteRanges.fromLastNBytes(0);
    assertRangeResolutionSuccess(range, 0, 0, -1);
    assertRangeResolutionSuccess(range, 20, 20, 19);
  }
Test that resolving {@link ByteRange}s with a blob size to generate ranges with defined start/end offsets works as
expected.
@throws Exception
ambry-api/src/test/java/com/github/ambry/router/ByteRangeTest.java