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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations