Commit 333de741 by christosts Committed by Ian Baker

Minor fixes in CacheDataSourceTest

PiperOrigin-RevId: 356695284
parent 41c94edc
...@@ -265,30 +265,31 @@ public final class CacheDataSourceTest { ...@@ -265,30 +265,31 @@ public final class CacheDataSourceTest {
} }
@Test @Test
public void contentLengthEdgeCases() throws Exception { public void boundedRead_doesNotSetContentLength() throws Exception {
DataSpec dataSpec = buildDataSpec(TEST_DATA.length - 2, 2); DataSpec dataSpec = buildDataSpec(0, TEST_DATA.length);
// Read partial at EOS but don't cross it so length is unknown. // Read up to the end of the data, but since the DataSpec is bounded, the read doesn't see the
// EOS, and so the content length remains unknown.
CacheDataSource cacheDataSource = createCacheDataSource(false, true); CacheDataSource cacheDataSource = createCacheDataSource(false, true);
assertReadData(cacheDataSource, dataSpec, true); assertReadData(cacheDataSource, dataSpec, true);
assertThat(ContentMetadata.getContentLength(cache.getContentMetadata(defaultCacheKey))) assertThat(ContentMetadata.getContentLength(cache.getContentMetadata(defaultCacheKey)))
.isEqualTo(C.LENGTH_UNSET); .isEqualTo(C.LENGTH_UNSET);
}
// Now do an unbounded request for whole data. This will cause a bounded request from upstream. @Test
// End of data from upstream shouldn't be mixed up with EOS and cause length set wrong. public void unboundedRead_setsContentLength() throws IOException {
cacheDataSource = createCacheDataSource(false, true); // Perform an unbounded request for the whole data. This should cause the content length to
// become known.
CacheDataSource cacheDataSource = createCacheDataSource(false, true);
assertReadDataContentLength(cacheDataSource, unboundedDataSpec, true, false); assertReadDataContentLength(cacheDataSource, unboundedDataSpec, true, false);
// Now the length set correctly do an unbounded request with offset. // Check the correct length is returned for an unbounded request.
assertThat( assertThat(
cacheDataSource.open( cacheDataSource.open(
buildDataSpec(TEST_DATA.length - 2, C.LENGTH_UNSET, defaultCacheKey))) buildDataSpec(TEST_DATA.length - 2, C.LENGTH_UNSET, defaultCacheKey)))
.isEqualTo(2); .isEqualTo(2);
cacheDataSource.close();
// An unbounded request with offset for not cached content.
dataSpec =
new DataSpec(Uri.parse("https://www.test.com/other"), TEST_DATA.length - 2, C.LENGTH_UNSET);
assertThat(cacheDataSource.open(dataSpec)).isEqualTo(C.LENGTH_UNSET);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment