Minor fixes in CacheDataSourceTest

PiperOrigin-RevId: 356695284
This commit is contained in:
christosts 2021-02-10 10:47:07 +00:00 committed by Ian Baker
parent 41c94edcc2
commit 333de74140

View file

@ -265,30 +265,31 @@ public final class CacheDataSourceTest {
}
@Test
public void contentLengthEdgeCases() throws Exception {
DataSpec dataSpec = buildDataSpec(TEST_DATA.length - 2, 2);
public void boundedRead_doesNotSetContentLength() throws Exception {
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);
assertReadData(cacheDataSource, dataSpec, true);
assertThat(ContentMetadata.getContentLength(cache.getContentMetadata(defaultCacheKey)))
.isEqualTo(C.LENGTH_UNSET);
}
// Now do an unbounded request for whole data. This will cause a bounded request from upstream.
// End of data from upstream shouldn't be mixed up with EOS and cause length set wrong.
cacheDataSource = createCacheDataSource(false, true);
@Test
public void unboundedRead_setsContentLength() throws IOException {
// 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);
// Now the length set correctly do an unbounded request with offset.
// Check the correct length is returned for an unbounded request.
assertThat(
cacheDataSource.open(
buildDataSpec(TEST_DATA.length - 2, C.LENGTH_UNSET, defaultCacheKey)))
.isEqualTo(2);
// 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);
cacheDataSource.close();
}
@Test