Search in sources :

Example 91 with MutableConfiguration

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"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Example 92 with MutableConfiguration

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));
}
Also used : MutableConfiguration(javax.cache.configuration.MutableConfiguration) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 93 with MutableConfiguration

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"));
}
Also used : HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Example 94 with MutableConfiguration

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");
}
Also used : MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 95 with MutableConfiguration

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();
}
Also used : CacheManager(javax.cache.CacheManager) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)118 Test (org.junit.Test)72 CacheManager (javax.cache.CacheManager)67 Cache (javax.cache.Cache)32 CachingProvider (javax.cache.spi.CachingProvider)27 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Test (org.junit.jupiter.api.Test)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)11 URI (java.net.URI)11 Duration (javax.cache.expiry.Duration)10 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6 RedisProcess (org.redisson.RedisRunner.RedisProcess)6 JCacheManager (org.infinispan.jcache.embedded.JCacheManager)5