use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class InvalidationMemberAddRemoveTest method createClientConfig.
protected ClientConfig createClientConfig() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty("hazelcast.invalidation.max.tolerated.miss.count", "0");
clientConfig.setProperty("hazelcast.invalidation.reconciliation.interval.seconds", Integer.toString(RECONCILIATION_INTERVAL_SECONDS));
return clientConfig;
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientEvictionTest method testMaxSizeEvictionWorks.
@Test
public void testMaxSizeEvictionWorks() throws Exception {
final int maxSize = 1000;
final int populationCount = 5000;
String mapName = randomString();
String cacheName = randomString();
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
cacheConfig.getEvictionConfig().setSize(maxSize).setEvictionPolicy(EvictionPolicy.LFU).setMaximumSizePolicy(EvictionConfig.MaxSizePolicy.ENTRY_COUNT);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addQueryCacheConfig(mapName, cacheConfig);
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> map = client.getMap(mapName);
// expecting at least populationCount - maxSize + 10 evicted entries according to max size.
// 10 states an error margin since eviction does not sweep precise number of entries.
int margin = 10;
final CountDownLatch evictedCount = new CountDownLatch(populationCount - maxSize - margin);
final QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, TruePredicate.INSTANCE, true);
String listener = cache.addEntryListener(new EntryEvictedListener() {
@Override
public void entryEvicted(EntryEvent event) {
evictedCount.countDown();
}
}, false);
for (int i = 0; i < populationCount; i++) {
map.put(i, i);
}
assertOpenEventually(evictedCount);
assertQueryCacheEvicted(maxSize, margin, cache);
assertTrue(cache.removeEntryListener(listener));
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method testNearCache_clearFromRemote.
@Test
public void testNearCache_clearFromRemote() {
String mapName = randomMapName();
HazelcastInstance server = hazelcastFactory.newHazelcastInstance(newConfig());
NearCacheConfig nearCacheConfig = newInvalidationEnabledNearCacheConfig();
ClientConfig clientConfig = newClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final IMap<Integer, Integer> map = client.getMap(mapName);
final int size = 147;
populateMap(map, size);
populateNearCache(map, size);
server.getMap(mapName).clear();
// Near Cache should be empty
assertTrueEventually(new AssertTask() {
public void run() {
for (int i = 0; i < size; i++) {
assertNull(map.get(i));
}
}
});
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapClear_call_from_member.
@Test
public void receives_one_clearEvent_after_mapClear_call_from_member() {
// start new member and populate map
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
IMap<Integer, Integer> memberMap = member.getMap("test");
populateMap(memberMap, 1000);
// populate client near cache
NearCacheConfig nearCacheConfig = newNearCacheConfig();
ClientConfig clientConfig = newClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> clientMap = client.getMap("test");
populateNearCache(clientMap, 1000);
// add test listener to count clear events
final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
// clear map from member side
memberMap.clear();
// sleep for a while to see there is another clear event coming
sleepSeconds(2);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals("Expecting only 1 clear event", 1, handler.getClearEventCount());
}
});
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method getNearCachedMapFromClient.
protected <K, V> IMap<K, V> getNearCachedMapFromClient(Config config, NearCacheConfig nearCacheConfig) {
String mapName = randomMapName();
hazelcastFactory.newHazelcastInstance(config);
nearCacheConfig.setName(mapName + "*");
ClientConfig clientConfig = newClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
return client.getMap(mapName);
}
Aggregations