Search in sources :

Example 6 with Ehcache

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();
    }
}
Also used : UpdatingCacheEntryFactory(net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory) UpdatingSelfPopulatingCache(net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) CacheException(net.sf.ehcache.CacheException) Test(org.junit.Test)

Example 7 with Ehcache

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();
    }
}
Also used : SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) UpdatingSelfPopulatingCache(net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache) UpdatingCacheEntryFactory(net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory) CacheEntryFactory(net.sf.ehcache.constructs.blocking.CacheEntryFactory) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) CacheException(net.sf.ehcache.CacheException) Test(org.junit.Test)

Example 8 with Ehcache

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);
}
Also used : Ehcache(net.sf.ehcache.Ehcache) Test(org.testng.annotations.Test)

Example 9 with Ehcache

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);
}
Also used : Ehcache(net.sf.ehcache.Ehcache) Test(org.testng.annotations.Test)

Example 10 with Ehcache

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()));
}
Also used : Account(org.killbill.billing.client.model.Account) Ehcache(net.sf.ehcache.Ehcache) Test(org.testng.annotations.Test)

Aggregations

Ehcache (net.sf.ehcache.Ehcache)39 Test (org.junit.Test)14 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)9 Element (net.sf.ehcache.Element)8 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)7 CacheException (net.sf.ehcache.CacheException)5 CacheManager (net.sf.ehcache.CacheManager)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)5 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)5 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)5 FileSystemResource (org.springframework.core.io.FileSystemResource)5 Resource (org.springframework.core.io.Resource)5 CacheKey (org.apereo.portal.utils.cache.CacheKey)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 Test (org.testng.annotations.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3