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