@Override public final String getName() { return this.cache.getName(); }
@Override public String getName() { return cache.getName(); }
@Override public final String getName() { return this.cache.getName(); }
/** Returns the object name of the management bean. */ private static ObjectName getObjectName(Cache<?, ?> cache, MBeanType type) { String cacheManagerName = sanitize(cache.getCacheManager().getURI().toString()); String cacheName = sanitize(cache.getName()); try { String name = String.format("javax.cache:type=Cache%s,CacheManager=%s,Cache=%s", type, cacheManagerName, cacheName); return new ObjectName(name); } catch (MalformedObjectNameException e) { String msg = String.format("Illegal ObjectName for cacheManager=[%s], cache=[%s]", cacheManagerName, cacheName); throw new CacheException(msg, e); } }
private void onError(Throwable throwable) { publishCacheEvent(() -> new CacheOnErrorEvent(cache.getName(), throwable)); }
private void onCacheHit(K cacheKey) { metrics.onCacheHit(); publishCacheEvent(() -> new CacheOnHitEvent<>(cache.getName(), cacheKey)); }
private void onCacheMiss(K cacheKey) { metrics.onCacheMiss(); publishCacheEvent(() -> new CacheOnMissEvent<>(cache.getName(), cacheKey)); }
private void checkConfigurationJmx(Supplier<Cache<?, ?>> cacheSupplier) throws Exception { Cache<?, ?> cache = cacheSupplier.get(); @SuppressWarnings("unchecked") CompleteConfiguration<?, ?> configuration = cache.getConfiguration(CompleteConfiguration.class); assertThat(configuration.isManagementEnabled(), is(true)); assertThat(configuration.isStatisticsEnabled(), is(true)); String name = "javax.cache:Cache=%s,CacheManager=%s,type=CacheStatistics"; ManagementFactory.getPlatformMBeanServer().getObjectInstance( new ObjectName(String.format(name, cache.getName(), PROVIDER_NAME))); } }
@Override public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) { String cacheName = cacheInvocationContext.getCacheName(); Cache<K, V> mock = mock(Cache.class); given(mock.getName()).willReturn(cacheName); return mock; }
@SuppressWarnings("unchecked") public void addCache(String name) { cacheNames.add(name); Cache cache = mock(Cache.class); given(cache.getName()).willReturn(name); given(cacheManager.getCache(name)).willReturn(cache); }
@Test public void testEhcacheCloseRemovesFromCacheManager() throws Exception { CachingProvider provider = Caching.getCachingProvider(); javax.cache.CacheManager cacheManager = provider.getCacheManager(this.getClass() .getResource("/ehcache-107-types.xml") .toURI(), getClass().getClassLoader()); MutableConfiguration<Long, String> cache1Conf = new MutableConfiguration<>(); javax.cache.Cache<Long, String> cache = cacheManager.createCache("cache1", cache1Conf); cacheManager.unwrap(org.ehcache.CacheManager.class).removeCache(cache.getName()); try { assertThat(cacheManager.getCache(cache.getName()), nullValue()); } finally { cacheManager.close(); } }
@Test public void testCacheManagerCloseLenientToEhcacheClosed() throws Exception { CachingProvider provider = Caching.getCachingProvider(); javax.cache.CacheManager cacheManager = provider.getCacheManager(this.getClass() .getResource("/ehcache-107-types.xml") .toURI(), getClass().getClassLoader()); MutableConfiguration<Long, String> cache1Conf = new MutableConfiguration<>(); javax.cache.Cache<Long, String> cache = cacheManager.createCache("cache1", cache1Conf); cacheManager.unwrap(org.ehcache.CacheManager.class).removeCache(cache.getName()); cacheManager.close(); } }
protected CacheResolver getCacheResolver(CacheInvocationContext<? extends Annotation> context, String cacheName) { CacheResolver cacheResolver = mock(CacheResolver.class); javax.cache.Cache cache; if (cacheName == null) { cache = null; } else { cache = mock(javax.cache.Cache.class); given(cache.getName()).willReturn(cacheName); } given(cacheResolver.resolveCache(context)).willReturn(cache); return cacheResolver; }
public JCacheManager(Cache<K, V> cache) { this.configuration = null; this.camelContext = null; this.classLoader = null; this.cacheName = cache.getName(); this.provider = null; this.manager = null; this.cache = cache; }
/** {@inheritDoc} */ public String getCacheProviderName() { return "jCache:" + featuresCache.getName() + ":" + featuresCache.getCacheManager().getCachingProvider().toString(); }
@Test public void testCacheMXBeanManagementTurnedOff() throws Exception { cache.getCacheManager().enableManagement(cache.getName(), false); try { lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough"); fail(); } catch (javax.management.InstanceNotFoundException e) { //expected. Shouldn't be there } }
@Before public void moreSetUp() { cache = getCacheManager().getCache(getTestCacheName(), Long.class, String.class); cache.getCacheManager().enableStatistics(cache.getName(), true); statisticsUpdateTimeoutMillis = Integer.valueOf(System.getProperty(STATISTICS_UPDATE_TIMEOUT_PROPERTY, DEFAULT_STATISTICS_UPDATE_TIMEOUT_SECONDS)); }
@Test public void createCache_NameOK() { String name = "c1"; getCacheManager().createCache(name, new MutableConfiguration()); Cache cache = getCacheManager().getCache(name); assertEquals(name, cache.getName()); }
@Test public void getOrCreateCache_StatusOK() { String name = "c1"; getCacheManager().createCache(name, new MutableConfiguration()); Cache cache = getCacheManager().getCache(name); assertNotNull(cache); assertEquals(name, cache.getName()); }
@Test public void cachingProviderGetCache() { String name = "c1"; Caching.getCachingProvider().getCacheManager().createCache(name, new MutableConfiguration().setTypes(Long.class, String.class)); Cache cache = Caching.getCache(name, Long.class, String.class); assertEquals(name, cache.getName()); Caching.getCachingProvider().getCacheManager().destroyCache(name); }