Search in sources :

Example 6 with Cache

use of javax.cache.Cache in project hazelcast by hazelcast.

the class BasicCacheLiteMemberTest method testCachesDestroyFromOtherManagers.

@Test
public void testCachesDestroyFromOtherManagers() {
    CacheManager cacheManager = instanceCachingProvider.getCacheManager();
    CacheManager cacheManager2 = liteCachingProvider.getCacheManager();
    MutableConfiguration configuration = new MutableConfiguration();
    final Cache c1 = cacheManager.createCache("c1", configuration);
    final Cache c2 = cacheManager2.createCache("c2", configuration);
    c1.put("key", "value");
    c2.put("key", "value");
    cacheManager.close();
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            c2.get("key");
        }
    }, 10);
}
Also used : CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) Cache(javax.cache.Cache) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Cache

use of javax.cache.Cache in project hazelcast by hazelcast.

the class CacheFromDifferentNodesTest method testCachesDestroy.

@Test
public void testCachesDestroy() {
    CacheManager cacheManager = cachingProvider1.getCacheManager();
    CacheManager cacheManager2 = cachingProvider2.getCacheManager();
    MutableConfiguration configuration = new MutableConfiguration();
    final Cache c1 = cacheManager.createCache("c1", configuration);
    final Cache c2 = cacheManager2.getCache("c1");
    c1.put("key", "value");
    cacheManager.destroyCache("c1");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            try {
                c2.get("key");
                throw new AssertionError("get should throw IllegalStateException");
            } catch (IllegalStateException e) {
            //ignored as expected
            }
        }
    });
}
Also used : CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) Cache(javax.cache.Cache) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with Cache

use of javax.cache.Cache in project hazelcast by hazelcast.

the class CacheListenerTest method testSyncListener_shouldNotHang_whenCacheClosed.

@Test
public void testSyncListener_shouldNotHang_whenCacheClosed() {
    final CachingProvider provider = getCachingProvider();
    final String cacheName = randomMapName();
    testSyncListener_shouldNotHang_AfterAction(cacheName, provider, new Runnable() {

        @Override
        public void run() {
            Cache cache = provider.getCacheManager().getCache(cacheName);
            cache.close();
        }
    });
}
Also used : HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with Cache

use of javax.cache.Cache in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method whenThereIsCacheConfigWithSameNameButDifferentFullNameAndCreatedByInstance_thenReturnDifferentCache.

private void whenThereIsCacheConfigWithSameNameButDifferentFullNameAndCreatedByInstance_thenReturnDifferentCache(boolean getCache) throws Exception {
    Config config = createConfig();
    config.addCacheConfig(createCacheSimpleConfig(CACHE_NAME));
    HazelcastInstance instance = createInstance(config);
    Cache cache1 = retrieveCache(instance, getCache);
    assertNotNull(cache1);
    CachingProvider cachingProvider = createCachingProvider(instance);
    Properties properties = HazelcastCachingProvider.propertiesByInstanceItself(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager(new URI("MY-URI"), null, properties);
    Cache cache2 = cacheManager.getCache(CACHE_NAME);
    assertNotNull(cache2);
    assertNotEquals(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) Properties(java.util.Properties) URI(java.net.URI) 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 10 with Cache

use of javax.cache.Cache 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)

Aggregations

Cache (javax.cache.Cache)107 IgniteCache (org.apache.ignite.IgniteCache)71 Ignite (org.apache.ignite.Ignite)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 SqlQuery (org.apache.ignite.cache.query.SqlQuery)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 CacheManager (javax.cache.CacheManager)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 ScanQuery (org.apache.ignite.cache.query.ScanQuery)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)11 Test (org.junit.Test)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 CacheException (javax.cache.CacheException)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 Collection (java.util.Collection)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 CachingProvider (javax.cache.spi.CachingProvider)8