use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class AbstractClientCachePartitionIteratorTest method getCacheProxy.
private <K, V> ClientCacheProxy<K, V> getCacheProxy() {
String cacheName = randomString();
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<K, V> config = new CacheConfig<K, V>();
config.getEvictionConfig().setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT).setSize(10000000);
return (ClientCacheProxy<K, V>) cacheManager.createCache(cacheName, config);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCacheClearTest method testClientInvalidationListenerCallCount.
@Test
public void testClientInvalidationListenerCallCount() {
ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
final AtomicInteger counter = new AtomicInteger(0);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new EventHandler() {
@Override
public void handle(Object event) {
counter.getAndIncrement();
}
@Override
public void beforeListenerRegister() {
}
@Override
public void onListenerRegister() {
}
}, config.getNameWithPrefix());
cache.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, counter.get());
}
}, 2);
// Make sure that the callback is not called for a while
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= 1);
}
}, 3);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCacheClearTest method testClientInvalidationListenerCallCountWhenServerCacheClearUsed.
@Test
public void testClientInvalidationListenerCallCountWhenServerCacheClearUsed() {
ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
final AtomicInteger counter = new AtomicInteger(0);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new EventHandler() {
@Override
public void handle(Object event) {
counter.getAndIncrement();
}
@Override
public void beforeListenerRegister() {
}
@Override
public void onListenerRegister() {
}
}, config.getNameWithPrefix());
ICache<Object, Object> serverCache = getHazelcastInstance().getCacheManager().getCache(config.getName());
serverCache.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, counter.get());
}
}, 2);
// Make sure that the callback is not called for a while
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= 1);
}
}, 3);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_registered.
@Test
public void test_cachePartitionLostListener_registered() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
final Cache<Integer, String> cache = cacheManager.createCache(cacheName, cacheConfig);
final ICache iCache = cache.unwrap(ICache.class);
iCache.addPartitionLostListener(new CachePartitionLostListener() {
@Override
public void partitionLost(CachePartitionLostEvent event) {
}
});
assertRegistrationsSizeEventually(instance, cacheName, 1);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked.
@Test
public void test_cachePartitionLostListener_invoked() {
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 EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
iCache.addPartitionLostListener(listener);
final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
final int partitionId = 5;
cacheService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
Aggregations