From 168a5d63c5d949485cd59d178e62ee810551ae2c Mon Sep 17 00:00:00 2001 From: eguven Date: Mon, 29 Jan 2018 08:09:15 -0800 Subject: [PATCH] Remove empty CachedContent in SimpleCache.releaseHoleSpan() In startReadWrite*() methods a new CachedContent is created if the there isn't one already for the given key. If the span is release without writing any content, this fix removes the added CachedContent. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183666821 --- .../android/exoplayer2/upstream/cache/SimpleCache.java | 1 + .../exoplayer2/upstream/cache/CacheDataSourceTest.java | 6 +++--- .../exoplayer2/playbacktests/gts/DashDownloadTest.java | 4 ++-- .../google/android/exoplayer2/testutil/CacheAsserts.java | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java index 4a77015f93..f2679fee0c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java @@ -236,6 +236,7 @@ public final class SimpleCache implements Cache { Assertions.checkNotNull(cachedContent); Assertions.checkState(cachedContent.isLocked()); cachedContent.setLocked(false); + index.maybeRemove(cachedContent.key); notifyAll(); } diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java index bd8752355c..67fae69b44 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java @@ -147,8 +147,7 @@ public final class CacheDataSourceTest { } @Test - public void testCantResolvedLengthContentReadInOneConnectionAndLengthIsResolved() - throws Exception { + public void testUnknownLengthContentReadInOneConnectionAndLengthIsResolved() throws Exception { FakeDataSource upstream = new FakeDataSource(); upstream .getDataSet() @@ -157,7 +156,8 @@ public final class CacheDataSourceTest { .setSimulateUnknownLength(true); CacheDataSource cacheDataSource = new CacheDataSource(cache, upstream, 0); - cacheDataSource.open(new DataSpec(testDataUri, 0, C.LENGTH_UNSET, testDataKey)); + int flags = DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH; + cacheDataSource.open(new DataSpec(testDataUri, 0, C.LENGTH_UNSET, testDataKey, flags)); TestUtil.readToEnd(cacheDataSource); cacheDataSource.close(); diff --git a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java index 56681d6305..dd5369d64d 100644 --- a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java +++ b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java @@ -100,8 +100,8 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2