From 8a74acbe6ff586bcc322846fa5041eb22261c1b7 Mon Sep 17 00:00:00 2001 From: danarapagna Date: Thu, 5 Apr 2018 19:12:58 -0700 Subject: [PATCH] Automated g4 rollback of changelist 191128111. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=191834511 --- .../upstream/cache/SimpleCache.java | 4 ++++ .../upstream/cache/SimpleCacheTest.java | 22 +++++++++---------- 2 files changed, 15 insertions(+), 11 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 d1b26f884c..57af765926 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 @@ -93,6 +93,10 @@ public final class SimpleCache implements Cache { * @param index The CachedContentIndex to be used. */ /*package*/ SimpleCache(File cacheDir, CacheEvictor evictor, CachedContentIndex index) { + if (!lockFolder(cacheDir)) { + throw new IllegalStateException("Another SimpleCache instance uses the folder: " + cacheDir); + } + this.cacheDir = cacheDir; this.evictor = evictor; this.index = index; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java index a35a86f933..15e2b80f59 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/SimpleCacheTest.java @@ -296,17 +296,17 @@ public class SimpleCacheTest { } } - // @Test - // public void testMultipleSimpleCacheWithSameCacheDirThrowsException() throws Exception { - // new SimpleCache(cacheDir, new NoOpCacheEvictor()); - // - // try { - // new SimpleCache(cacheDir, new NoOpCacheEvictor()); - // assertWithMessage("Exception was expected").fail(); - // } catch (IllegalStateException e) { - // // Expected. Do nothing. - // } - // } + @Test + public void testMultipleSimpleCacheWithSameCacheDirThrowsException() throws Exception { + new SimpleCache(cacheDir, new NoOpCacheEvictor()); + + try { + new SimpleCache(cacheDir, new NoOpCacheEvictor()); + assertWithMessage("Exception was expected").fail(); + } catch (IllegalStateException e) { + // Expected. Do nothing. + } + } @Test public void testMultipleSimpleCacheWithSameCacheDirDoesNotThrowsExceptionAfterRelease()