use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast-simulator by hazelcast.
the class CacheUtils method createCacheManager.
/**
* Creates a cache manager
*
* @param hazelcastInstance the HazelcastInstance
* @param uri the uri
* @return the CacheManager for given URI and default ClassLoader.
*/
public static HazelcastCacheManager createCacheManager(HazelcastInstance hazelcastInstance, URI uri) {
Properties properties = propertiesByInstanceName(hazelcastInstance.getName());
CachingProvider cachingProvider = getCachingProvider(hazelcastInstance);
return (HazelcastCacheManager) cachingProvider.getCacheManager(uri, null, properties);
}
use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast by hazelcast.
the class CacheConfigTest method configUrlShouldBeUsedAsInstanceNameIfInstanceNameIsNotSpecified.
@Test
public void configUrlShouldBeUsedAsInstanceNameIfInstanceNameIsNotSpecified() throws Exception {
URI uri = new URI("MY-SCOPE");
Properties properties = new Properties();
properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, configUrl2.toString());
HazelcastCacheManager cacheManager = (HazelcastCacheManager) Caching.getCachingProvider().getCacheManager(uri, null, properties);
assertNotNull(cacheManager);
assertEquals(configUrl2.toString(), cacheManager.getHazelcastInstance().getName());
}
use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast by hazelcast.
the class CacheConfigTest method instanceNamePropertyShouldBeUsedEvenThoughInstanceNameIsSpecifiedInTheConfig.
@Test
public void instanceNamePropertyShouldBeUsedEvenThoughInstanceNameIsSpecifiedInTheConfig() throws Exception {
String instanceName = randomName();
URI uri = new URI("MY-SCOPE");
Properties properties = new Properties();
properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, configUrl1.toString());
properties.setProperty(HazelcastCachingProvider.HAZELCAST_INSTANCE_NAME, instanceName);
HazelcastCacheManager cacheManager = (HazelcastCacheManager) Caching.getCachingProvider().getCacheManager(uri, null, properties);
assertNotNull(cacheManager);
assertEquals(instanceName, cacheManager.getHazelcastInstance().getName());
}
use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast by hazelcast.
the class CacheBackupAccessor method size.
@Override
public int size() {
InternalPartitionService partitionService = getNode(cluster[0]).getPartitionService();
IPartition[] partitions = partitionService.getPartitions();
int count = 0;
for (IPartition partition : partitions) {
Address replicaAddress = partition.getReplicaAddress(replicaIndex);
if (replicaAddress == null) {
continue;
}
HazelcastInstance hz = getInstanceWithAddress(replicaAddress);
HazelcastInstanceImpl hazelcastInstanceImpl = getHazelcastInstanceImpl(hz);
CachingProvider provider = createServerCachingProvider(hazelcastInstanceImpl);
HazelcastCacheManager cacheManager = (HazelcastServerCacheManager) provider.getCacheManager();
NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(cacheName);
int partitionId = partition.getPartitionId();
count += runOnPartitionThread(hz, new SizeCallable(cacheService, cacheNameWithPrefix, partitionId), partitionId);
}
return count;
}
use of com.hazelcast.cache.HazelcastCacheManager in project hazelcast by hazelcast.
the class CacheExpirationPromotionTest method promoted_replica_should_send_eviction_to_other_backup.
@Test
public void promoted_replica_should_send_eviction_to_other_backup() {
final CachingProvider provider = createServerCachingProvider(instances[0]);
provider.getCacheManager().createCache(cacheName, getCacheConfig());
HazelcastCacheManager cacheManager = (HazelcastServerCacheManager) provider.getCacheManager();
final String keyOwnedByLastInstance = generateKeyOwnedBy(instances[nodeCount - 1]);
ICache<String, String> cache = cacheManager.getCache(cacheName).unwrap(ICache.class);
cache.put(keyOwnedByLastInstance, "dummyVal", new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
final BackupAccessor<String, String> backupAccessor = TestBackupUtils.newCacheAccessor(instances, cacheName, 1);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotNull(backupAccessor.get(keyOwnedByLastInstance));
}
});
instances[nodeCount - 1].shutdown();
// the backup replica became the primary, now the backup is the other node.
// we check if the newly appointed replica sent expiration to backups
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, backupAccessor.size());
}
});
}
Aggregations