cacheFb.setCacheName("myCache1");
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
Class<? extends Ehcache> objectType2 = cacheFb.getObjectType();
assertSame(objectType, objectType2);
CacheConfiguration config = cache.getCacheConfiguration();
assertEquals("myCache1", cache.getName());
if (useCacheManagerFb){
assertEquals("myCache1.maxElements", 300, config.getMaxElementsInMemory());
}
else {
assertEquals("myCache1.maxElements", 10000, config.getMaxElementsInMemory());
}
// Cache region is not defined. Should create one with default properties.
cacheFb = new EhCacheFactoryBean();
if (useCacheManagerFb) {
cacheFb.setCacheManager(cacheManagerFb.getObject());
}
cacheFb.setCacheName("undefinedCache");
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache", cache.getName());
assertTrue("default maxElements is correct", config.getMaxElementsInMemory() == 10000);
assertFalse("default eternal is correct", config.isEternal());
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120);
assertTrue("default diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 120);
// overriding the default properties
cacheFb = new EhCacheFactoryBean();
if (useCacheManagerFb) {
cacheFb.setCacheManager(cacheManagerFb.getObject());
}
cacheFb.setBeanName("undefinedCache2");
cacheFb.setMaxElementsInMemory(5);
cacheFb.setTimeToLive(8);
cacheFb.setTimeToIdle(7);
cacheFb.setDiskExpiryThreadIntervalSeconds(10);
cacheFb.afterPropertiesSet();
cache = (Cache) cacheFb.getObject();
config = cache.getCacheConfiguration();
assertEquals("undefinedCache2", cache.getName());
assertTrue("overridden maxElements is correct", config.getMaxElementsInMemory() == 5);
assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 8);
assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 7);
assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
}
finally {
if (cacheManagerFbInitialized) {
cacheManagerFb.destroy();
}