@Test
public void testUnsatisfiableRange() throws Exception {

  // Bounded request but the content length is unknown. This forces all data to be cached but not
  // the length.
  assertCacheAndRead(boundedDataSpec, /* unknownLength= */ true);
  // Now do an unbounded request. This will read all of the data from cache and then try to read
  // more from upstream which will cause to a 416 so CDS will store the length.
  CacheDataSource cacheDataSource =
      createCacheDataSource(/* setReadException= */ true, /* unknownLength= */ true);
  assertReadDataContentLength(
      cacheDataSource, unboundedDataSpec, /* unknownLength= */ true, /* customCacheKey= */ false);
  // If the user try to access off range then it should throw an IOException.
  try {
    cacheDataSource =
        createCacheDataSource(/* setReadException= */ false, /* unknownLength= */ false);
    cacheDataSource.open(buildDataSpec(TEST_DATA.length, /* length= */ 1, defaultCacheKey));
    fail();
  } catch (IOException e) {
    // Expected.
  }
}