mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-10636: CachingContentStore: afterWritingCacheFile() return value is ignored
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@34711 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -215,8 +215,18 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
|
|||||||
|
|
||||||
if (reader != null)
|
if (reader != null)
|
||||||
{
|
{
|
||||||
quota.afterWritingCacheFile(contentSize);
|
boolean keepCacheFile = quota.afterWritingCacheFile(contentSize);
|
||||||
return reader;
|
if (keepCacheFile)
|
||||||
|
{
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Quota strategy has requested cache file not to be kept.
|
||||||
|
cache.deleteFile(url);
|
||||||
|
cache.remove(url);
|
||||||
|
return backingStore.getReader(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Have tried multiple times to cache the item and read it back from the cache
|
// Have tried multiple times to cache the item and read it back from the cache
|
||||||
|
@@ -108,6 +108,7 @@ public class CachingContentStoreTest
|
|||||||
QuotaManagerStrategy quota = mock(QuotaManagerStrategy.class);
|
QuotaManagerStrategy quota = mock(QuotaManagerStrategy.class);
|
||||||
cachingStore.setQuota(quota);
|
cachingStore.setQuota(quota);
|
||||||
when(quota.beforeWritingCacheFile(1274L)).thenReturn(true);
|
when(quota.beforeWritingCacheFile(1274L)).thenReturn(true);
|
||||||
|
when(quota.afterWritingCacheFile(1274L)).thenReturn(true);
|
||||||
|
|
||||||
ContentReader returnedReader = cachingStore.getReader("url");
|
ContentReader returnedReader = cachingStore.getReader("url");
|
||||||
|
|
||||||
@@ -286,6 +287,31 @@ public class CachingContentStoreTest
|
|||||||
verify(cache).remove("url");
|
verify(cache).remove("url");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void quotaManagerCanRequestFileDeletionFromCacheAfterWriteWhenNotCacheOnInbound()
|
||||||
|
{
|
||||||
|
when(cache.getReader("url")).thenReturn(cachedContent);
|
||||||
|
when(backingStore.getReader("url")).thenReturn(sourceContent);
|
||||||
|
when(sourceContent.getSize()).thenReturn(1274L);
|
||||||
|
when(cache.put("url", sourceContent)).thenReturn(true);
|
||||||
|
|
||||||
|
QuotaManagerStrategy quota = mock(QuotaManagerStrategy.class);
|
||||||
|
cachingStore.setQuota(quota);
|
||||||
|
|
||||||
|
// Don't veto writing the cache file.
|
||||||
|
when(quota.beforeWritingCacheFile(1274L)).thenReturn(true);
|
||||||
|
// Do request cache file deletion.
|
||||||
|
when(quota.afterWritingCacheFile(1234L)).thenReturn(false);
|
||||||
|
|
||||||
|
ContentReader returnedReader = cachingStore.getReader("url");
|
||||||
|
|
||||||
|
// Was the file deleted?
|
||||||
|
verify(cache).deleteFile("url");
|
||||||
|
verify(cache).remove("url");
|
||||||
|
// As the cache file has been deleted, the reader must come from the backing store
|
||||||
|
// rather than the cache.
|
||||||
|
assertSame(returnedReader, sourceContent);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected=RuntimeException.class)
|
@Test(expected=RuntimeException.class)
|
||||||
// Check that exceptions raised by the backing store's putContent(ContentReader)
|
// Check that exceptions raised by the backing store's putContent(ContentReader)
|
||||||
|
Reference in New Issue
Block a user