ALF-22060: Reader on the backing store is obtained only once in CachingContentStore (#329)

This commit is contained in:
Nicolas Barithel
2019-02-11 16:26:16 +01:00
committed by eknizat
parent fa43cb52dc
commit e8da151640
2 changed files with 6 additions and 3 deletions

View File

@@ -206,7 +206,7 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
return backingStoreReader; return backingStoreReader;
} }
ContentReader reader = attemptCacheAndRead(url); ContentReader reader = attemptCacheAndRead(url, backingStoreReader);
if (reader != null) if (reader != null)
{ {
@@ -254,14 +254,14 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
* @param url URL to cache. * @param url URL to cache.
* @return A reader onto the cached content file or null if unable to provide one. * @return A reader onto the cached content file or null if unable to provide one.
*/ */
private ContentReader attemptCacheAndRead(String url) private ContentReader attemptCacheAndRead(String url, ContentReader backingStoreReader)
{ {
ContentReader reader = null; ContentReader reader = null;
try try
{ {
if (!cache.contains(url)) if (!cache.contains(url))
{ {
if (cache.put(url, backingStore.getReader(url))) if (cache.put(url, backingStoreReader))
{ {
reader = cache.getReader(url); reader = cache.getReader(url);
} }

View File

@@ -38,6 +38,7 @@ import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -121,6 +122,8 @@ public class CachingContentStoreTest
assertSame(returnedReader, cachedContent); assertSame(returnedReader, cachedContent);
verify(quota).afterWritingCacheFile(1274L); verify(quota).afterWritingCacheFile(1274L);
// Check backing store reader is only acquired once
verify(backingStore, only()).getReader("url");
} }