Search in sources :

Example 46 with Cache

use of javax.cache.Cache 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) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstanceCacheManager(com.hazelcast.cache.impl.HazelcastInstanceCacheManager) CacheManager(javax.cache.CacheManager) Properties(java.util.Properties) URI(java.net.URI) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache)

Example 47 with Cache

use of javax.cache.Cache 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) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstanceCacheManager(com.hazelcast.cache.impl.HazelcastInstanceCacheManager) CacheManager(javax.cache.CacheManager) Properties(java.util.Properties) URI(java.net.URI) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache)

Example 48 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) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstanceCacheManager(com.hazelcast.cache.impl.HazelcastInstanceCacheManager) CacheManager(javax.cache.CacheManager) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 49 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) ICacheManager(com.hazelcast.core.ICacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstanceCacheManager(com.hazelcast.cache.impl.HazelcastInstanceCacheManager) CacheManager(javax.cache.CacheManager) Properties(java.util.Properties) URI(java.net.URI) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Example 50 with Cache

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

the class CacheExpirationTest method testBackupsAreEmptyAfterExpiration.

@Test
public void testBackupsAreEmptyAfterExpiration() {
    SimpleExpiryListener listener = new SimpleExpiryListener();
    CacheConfig cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(100, 100, 100), listener);
    Cache cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
    }
    assertEqualsEventually(KEY_RANGE, listener.getExpirationCount());
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
        assertBackupSizeEventually(0, backupAccessor);
    }
}
Also used : BackupAccessor(com.hazelcast.test.backup.BackupAccessor) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Cache (javax.cache.Cache)271 IgniteCache (org.apache.ignite.IgniteCache)157 Test (org.junit.Test)130 Ignite (org.apache.ignite.Ignite)101 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)68 List (java.util.List)62 Map (java.util.Map)56 ScanQuery (org.apache.ignite.cache.query.ScanQuery)54 ArrayList (java.util.ArrayList)51 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)45 QueryCursor (org.apache.ignite.cache.query.QueryCursor)43 HashMap (java.util.HashMap)41 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)41 Collection (java.util.Collection)38 HashSet (java.util.HashSet)38 CacheManager (javax.cache.CacheManager)38 CacheException (javax.cache.CacheException)35 IgniteEx (org.apache.ignite.internal.IgniteEx)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)32 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)32