use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class ClientQueryCacheTest method getConfig.
private ClientConfig getConfig(String queryCacheName, boolean enableInitialPopulation, String mapName) {
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setPopulate(enableInitialPopulation).getPredicateConfig().setImplementation(TruePredicate.INSTANCE);
return addConfig(queryCacheConfig, mapName);
}
use of com.hazelcast.config.QueryCacheConfig 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.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
String mapName = randomString();
String queryCacheName = randomString();
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(1111);
queryCacheConfig.setDelaySeconds(3);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
mapConfig.setBackupCount(0);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
setTestSequencer(node, 9);
setTestSequencer(node2, 9);
IMap<Integer, Integer> map = getMap(node, mapName);
node2.getMap(mapName);
//set test sequencer to subscribers.
int count = 30;
final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
queryCache.tryRecover();
}
}, false);
for (int i = 0; i < count; i++) {
map.put(i, i);
}
AssertTask task = new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
};
assertTrueEventually(task);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class TestClientApplicationContext method testFullQueryCacheConfig.
@Test
public void testFullQueryCacheConfig() throws Exception {
ClientConfig config = client6.getClientConfig();
QueryCacheConfig queryCacheConfig = getQueryCacheConfig(config);
EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
assertTrue(entryListenerConfig.isIncludeValue());
assertFalse(entryListenerConfig.isLocal());
assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
assertFalse(queryCacheConfig.isIncludeValue());
assertEquals("my-query-cache-1", queryCacheConfig.getName());
assertEquals(12, queryCacheConfig.getBatchSize());
assertEquals(33, queryCacheConfig.getBufferSize());
assertEquals(12, queryCacheConfig.getDelaySeconds());
assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
assertTrue(queryCacheConfig.isCoalesce());
assertFalse(queryCacheConfig.isPopulate());
assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaxSizePolicy());
assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
assertEquals(2, queryCacheConfig.getIndexConfigs().size());
IndexConfig hashIndex = queryCacheConfig.getIndexConfigs().get(0);
assertEquals(IndexType.HASH, hashIndex.getType());
assertNull(hashIndex.getName());
assertEquals(1, hashIndex.getAttributes().size());
assertEquals("name", hashIndex.getAttributes().get(0));
IndexConfig sortedIndex = queryCacheConfig.getIndexConfigs().get(1);
assertEquals(IndexType.SORTED, sortedIndex.getType());
assertEquals("sortedIndex", sortedIndex.getName());
assertEquals(2, sortedIndex.getAttributes().size());
assertEquals("age", sortedIndex.getAttributes().get(0));
assertEquals("name", sortedIndex.getAttributes().get(1));
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testFullQueryCacheConfig.
@Test
public void testFullQueryCacheConfig() {
MapConfig mapConfig = config.getMapConfig("map-with-query-cache");
QueryCacheConfig queryCacheConfig = mapConfig.getQueryCacheConfigs().get(0);
EntryListenerConfig entryListenerConfig = queryCacheConfig.getEntryListenerConfigs().get(0);
assertTrue(entryListenerConfig.isIncludeValue());
assertFalse(entryListenerConfig.isLocal());
assertEquals("com.hazelcast.spring.DummyEntryListener", entryListenerConfig.getClassName());
assertFalse(queryCacheConfig.isIncludeValue());
assertEquals("my-query-cache-1", queryCacheConfig.getName());
assertEquals(12, queryCacheConfig.getBatchSize());
assertEquals(33, queryCacheConfig.getBufferSize());
assertEquals(12, queryCacheConfig.getDelaySeconds());
assertEquals(InMemoryFormat.OBJECT, queryCacheConfig.getInMemoryFormat());
assertTrue(queryCacheConfig.isCoalesce());
assertTrue(queryCacheConfig.isSerializeKeys());
assertFalse(queryCacheConfig.isPopulate());
assertIndexesEqual(queryCacheConfig);
assertEquals("__key > 12", queryCacheConfig.getPredicateConfig().getSql());
assertEquals(EvictionPolicy.LRU, queryCacheConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(MaxSizePolicy.ENTRY_COUNT, queryCacheConfig.getEvictionConfig().getMaxSizePolicy());
assertEquals(111, queryCacheConfig.getEvictionConfig().getSize());
}
Aggregations