use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCache.
@SuppressWarnings("unchecked")
private void testQueryCache(boolean includeValue) {
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
queryCacheConfig.setIncludeValue(includeValue);
Config config = new Config();
config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
IMap<Integer, Integer> map = getIMap(config);
String cacheName = randomString();
for (int i = 0; i < 50; i++) {
map.put(i, i);
}
Predicate<Integer, Integer> predicate = Predicates.sql("this > 5 AND this < 100");
QueryCache<Integer, Integer> cache = map.getQueryCache(cacheName, predicate, includeValue);
for (int i = 50; i < 100; i++) {
map.put(i, i);
}
int expected = 94;
assertQueryCacheSizeEventually(expected, cache);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheTest method testWithInitialPopulation.
private void testWithInitialPopulation(boolean enableInitialPopulation, int expectedSize, int numberOfElementsToPut) {
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
queryCacheConfig.setPopulate(enableInitialPopulation);
Config config = new Config();
config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
IMap<Integer, Employee> map = getIMap(config);
populateMap(map, numberOfElementsToPut);
QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
assertEquals(expectedSize, queryCache.size());
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCache_withLocalListener.
@Test
public void testQueryCache_withLocalListener() {
Config config = new Config().setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
config.getMapConfig(mapName).addQueryCacheConfig(queryCacheConfig);
IMap<Integer, Integer> map = getIMap(config);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
final AtomicInteger countAddEvent = new AtomicInteger();
final AtomicInteger countRemoveEvent = new AtomicInteger();
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
countAddEvent.incrementAndGet();
}
@Override
public void entryRemoved(EntryEvent event) {
countRemoveEvent.incrementAndGet();
}
}, SQL_PREDICATE, true);
for (int i = 0; i < 30; i++) {
map.remove(i);
}
assertTrueEventually(() -> assertEquals(0, queryCache.size()));
assertTrueEventually(() -> assertEquals("Count of add events wrong!", 9, countAddEvent.get()));
assertTrueEventually(() -> assertEquals("Count of remove events wrong!", 9, countRemoveEvent.get()));
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
final String mapName = randomString();
String queryCacheName = randomString();
Config config = new Config();
config.setProperty(ClusterProperty.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);
final 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);
final CountDownLatch waitEventLossNotification = new CountDownLatch(1);
final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
queryCache.tryRecover();
waitEventLossNotification.countDown();
}
}, false);
int count = 30;
for (int i = 0; i < count; i++) {
map.put(i, i);
}
assertOpenEventually(waitEventLossNotification);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(9, queryCache.size());
}
});
// re-put entries and check if broken-sequences holder map will be empty
for (int i = 0; i < count; i++) {
map.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
Map brokenSequences = getBrokenSequences(node, mapName, queryCache);
assertTrue("After recovery, there should be no broken sequences left", brokenSequences.isEmpty());
}
});
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheIndexConfigTest method testIndexConfigIsRespected.
@Test
public void testIndexConfigIsRespected() {
IndexConfig indexConfig = IndexUtils.createTestIndexConfig(IndexType.SORTED, "field");
final Config config = new Config();
final MapConfig mapConfig = new MapConfig("map").addQueryCacheConfig(new QueryCacheConfig().setName("query-cache").setPredicateConfig(new PredicateConfig(Predicates.alwaysTrue())).addIndexConfig(indexConfig));
config.addMapConfig(mapConfig);
final HazelcastInstance instance = createHazelcastInstance(config);
final IMap<Object, Object> map = instance.getMap("map");
final DefaultQueryCache<Object, Object> cache = (DefaultQueryCache<Object, Object>) map.getQueryCache("query-cache");
assertNotNull(cache.indexes.getIndex(indexConfig.getName()));
assertTrue(cache.indexes.getIndex(indexConfig.getName()).isOrdered());
}
Aggregations