@SuppressWarnings("WeakerAccess") protected ClassLoader getClassLoader(CachingProvider cachingProvider) { // todo (5.3) : shouldn't this use Hibernate's AggregatedClassLoader? return cachingProvider.getDefaultClassLoader(); }
@BeforeClass(alwaysRun = true) public void beforeClass() { CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName()); cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); }
@Before public void setUp() throws Exception { cachingProvider = Caching.getCachingProvider(); cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-integration.xml") .toURI(), cachingProvider.getDefaultClassLoader()); }
@BeforeClass public void beforeClass() { CachingProvider provider = Caching.getCachingProvider(PROVIDER_NAME); cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); }
JCacheProfiler() { random = new Random(); count = new LongAdder(); CachingProvider provider = Caching.getCachingProvider(CaffeineCachingProvider.class.getName()); CacheManager cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); cache = cacheManager.createCache("profiler", new MutableConfiguration<>()); executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder() .setPriority(Thread.MIN_PRIORITY).setDaemon(true).build()); }
@Before public void setUp() throws Exception { CachingProvider cachingProvider = Caching.getCachingProvider(); cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-serializer.xml") .toURI(), cachingProvider.getDefaultClassLoader()); }
/** Resolves the annotations to the provider as multiple are on the IDE's classpath. */ void configureCachingProvider() { CachingProvider provider = Caching.getCachingProvider( CaffeineCachingProvider.class.getName()); CacheManager cacheManager = provider.getCacheManager( provider.getDefaultURI(), provider.getDefaultClassLoader()); bind(CacheResolverFactory.class).toInstance(new DefaultCacheResolverFactory(cacheManager)); bind(CacheManager.class).toInstance(cacheManager); } }
@Test public void testCacheLevelOnlyOneOverridesCacheManagerLevel() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/org/ehcache/docs/ehcache-107-mbeans-cache-manager-config.xml") .toURI(), provider.getDefaultClassLoader()); Cache<String, String> cache = cacheManager.getCache("overrideOneCache", String.class, String.class); @SuppressWarnings("unchecked") Eh107Configuration<String, String> configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(false)); assertThat(isMbeanRegistered("overrideOneCache", MBEAN_MANAGEMENT_TYPE), is(true)); assertThat(isMbeanRegistered("overrideOneCache", MBEAN_STATISTICS_TYPE), is(false)); }
@Test public void testEnabledAtCacheManagerLevel() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/org/ehcache/docs/ehcache-107-mbeans-cache-manager-config.xml") .toURI(), provider.getDefaultClassLoader()); Cache<String, String> cache = cacheManager.getCache("stringCache", String.class, String.class); @SuppressWarnings("unchecked") Eh107Configuration<String, String> configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(true)); assertThat(isMbeanRegistered("stringCache", MBEAN_MANAGEMENT_TYPE), is(true)); assertThat(isMbeanRegistered("stringCache", MBEAN_STATISTICS_TYPE), is(true)); }
@Test public void testCacheLevelOverridesCacheManagerLevel() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/org/ehcache/docs/ehcache-107-mbeans-cache-manager-config.xml") .toURI(), provider.getDefaultClassLoader()); Cache<String, String> cache = cacheManager.getCache("overrideCache", String.class, String.class); @SuppressWarnings("unchecked") Eh107Configuration<String, String> configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(configuration.isManagementEnabled(), is(false)); assertThat(configuration.isStatisticsEnabled(), is(false)); assertThat(isMbeanRegistered("overrideCache", MBEAN_MANAGEMENT_TYPE), is(false)); assertThat(isMbeanRegistered("overrideCache", MBEAN_STATISTICS_TYPE), is(false)); }
@Test public void testEnabledAtCacheLevel() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-cache-config.xml") .toURI(), provider.getDefaultClassLoader()); Cache<String, String> cache = cacheManager.getCache("stringCache", String.class, String.class); @SuppressWarnings("unchecked") Eh107Configuration<String, String> configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(true)); assertThat(isMbeanRegistered("stringCache", MBEAN_MANAGEMENT_TYPE), is(true)); assertThat(isMbeanRegistered("stringCache", MBEAN_STATISTICS_TYPE), is(true)); }
@Test public void testManagementEnabledOverriddenFromTemplate() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml") .toURI(), provider.getDefaultClassLoader()); MutableConfiguration<Long, String> configuration = new MutableConfiguration<>(); configuration.setTypes(Long.class, String.class); configuration.setManagementEnabled(true); configuration.setStatisticsEnabled(true); Cache<Long, String> cache = cacheManager.createCache("disables-mbeans", configuration); @SuppressWarnings("unchecked") Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(eh107Configuration.isManagementEnabled(), is(false)); assertThat(eh107Configuration.isStatisticsEnabled(), is(false)); assertThat(isMbeanRegistered("disables-mbeans", MBEAN_MANAGEMENT_TYPE), is(false)); assertThat(isMbeanRegistered("disables-mbeans", MBEAN_STATISTICS_TYPE), is(false)); }
@Test public void testManagementDisabledOverriddenFromTemplate() throws Exception { CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml") .toURI(), provider.getDefaultClassLoader()); MutableConfiguration<Long, String> configuration = new MutableConfiguration<>(); configuration.setTypes(Long.class, String.class); configuration.setManagementEnabled(false); configuration.setStatisticsEnabled(false); Cache<Long, String> cache = cacheManager.createCache("enables-mbeans", configuration); @SuppressWarnings("unchecked") Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class); assertThat(eh107Configuration.isManagementEnabled(), is(true)); assertThat(eh107Configuration.isStatisticsEnabled(), is(true)); assertThat(isMbeanRegistered("enables-mbeans", MBEAN_MANAGEMENT_TYPE), is(true)); assertThat(isMbeanRegistered("enables-mbeans", MBEAN_STATISTICS_TYPE), is(true)); }
@Test public void testCacheUsesCacheManagerClassLoaderForDefaultURI() { CachingProvider cachingProvider = Caching.getCachingProvider(); LimitedClassLoader limitedClassLoader = new LimitedClassLoader(cachingProvider.getDefaultClassLoader()); CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), limitedClassLoader); MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); Cache<Object, Object> cache = cacheManager.createCache("test", configuration); cache.put(1L, new Customer(1L)); try { cache.get(1L); fail("Expected AssertionError"); } catch (AssertionError e) { assertThat(e.getMessage(), is("No com.pany here")); } }
public CacheResolverFactoryImpl() { provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()); }
/** * Constructs the resolver */ public DefaultCacheResolverFactory() { CachingProvider provider = Caching.getCachingProvider(); this.cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()); }
/** * Obtains a CacheManager using a string-based name from the default * CachingProvider. * * @return a CacheManager * @throws Exception */ public static CacheManager getCacheManager() throws Exception { CachingProvider provider = Caching.getCachingProvider(); URI uri = provider.getDefaultURI(); return Caching.getCachingProvider().getCacheManager(uri, provider.getDefaultClassLoader()); }
@Test public void getCacheManager_nullUriParameter() { CachingProvider provider = Caching.getCachingProvider(); final URI NULL_URI = null; CacheManager manager = provider.getCacheManager(NULL_URI, provider.getDefaultClassLoader(), null); assertNotNull(manager); assertEquals(provider.getDefaultURI(), manager.getURI()); }
@Test public void getCacheManager_defaultURI() { CachingProvider provider = Caching.getCachingProvider(); assertSame(provider.getCacheManager(), provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader())); CacheManager manager = provider.getCacheManager(); assertEquals(provider.getDefaultURI(), manager.getURI()); }
@Test public void getCacheManager_nullClassLoader() { CachingProvider provider = Caching.getCachingProvider(); final ClassLoader NULL_CLASSLOADER = null; // null classloader is treated as provider.getDefaultClassLoader(). CacheManager manager = provider.getCacheManager(provider.getDefaultURI(), NULL_CLASSLOADER, null); assertNotNull(manager); CacheManager sameManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), null); assertEquals(sameManager, manager); assertEquals(sameManager.getClassLoader(), manager.getClassLoader()); }