use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_cacheLoader_if_itIs_hazelcastInstanceAware.
@Test
public void test_inject_hazelcastInstance_to_cacheLoader_if_itIs_hazelcastInstanceAware() {
long id1 = generateUniqueHazelcastInjectionId();
long id2 = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
cacheConfig.setCacheLoaderFactory(new HazelcastInstanceAwareCacheLoaderFactory(id1, id2));
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
Cache<Integer, Integer> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.put(1, 1);
assertEquals("Hazelcast instance has not been injected into cache loader factory!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id1));
assertEquals("Hazelcast instance has not been injected into cache loader!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id2));
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheThroughHazelcastInstanceTest method whenThereIsCacheConfigAndCreatedByCacheManager_thenReturnsSameCache.
private void whenThereIsCacheConfigAndCreatedByCacheManager_thenReturnsSameCache(boolean getCache) {
HazelcastInstance instance = createInstance();
CachingProvider cachingProvider = createCachingProvider(instance);
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache cache1 = cacheManager.createCache(CACHE_NAME, createCacheConfig(CACHE_NAME));
assertNotNull(cache1);
Cache cache2 = retrieveCache(instance, getCache);
assertNotNull(cache2);
// verify that they are same cache instance
assertTrue(cache1 == cache2);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheStatsTest method doTestForOwnedEntryCount.
private void doTestForOwnedEntryCount(boolean useBackups, boolean triggerMigration) {
final String cacheName = randomName();
ICache<Integer, String> cache;
CacheStatistics[] allStats;
HazelcastInstance instance2 = null;
if (useBackups) {
// Create the second instance to store data as backup.
instance2 = getHazelcastInstance();
CachingProvider cp = getCachingProvider(instance2);
CacheManager cm = cp.getCacheManager();
cache = createCache(cacheName);
ICache<Integer, String> c = cm.getCache(cacheName).unwrap(ICache.class);
allStats = new CacheStatistics[] { cache.getLocalCacheStatistics(), c.getLocalCacheStatistics() };
} else {
cache = createCache(cacheName);
allStats = new CacheStatistics[] { cache.getLocalCacheStatistics() };
}
final int ENTRY_COUNT = 100;
for (int i = 0; i < ENTRY_COUNT; i++) {
cache.put(i, "Value-" + i);
}
assertOwnedEntryCount(ENTRY_COUNT, allStats);
if (triggerMigration && instance2 != null) {
// Shutdown the second instance to trigger migration so first instance will be owner of all partitions.
instance2.shutdown();
allStats = new CacheStatistics[] { cache.getLocalCacheStatistics() };
assertOwnedEntryCount(ENTRY_COUNT, allStats);
}
for (int i = 0; i < 10; i++) {
cache.remove(i);
}
assertOwnedEntryCount(ENTRY_COUNT - 10, allStats);
for (int i = 10; i < ENTRY_COUNT; i++) {
cache.remove(i);
}
assertOwnedEntryCount(0, allStats);
for (int i = 0; i < ENTRY_COUNT; i++) {
cache.put(i, "Value-" + i);
}
assertOwnedEntryCount(ENTRY_COUNT, allStats);
if (triggerMigration) {
// Create the second instance to trigger migration
// so the second instance will be owner of some partitions
// and the first instance will lose ownership of some instances.
instance2 = getHazelcastInstance();
CachingProvider cp = getCachingProvider(instance2);
CacheManager cm = cp.getCacheManager();
ICache<Integer, String> c = cm.getCache(cacheName).unwrap(ICache.class);
allStats = new CacheStatistics[] { cache.getLocalCacheStatistics(), c.getLocalCacheStatistics() };
assertOwnedEntryCount(ENTRY_COUNT, allStats);
}
cache.clear();
assertOwnedEntryCount(0, allStats);
for (int i = 0; i < ENTRY_COUNT; i++) {
cache.put(i, "Value-" + i);
}
assertOwnedEntryCount(ENTRY_COUNT, allStats);
cache.destroy();
assertOwnedEntryCount(0, allStats);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ICacheDataStructureAdapterTest method setUp.
@Before
public void setUp() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
HazelcastServerCachingProvider cachingProvider = createCachingProvider(hazelcastInstance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
cache = (ICache<Integer, String>) cacheManager.createCache("CacheDataStructureAdapterTest", cacheConfig);
adapter = new ICacheDataStructureAdapter<Integer, String>(cache);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ClientManagerTest method testMultiClusterMultipleClients.
@Test
public void testMultiClusterMultipleClients() throws MalformedURLException, URISyntaxException {
final String cacheName = "test";
final String key1 = "key1";
final String valuecm1 = "Value-is-cm1";
final String valuecm2 = "Value-is-cm2";
final HazelcastClientCachingProvider cachingProvider = new HazelcastClientCachingProvider();
final CacheManager cm1 = cachingProvider.getCacheManager(uri1, null);
final CacheManager cm2 = cachingProvider.getCacheManager(uri2, null);
final CacheConfig<String, String> cacheConfig = new CacheConfig<String, String>();
final Cache<String, String> cache1 = cm1.createCache(cacheName, cacheConfig);
final Cache<String, String> cache2 = cm2.createCache(cacheName, cacheConfig);
cache1.put(key1, valuecm1);
cache2.put(key1, valuecm2);
assertEquals(valuecm1, cache1.get(key1));
assertEquals(valuecm2, cache2.get(key1));
cachingProvider.close(uri1, null);
cachingProvider.close(uri2, null);
// cm1.close();
// cm2.close();
final CacheManager cm11 = cachingProvider.getCacheManager(uri1, null);
final Cache<String, String> cache11 = cm11.getCache(cacheName);
assertEquals(valuecm1, cache11.get(key1));
cm11.close();
}
Aggregations