Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

59923: Fixes StandardQuotaStrategyTest, that was broken by changes in cache behaviour.
   Non-clustered (Google Guava) caches do not use maxItems as a hard-limit any more - eviction takes place as cache size approaches the limit.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62233 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis 2014-02-12 09:42:08 +00:00
parent 13e34899ef
commit 00cd413c12
2 changed files with 21 additions and 9 deletions

View File

@ -109,13 +109,27 @@ public class StandardQuotaStrategyTest
// Quota is 20MB. The quota manager will... // Quota is 20MB. The quota manager will...
// * start the cleaner at 16MB (80% of 20MB) // * start the cleaner at 16MB (80% of 20MB)
// * refuse to cache any more files at 18MB (90% of 20MB) // * refuse to cache any more files at 18MB (90% of 20MB)
List<String> contentURLs = new ArrayList<>();
for (int i = 0; i < 15; i++) for (int i = 0; i < 15; i++)
{ {
writeSingleFileInMB(1); String url = writeSingleFileInMB(1);
contentURLs.add(url);
} }
// All 15 should be retained. // All 15 should be retained.
assertEquals(15, findCacheFiles().size()); assertEquals(15, findCacheFiles().size());
// Simulate eviction from the in-memory cache. We'll evict 10, so that 6 of the
// eventual 16 created files have details remaining in the cache.
//
// Note, we're simulating eviction here, rather than imposing, for example, a maxItems on the
// cache (i.e. the "cachingContentStoreCache" bean) since cache behaviour isn't easily deterministic
// in this respect - the google guava cache in particular, evicts items as the cache size *approaches*
// the size limit.
for (int evictCount = 0; evictCount < 10; evictCount++)
{
cache.remove(contentURLs.get(evictCount));
}
// Writing one more file should trigger a clean. // Writing one more file should trigger a clean.
writeSingleFileInMB(1); writeSingleFileInMB(1);
@ -125,9 +139,8 @@ public class StandardQuotaStrategyTest
Thread.sleep(50); Thread.sleep(50);
} }
// As the cache is set to contain a max of 12 items in-memory (see cachingContentStoreCache // Since 6 of the 16 total had details in the in-memory cache at the time the cleaner
// definition in test-std-quota-context.xml) and 2 cache items are required per cached content URL // ran, then only 6 files should remain on disk - the rest should have been removed by the cleaner.
// then after the cleaner has processed the tree there will 6 items left on disk (12/2).
assertEquals(6, findCacheFiles().size()); assertEquals(6, findCacheFiles().size());
} }
@ -164,11 +177,12 @@ public class StandardQuotaStrategyTest
assertEquals(3, files.get(2).length() / FileUtils.ONE_MB); assertEquals(3, files.get(2).length() / FileUtils.ONE_MB);
} }
private void writeSingleFileInMB(int sizeInMb) throws IOException private String writeSingleFileInMB(int sizeInMb) throws IOException
{ {
ContentWriter writer = store.getWriter(ContentContext.NULL_CONTEXT); ContentWriter writer = store.getWriter(ContentContext.NULL_CONTEXT);
File content = createFileOfSize(sizeInMb * 1024); File content = createFileOfSize(sizeInMb * 1024);
writer.putContent(content); writer.putContent(content);
return writer.getContentUrl();
} }
private File createFileOfSize(long sizeInKB) throws IOException private File createFileOfSize(long sizeInKB) throws IOException

View File

@ -35,9 +35,7 @@
</bean> </bean>
<bean id="cachingContentStoreCache" class="org.alfresco.repo.cache.DefaultSimpleCache"> <bean id="cachingContentStoreCache" class="org.alfresco.repo.cache.DefaultSimpleCache"/>
<property name="maxItems" value="12"/>
</bean>
<bean id="cachedContentCleaner" <bean id="cachedContentCleaner"