Search in sources :

Example 1 with HazelcastCacheManager

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);
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) Properties(java.util.Properties) CachingProvider(javax.cache.spi.CachingProvider)

Example 2 with HazelcastCacheManager

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());
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) Properties(java.util.Properties) URI(java.net.URI) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with HazelcastCacheManager

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());
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) Properties(java.util.Properties) URI(java.net.URI) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with HazelcastCacheManager

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;
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Accessors.getHazelcastInstanceImpl(com.hazelcast.test.Accessors.getHazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Address(com.hazelcast.cluster.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IPartition(com.hazelcast.internal.partition.IPartition) CachingProvider(javax.cache.spi.CachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CacheService(com.hazelcast.cache.impl.CacheService)

Example 5 with HazelcastCacheManager

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());
        }
    });
}
Also used : HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) AssertTask(com.hazelcast.test.AssertTask) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)10 Test (org.junit.Test)7 Properties (java.util.Properties)5 SlowTest (com.hazelcast.test.annotation.SlowTest)4 URI (java.net.URI)4 CachingProvider (javax.cache.spi.CachingProvider)4 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)3 HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 CacheFromDifferentNodesTest (com.hazelcast.cache.CacheFromDifferentNodesTest)2 HazelcastInstanceImpl (com.hazelcast.instance.impl.HazelcastInstanceImpl)2 Node (com.hazelcast.instance.impl.Node)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 Accessors.getHazelcastInstanceImpl (com.hazelcast.test.Accessors.getHazelcastInstanceImpl)2 Accessors.getNode (com.hazelcast.test.Accessors.getNode)2 CacheService (com.hazelcast.cache.impl.CacheService)1 Address (com.hazelcast.cluster.Address)1