mirror of
https://github.com/samsonjs/media.git
synced 2026-03-29 10:05:48 +00:00
Minor fixes in CacheDataSourceTest
PiperOrigin-RevId: 356695284
This commit is contained in:
parent
41c94edcc2
commit
333de74140
1 changed files with 13 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue