Search in sources :

Example 36 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method whenThereIsCacheConfigAndCreatedByInstance_thenReturnSameCache.

private void whenThereIsCacheConfigAndCreatedByInstance_thenReturnSameCache(boolean getCache) {
    Config config = createConfig();
    config.addCacheConfig(createCacheSimpleConfig(CACHE_NAME));
    HazelcastInstance instance = createInstance(config);
    Cache cache1 = retrieveCache(instance, getCache);
    assertNotNull(cache1);
    CachingProvider cachingProvider = createCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    Cache cache2 = cacheManager.getCache(CACHE_NAME);
    assertNotNull(cache2);
    // verify that they are same cache instance
    assertTrue(cache1 == cache2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 37 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method whenThereIsCacheConfigWithURIandCreatedByCacheManager_thenReturnsSameCache.

private void whenThereIsCacheConfigWithURIandCreatedByCacheManager_thenReturnsSameCache(boolean getCache) throws Exception {
    HazelcastInstance instance = createInstance();
    CachingProvider cachingProvider = createCachingProvider(instance);
    Properties properties = HazelcastCachingProvider.propertiesByInstanceItself(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager(new URI("MY-URI"), null, properties);
    Cache cache1 = cacheManager.createCache(CACHE_NAME, createCacheConfig(CACHE_NAME));
    assertNotNull(cache1);
    Cache cache2 = retrieveCache(instance, "MY-URI/" + CACHE_NAME, getCache);
    assertNotNull(cache2);
    // verify that they are same cache instance
    assertTrue(cache1 == cache2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) Properties(java.util.Properties) URI(java.net.URI) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache)

Example 38 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method whenThereIsCacheConfigWithSameNameButDifferentFullNameAndCreatedByCacheManager_thenFail.

private void whenThereIsCacheConfigWithSameNameButDifferentFullNameAndCreatedByCacheManager_thenFail(boolean getCache) throws Exception {
    HazelcastInstance instance = createInstance();
    CachingProvider cachingProvider = createCachingProvider(instance);
    Properties properties = HazelcastCachingProvider.propertiesByInstanceItself(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager(new URI("MY-URI"), null, properties);
    Cache cache1 = cacheManager.createCache(CACHE_NAME, createCacheConfig(CACHE_NAME));
    assertNotNull(cache1);
    retrieveCache(instance, getCache);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) Properties(java.util.Properties) URI(java.net.URI) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache)

Example 39 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheSplitBrainTest method createCache.

private static Cache createCache(HazelcastInstance hazelcastInstance, CacheConfig cacheConfig) {
    CachingProvider cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
    CacheManager cacheManager1 = cachingProvider1.getCacheManager();
    return cacheManager1.createCache(cacheConfig.getName(), cacheConfig);
}
Also used : CacheManager(javax.cache.CacheManager) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 40 with CachingProvider

use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.

the class CacheConfigTest method testGetPreConfiguredCache.

@Test
public void testGetPreConfiguredCache() {
    Config config = new Config();
    config.addCacheConfig(new CacheSimpleConfig().setName("test"));
    int count = 4;
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(count);
    for (int i = 0; i < count; i++) {
        HazelcastInstance instance = factory.newHazelcastInstance(config);
        CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(instance);
        CacheManager cacheManager = provider.getCacheManager();
        Cache<Object, Object> cache = cacheManager.getCache("test");
        assertNotNull("Pre-configured cache cannot be retrieved on instance: " + i, cache);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CachingProvider (javax.cache.spi.CachingProvider)66 CacheManager (javax.cache.CacheManager)48 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)42 Test (org.junit.Test)33 QuickTest (com.hazelcast.test.annotation.QuickTest)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)24 ParallelTest (com.hazelcast.test.annotation.ParallelTest)24 CacheConfig (com.hazelcast.config.CacheConfig)21 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)18 ClientConfig (com.hazelcast.client.config.ClientConfig)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 MutableConfiguration (javax.cache.configuration.MutableConfiguration)12 ICache (com.hazelcast.cache.ICache)10 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)10 Cache (javax.cache.Cache)10 HazelcastCachingProvider (com.hazelcast.cache.HazelcastCachingProvider)9 Config (com.hazelcast.config.Config)8 Data (com.hazelcast.nio.serialization.Data)8 Before (org.junit.Before)8 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)7