use of net.sf.ehcache.Ehcache in project spring-framework by spring-projects.
the class EhCacheSupportTests method testEhCacheFactoryBeanWithUpdatingSelfPopulatingCache.
@Test
public void testEhCacheFactoryBeanWithUpdatingSelfPopulatingCache() throws Exception {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setCacheEntryFactory(new UpdatingCacheEntryFactory() {
@Override
public Object createEntry(Object key) throws Exception {
return key;
}
@Override
public void updateEntryValue(Object key, Object value) throws Exception {
}
});
assertEquals(cacheFb.getObjectType(), UpdatingSelfPopulatingCache.class);
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof UpdatingSelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getObjectValue());
} finally {
cacheManagerFb.destroy();
}
}
use of net.sf.ehcache.Ehcache in project spring-framework by spring-projects.
the class EhCacheSupportTests method testEhCacheFactoryBeanWithSelfPopulatingCache.
@Test
public void testEhCacheFactoryBeanWithSelfPopulatingCache() throws Exception {
EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.afterPropertiesSet();
try {
CacheManager cm = cacheManagerFb.getObject();
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
cacheFb.setCacheManager(cm);
cacheFb.setCacheName("myCache1");
cacheFb.setCacheEntryFactory(new CacheEntryFactory() {
@Override
public Object createEntry(Object key) throws Exception {
return key;
}
});
assertEquals(cacheFb.getObjectType(), SelfPopulatingCache.class);
cacheFb.afterPropertiesSet();
Ehcache myCache1 = cm.getEhcache("myCache1");
assertTrue(myCache1 instanceof SelfPopulatingCache);
assertEquals("myKey1", myCache1.get("myKey1").getObjectValue());
} finally {
cacheManagerFb.destroy();
}
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class TestCache method testInvalidateCacheByName.
@Test(groups = "slow", description = "Can Invalidate (clear) a Cache by name")
public void testInvalidateCacheByName() throws Exception {
// get Ehcache item with name "record-id"
final Ehcache cache = cacheManager.getEhcache(CacheType.RECORD_ID.getCacheName());
// verify that it is not null and has one stored key (the default tenant created for all integration tests)
assertNotNull(cache);
Assert.assertEquals(cache.getSize(), 1);
// invalidate the specified cache
killBillClient.invalidateCacheByName(cache.getName(), requestOptions);
// verify that now the cache is empty and has no keys stored
Assert.assertEquals(cache.getSize(), 0);
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class TestCache method testInvalidateAllCaches.
@Test(groups = "slow", description = "Can Invalidate (clear) all available Caches")
public void testInvalidateAllCaches() throws Exception {
// get Ehcache item with name "record-id"
final Ehcache cache = cacheManager.getEhcache(CacheType.RECORD_ID.getCacheName());
// verify that it is not null and has one stored key (the default tenant created for all integration tests)
assertNotNull(cache);
Assert.assertEquals(cache.getSize(), 1);
// invalidate all caches
killBillClient.invalidateAllCaches(requestOptions);
// verify that now the cache is empty and has no keys stored
Assert.assertEquals(cache.getSize(), 0);
}
use of net.sf.ehcache.Ehcache in project killbill by killbill.
the class TestCache method testInvalidateCacheByAccount.
@Test(groups = "slow", description = "Can Invalidate (clear) all Account Caches by accountId")
public void testInvalidateCacheByAccount() throws Exception {
final Account input = createAccountNoPMBundleAndSubscription();
// get all caches per account level
final Ehcache accountRecordIdCache = cacheManager.getEhcache(CacheType.ACCOUNT_RECORD_ID.getCacheName());
final Ehcache accountImmutableCache = cacheManager.getEhcache(CacheType.ACCOUNT_IMMUTABLE.getCacheName());
final Ehcache accountBcdCache = cacheManager.getEhcache(CacheType.ACCOUNT_BCD.getCacheName());
// verify that they are not null and have the accountId stored as a key (the account created before)
assertNotNull(accountRecordIdCache);
assertNotNull(accountRecordIdCache.get(input.getAccountId().toString()));
assertNotNull(accountImmutableCache);
assertNotNull(accountImmutableCache.get(input.getAccountId()));
assertNotNull(accountBcdCache);
assertNotNull(accountBcdCache.get(input.getAccountId()));
// invalidate caches per account level by accountId
killBillClient.invalidateCacheByAccount(input.getAccountId().toString(), requestOptions);
// verify that now the caches don't have the accountId key stored
Assert.assertNull(accountRecordIdCache.get(input.getAccountId().toString()));
Assert.assertNull(accountImmutableCache.get(input.getAccountId()));
Assert.assertNull(accountBcdCache.get(input.getAccountId()));
}
Aggregations