Search in sources :

Example 41 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.

the class ClientCacheCreationTest method createSingleCache_whenMemberBounce.

@Test
public void createSingleCache_whenMemberBounce() throws InterruptedException {
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    hazelcastInstance.shutdown();
    final CountDownLatch cacheCreated = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            MutableConfiguration configuration = new MutableConfiguration();
            cacheManager.createCache("xmlCache", configuration);
            cacheCreated.countDown();
        }
    }).start();
    // leave some gap to let create cache to start and retry
    Thread.sleep(2000);
    Hazelcast.newHazelcastInstance();
    assertOpenEventually(cacheCreated);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheCreationTest(com.hazelcast.cache.CacheCreationTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 42 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project ignite by apache.

the class CacheStopAndDestroySelfTest method testTckStyleCreateDestroyClose.

/**
 * Tests start -> destroy -> start -> close using CacheManager.
 */
@Test
public void testTckStyleCreateDestroyClose() throws Exception {
    startGridsMultiThreaded(gridCount());
    CacheManager mgr = Caching.getCachingProvider().getCacheManager();
    String cacheName = "cache";
    mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    mgr.destroyCache(cacheName);
    Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
    cache.close();
    // Check second close succeeds without exception.
    cache.close();
    try {
        cache.get(1);
        fail();
    } catch (IllegalStateException ignored) {
    // No-op;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 43 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project wcomponents by BorderTech.

the class PlainTextRendererImpl method getCache.

/**
 * @return the cache instance
 */
protected synchronized Cache<String, String> getCache() {
    Cache<String, String> cache = Caching.getCache(CACHE_NAME, String.class, String.class);
    if (cache == null) {
        final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
        MutableConfiguration<String, String> config = new MutableConfiguration<>();
        config.setTypes(String.class, String.class);
        config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
        // No need to serialize the result
        config.setStoreByValue(false);
        cache = mgr.createCache(CACHE_NAME, config);
    }
    return cache;
}
Also used : CacheManager(javax.cache.CacheManager) Duration(javax.cache.expiry.Duration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 44 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project wcomponents by BorderTech.

the class VelocityCacheImpl method getCache.

/**
 * @return the cache instance
 */
protected synchronized Cache<Object, Resource> getCache() {
    Cache<Object, Resource> cache = Caching.getCache(CACHE_NAME, Object.class, Resource.class);
    if (cache == null) {
        final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
        MutableConfiguration<Object, Resource> config = new MutableConfiguration<>();
        config.setTypes(Object.class, Resource.class);
        config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
        // Velocity template classes are not serializable so use by ref.
        config.setStoreByValue(false);
        cache = mgr.createCache(CACHE_NAME, config);
    }
    return cache;
}
Also used : Resource(org.apache.velocity.runtime.resource.Resource) CacheManager(javax.cache.CacheManager) Duration(javax.cache.expiry.Duration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 45 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project Payara by payara.

the class PayaraCacheResolverFactory method getExceptionCacheResolver.

@Override
public CacheResolver getExceptionCacheResolver(CacheMethodDetails<CacheResult> cmd) {
    CacheResult result = cmd.getCacheAnnotation();
    String cacheName = result.exceptionCacheName();
    Cache cache = cacheManager.getCache(cacheName);
    if ((cache == null)) {
        cache = cacheManager.createCache(cacheName, new MutableConfiguration<Object, Object>());
    }
    return new PayaraCacheResolver(cache);
}
Also used : CacheResult(javax.cache.annotation.CacheResult) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)146 Test (org.junit.Test)97 CacheManager (javax.cache.CacheManager)76 CachingProvider (javax.cache.spi.CachingProvider)35 Cache (javax.cache.Cache)32 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 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)11 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)10 Duration (javax.cache.expiry.Duration)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)7 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6