Search in sources :

Example 26 with CacheManager

use of net.sf.ehcache.CacheManager in project joynr by bmwcarit.

the class ProvisionedDomainAccessControlStoreTest method testGetDomainRoles.

@Test
public void testGetDomainRoles() throws Exception {
    Properties customProperties = new Properties();
    customProperties.put(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_DOMAIN_ROLES, domainRoleEntryString);
    Injector injector = getInjector(customProperties);
    DomainAccessControlStore store = injector.getInstance(DomainAccessControlStore.class);
    assertEquals("DRE for UID1 should be the same as expectedOwnerAccessControlEntry", expectedUserDomainRoleEntry, store.getDomainRoles(UID1).get(0));
    assertEquals("DRE for UID1 and Role.OWNER should be the same as expectedOwnerAccessControlEntry", expectedUserDomainRoleEntry, store.getDomainRole(UID1, Role.OWNER));
    CacheManager cacheManager = injector.getInstance(CacheManager.class);
    cacheManager.removeAllCaches();
}
Also used : Injector(com.google.inject.Injector) CacheManager(net.sf.ehcache.CacheManager) Properties(java.util.Properties) Test(org.junit.Test)

Example 27 with CacheManager

use of net.sf.ehcache.CacheManager in project joynr by bmwcarit.

the class ProvisionedDomainAccessControlStoreTest method testGetMasterAce.

@Test
public void testGetMasterAce() throws Exception {
    Properties customProperties = new Properties();
    customProperties.put(StaticDomainAccessControlProvisioning.PROPERTY_PROVISIONED_MASTER_ACCESSCONTROLENTRIES, masterAccessControlEntryString);
    Injector injector = getInjector(customProperties);
    DomainAccessControlStore store = injector.getInstance(DomainAccessControlStore.class);
    assertEquals("Master ACE associated to UID1 from Master ACL should be the same as expectedMasterAccessControlEntry", expectedMasterAccessControlEntry, store.getMasterAccessControlEntries(UID1).get(0));
    assertEquals("Master ACE associated to DOMAIN1 and INTERFACE1 should be the same as expectedMasterAccessControlEntry", expectedMasterAccessControlEntry, store.getMasterAccessControlEntries(DOMAIN1, INTERFACE1).get(0));
    assertEquals("Master ACE associated to UID1, DOMAIN1 and INTERFACE1 should be the same as expectedMasterAccessControlEntry", expectedMasterAccessControlEntry, store.getMasterAccessControlEntries(UID1, DOMAIN1, INTERFACE1).get(0));
    CacheManager cacheManager = injector.getInstance(CacheManager.class);
    cacheManager.removeAllCaches();
}
Also used : Injector(com.google.inject.Injector) CacheManager(net.sf.ehcache.CacheManager) Properties(java.util.Properties) Test(org.junit.Test)

Example 28 with CacheManager

use of net.sf.ehcache.CacheManager in project coastal-hazards by USGS-CIDA.

the class CacheResource method clearCache.

boolean clearCache() {
    boolean cleared = false;
    try {
        CacheConfiguration ehConfig = new CacheConfiguration().name(cacheName).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).maxBytesLocalDisk(10, MemoryUnit.MEGABYTES).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).clearOnFlush(true);
        Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(cacheLocation)).dynamicConfig(false).cache(ehConfig);
        CacheManager cacheManager = CacheManager.create(managerConfig);
        Ehcache ehcache = cacheManager.getEhcache(cacheName);
        if (ehcache != null) {
            ehcache.flush();
            ehcache.removeAll();
            cleared = true;
        } else {
            cleared = false;
        }
    } catch (Exception e) {
        log.debug("Unable to clear cache", e);
        cleared = false;
    }
    return cleared;
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 29 with CacheManager

use of net.sf.ehcache.CacheManager in project coastal-hazards by USGS-CIDA.

the class CacheResourceTest method testClearCache.

/**
 * Test of clearCache method, of class CacheResource.
 */
@Test
public void testClearCache() {
    CacheConfiguration ehConfig = new CacheConfiguration().name(CACHE_NAME).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).timeToLiveSeconds(1000).timeToIdleSeconds(1000).clearOnFlush(true);
    Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(CACHE_LOCATION)).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).maxBytesLocalDisk(100, MemoryUnit.MEGABYTES).dynamicConfig(false).cache(ehConfig);
    CacheManager cacheManager = CacheManager.create(managerConfig);
    Ehcache ehcache = cacheManager.getEhcache(CACHE_NAME);
    for (int i = 0; i < 100; i++) {
        Element e = new Element(i, "value" + i);
        ehcache.put(e);
    }
    assertThat(ehcache.getSize(), is(equalTo(100)));
    CacheResource instance = new CacheResource();
    boolean cleared = instance.clearCache();
    assertThat(cleared, is(equalTo(true)));
    assertThat(ehcache.getSize(), is(equalTo(0)));
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 30 with CacheManager

use of net.sf.ehcache.CacheManager in project onebusaway-application-modules by camsys.

the class CacheableMethodManagerTest method test.

@Test
public void test() throws Throwable {
    CacheableMethodKeyFactoryManager factoryManager = new CacheableMethodKeyFactoryManager();
    CacheManager cacheManager = new CacheManager(getClass().getResource("ehcache-test.xml"));
    CacheableMethodManager manager = new CacheableMethodManager();
    manager.setCacheableMethodKeyFactoryManager(factoryManager);
    manager.setCacheManager(cacheManager);
    MockServiceImpl impl = new MockServiceImpl();
    Method method = MockServiceImpl.class.getMethod("evalauteBeanWithParameterAnnotation", MockBean.class, Boolean.TYPE);
    MockBean bean = new MockBean();
    bean.setId("id");
    ProceedingJoinPoint pjp = ProceedingJoinPointFactory.create(impl, impl, MockService.class, method, bean, false);
    Object value = manager.evaluate(pjp);
    assertEquals("test", value);
    assertEquals(1, impl.getEvalauteBeanWithParameterAnnotationCount());
    value = manager.evaluate(pjp);
    assertEquals("test", value);
    assertEquals(1, impl.getEvalauteBeanWithParameterAnnotationCount());
    /**
     * This time we indicate we want a cache refresh
     */
    ProceedingJoinPoint pjp2 = ProceedingJoinPointFactory.create(impl, impl, MockService.class, method, bean, true);
    value = manager.evaluate(pjp2);
    assertEquals("test", value);
    assertEquals(2, impl.getEvalauteBeanWithParameterAnnotationCount());
}
Also used : CacheManager(net.sf.ehcache.CacheManager) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3