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:
Matt Ward
2012-03-23 10:34:19 +00:00
parent 508c880dea
commit bb8fd4c88b
2 changed files with 38 additions and 2 deletions

View File

@@ -215,9 +215,19 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
if (reader != null) if (reader != null)
{ {
quota.afterWritingCacheFile(contentSize); boolean keepCacheFile = quota.afterWritingCacheFile(contentSize);
if (keepCacheFile)
{
return reader; 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
// but there is a recurring problem - give up and return the item from the backing store. // but there is a recurring problem - give up and return the item from the backing store.

View File

@@ -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)