use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheExpiryTest method testCacheStatisticsRemoveAllNoneExpired.
@Test
public void testCacheStatisticsRemoveAllNoneExpired() throws Exception {
ExpiryPolicy policy = new CreatedExpiryPolicy(Duration.ETERNAL);
setupExpiryPolicyClientServer(policy);
MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient)).setStatisticsEnabled(true);
Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
for (int i = 0; i < 100; i++) {
cache.put(i, i + 100);
}
cache.removeAll();
assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CacheRemovals"));
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheManagerManagementTest method testCacheManagementOffThenOnThenOff.
@Test
public void testCacheManagementOffThenOnThenOff() throws Exception {
MutableConfiguration configuration = new MutableConfiguration();
configuration.setManagementEnabled(false);
cacheManager.createCache("cache1", configuration);
cacheManager.createCache("cache2", configuration);
Set<? extends ObjectName> names = mBeanServer.queryNames(new ObjectName("javax.cache:*"), null);
Assert.assertTrue(names.size() == 0);
configuration.setManagementEnabled(true);
cacheManager.createCache("cache3", configuration);
cacheManager.createCache("cache4", configuration);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
cacheManager.enableManagement("cache3", false);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1));
cacheManager.enableManagement("cache3", true);
assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheMBStatisticsBeanTest method testExpiryOnCreation.
@Test
public void testExpiryOnCreation() throws Exception {
// close cache since need to configure cache with ExpireOnCreationPolicy
CacheManager mgr = cache.getCacheManager();
mgr.destroyCache(cache.getName());
MutableConfiguration<Long, String> config = new MutableConfiguration<Long, String>();
config.setStatisticsEnabled(true);
config.setTypes(Long.class, String.class);
config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnCreationPolicy.class));
cache = mgr.createCache(getTestCacheName(), config);
cache.put(1L, "hello");
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
Map<Long, String> map = new HashMap<Long, String>();
map.put(2L, "goodbye");
map.put(3L, "world");
cache.putAll(map);
assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class CacheMXBeanTest method testCustomConfiguration.
@Test
public void testCustomConfiguration() throws Exception {
boolean storeByValue = false;
MutableConfiguration configuration = new MutableConfiguration().setReadThrough(false).setWriteThrough(false).setStoreByValue(storeByValue).setTypes(java.math.BigDecimal.class, java.awt.Color.class).setManagementEnabled(true).setStatisticsEnabled(false);
Cache cache = null;
try {
cache = getCacheManager().createCache("customCache", configuration);
} catch (UnsupportedOperationException e) {
storeByValue = true;
configuration.setStoreByValue(storeByValue);
cache = getCacheManager().createCache("customCache", configuration);
}
assertEquals("java.math.BigDecimal", lookupManagementAttribute(cache, CacheConfiguration, "KeyType"));
assertEquals("java.awt.Color", lookupManagementAttribute(cache, CacheConfiguration, "ValueType"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "WriteThrough"));
assertEquals(storeByValue, lookupManagementAttribute(cache, CacheConfiguration, "StoreByValue"));
assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "StatisticsEnabled"));
assertEquals(true, lookupManagementAttribute(cache, CacheConfiguration, "ManagementEnabled"));
// this used to just call close() but that does not work if an implementation maintains statistics on the cluster.
cache.getCacheManager().destroyCache("customCache");
}
use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.
the class ListenerTest method missingListenerFactory.
@Test
public void missingListenerFactory() {
CacheManager mgr = getCachingProvider().getCacheManager();
cache = mgr.createCache(CACHE_NAME, new MutableConfiguration<>());
assertThatCode(() -> cache.registerCacheEntryListener(SYNC_LISTENER)).isInstanceOf(IllegalArgumentException.class);
cache.close();
}
Aggregations