Search in sources :

Example 6 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class EventQueuePluginTest method testCache.

@Test
public void testCache() {
    CompleteConfiguration<Integer, Integer> cacheConfig = new MutableConfiguration<Integer, Integer>().addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<Integer, Integer>(FactoryBuilder.factoryOf(new TestCacheListener()), null, true, true));
    CachingProvider memberProvider = createServerCachingProvider(hz);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    final ICache<Integer, Integer> cache = memberCacheManager.createCache(CACHE_NAME, cacheConfig);
    spawn(new Runnable() {

        @Override
        public void run() {
            Random random = new Random();
            for (int i = 0; i < EVENT_COUNTER; i++) {
                int key = random.nextInt(Integer.MAX_VALUE);
                cache.putAsync(key, 23);
                cache.removeAsync(key);
            }
        }
    });
    assertContainsEventually("ICache '/hz/" + CACHE_NAME + "' CREATED sampleCount=", "ICache '/hz/" + CACHE_NAME + "' REMOVED sampleCount=");
}
Also used : Random(java.util.Random) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) 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)

Example 7 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager 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 8 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCachePreloaderTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean createClient) {
    CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
    CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    ICache<K, V> memberCache = memberCacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
    if (!createClient) {
        return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new ICacheDataStructureAdapter<K, V>(memberCache), false, null, null);
    }
    NearCacheTestContext<K, V, Data, String> clientContext = createClientContext(cacheConfig);
    return new NearCacheTestContext<K, V, Data, String>(clientContext.serializationService, clientContext.nearCacheInstance, member, clientContext.nearCacheAdapter, new ICacheDataStructureAdapter<K, V>(memberCache), false, clientContext.nearCache, clientContext.nearCacheManager, clientContext.cacheManager, memberCacheManager);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)

Example 9 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCacheSerializationCountTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
    Config config = getConfig();
    prepareSerializationConfig(config.getSerializationConfig());
    ClientConfig clientConfig = getClientConfig();
    if (nearCacheConfig != null) {
        clientConfig.addNearCacheConfig(nearCacheConfig);
    }
    prepareSerializationConfig(clientConfig.getSerializationConfig());
    CacheConfig<K, V> cacheConfig = createCacheConfig(cacheInMemoryFormat);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
    ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ICacheDataStructureAdapter<K, V>(clientCache), new ICacheDataStructureAdapter<K, V>(memberCache), false, nearCache, nearCacheManager, cacheManager, memberCacheManager);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 10 with HazelcastServerCacheManager

use of com.hazelcast.cache.impl.HazelcastServerCacheManager in project hazelcast by hazelcast.

the class ClientCacheNearCachePreloaderTest method createContext.

@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean createNearCacheInstance) {
    Config config = getConfig();
    CacheConfig<K, V> cacheConfig = getCacheConfig(nearCacheConfig);
    HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
    CachingProvider memberProvider = createServerCachingProvider(member);
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    ICache<K, V> memberCache = memberCacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
    ICacheDataStructureAdapter<K, V> dataAdapter = new ICacheDataStructureAdapter<>(memberCache);
    if (createNearCacheInstance) {
        return createNearCacheContextBuilder(cacheConfig).setDataInstance(member).setDataAdapter(dataAdapter).setMemberCacheManager(memberCacheManager).build();
    }
    return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, getSerializationService(member)).setDataInstance(member).setDataAdapter(dataAdapter).build();
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) Data(com.hazelcast.internal.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider)

Aggregations

HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)14 CachingProvider (javax.cache.spi.CachingProvider)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)9 ClientConfig (com.hazelcast.client.config.ClientConfig)8 CacheConfig (com.hazelcast.config.CacheConfig)6 Config (com.hazelcast.config.Config)6 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)5 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)4 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)4 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)4 NearCacheConfig (com.hazelcast.config.NearCacheConfig)4 ICacheDataStructureAdapter (com.hazelcast.internal.adapter.ICacheDataStructureAdapter)4 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)4 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)4 Data (com.hazelcast.nio.serialization.Data)4 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)3 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)3 NearCacheTestUtils.createNearCacheConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.createNearCacheConfig)3