use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class InvalidationMetadataDistortionTest method createCacheConfig.
@Override
protected CacheConfig createCacheConfig(InMemoryFormat inMemoryFormat) {
CacheConfig cacheConfig = super.createCacheConfig(inMemoryFormat);
cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
return cacheConfig;
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCacheConfigTest method createCacheConfigOnAllNodes.
@Test
public void createCacheConfigOnAllNodes() {
final String CACHE_NAME = "myCache";
HazelcastInstance client = null;
HazelcastInstance server1 = null;
HazelcastInstance server2 = null;
try {
Config config = new Config();
CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig().setName(CACHE_NAME).setBackupCount(// Be sure that cache put operation is mirrored to backup node
1);
config.addCacheConfig(cacheSimpleConfig);
// Create servers with configured caches
server1 = Hazelcast.newHazelcastInstance(config);
server2 = Hazelcast.newHazelcastInstance(config);
ICacheService cacheService1 = getCacheService(server1);
ICacheService cacheService2 = getCacheService(server2);
// Create the hazelcast client instance
client = HazelcastClient.newHazelcastClient();
// Create the client cache manager
CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<String, String> cache = cacheManager.getCache(CACHE_NAME);
assertNotNull(cache);
CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
assertNotNull(cacheService1.getCacheConfig(cacheConfig.getNameWithPrefix()));
assertNotNull(cacheService2.getCacheConfig(cacheConfig.getNameWithPrefix()));
// First attempt to use the cache will trigger to create its record store.
// So, we are testing also this case. There should not be any exception.
// In here, we are testing both of nodes since there is a backup,
// put is also applied to other (backup node).
cache.put("key", "value");
} finally {
if (client != null) {
client.shutdown();
}
if (server1 != null) {
server1.shutdown();
}
if (server2 != null) {
server2.shutdown();
}
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_removed.
@Test
public void test_cachePartitionLostListener_removed() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final String registrationId = iCache.addPartitionLostListener(mock(CachePartitionLostListener.class));
assertRegistrationsSizeEventually(instance, cacheName, 1);
assertTrue(iCache.removePartitionLostListener(registrationId));
assertRegistrationsSizeEventually(instance, cacheName, 0);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked_fromOtherNode.
@Test
public void test_cachePartitionLostListener_invoked_fromOtherNode() {
final String cacheName = randomName();
HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance1);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
iCache.addPartitionLostListener(listener);
assertRegistrationsSizeEventually(instance1, cacheName, 1);
assertRegistrationsSizeEventually(instance2, cacheName, 1);
final CacheService cacheService1 = getNode(instance1).getNodeEngine().getService(CacheService.SERVICE_NAME);
final CacheService cacheService2 = getNode(instance2).getNodeEngine().getService(CacheService.SERVICE_NAME);
final int partitionId = 5;
cacheService1.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
cacheService2.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CallbackAwareClientDelegatingFutureTest method createCache.
private Cache createCache(int blockMilis, boolean throwError) {
CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfiguration cacheConfig = new CacheConfig().setReadThrough(true).setCacheLoaderFactory(new BlockableCacheLoaderFactory(blockMilis, throwError));
return cacheManager.createCache(CACHE_NAME, cacheConfig);
}
Aggregations