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 QueryCacheBasicTest method setup.
// setup a map with 2 query caches, same predicate, one includes values, the other excludes values
@Before
public void setup() {
Config config = new Config();
config.getMapConfig(TEST_MAP_NAME).addQueryCacheConfig(new QueryCacheConfig(QUERY_CACHE_NAME).setPredicateConfig(new PredicateConfig(predicate)).setIncludeValue(includeValues));
if (useNearCache) {
config.getMapConfig(TEST_MAP_NAME).setNearCacheConfig(new NearCacheConfig().setCacheLocalEntries(true));
}
config.setProperty(MapEventPublisherImpl.LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES.getName(), Boolean.toString(useQueryCacheNaturalFilteringStrategy));
instance = createHazelcastInstance(config);
map = getMap(instance, "EntryListenerEventTypesTestMap");
queryCache = map.getQueryCache(QUERY_CACHE_NAME);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheCoalescingTest method getConfig.
private Config getConfig(String mapName, String cacheName) {
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName).setCoalesce(true).setBatchSize(64).setBufferSize(64).setDelaySeconds(3);
Config config = new Config().setProperty(PARTITION_COUNT.getName(), "1");
config.getMapConfig(mapName).addQueryCacheConfig(cacheConfig);
return config;
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheInMemoryFormatTest method testInMemoryFormat.
private void testInMemoryFormat(InMemoryFormat inMemoryFormat, int expectedDeserializationCount) {
SerializableObject.deserializationCount.set(0);
String mapName = randomString();
String cacheName = randomString();
Config config = new Config();
MapConfig mapConfig = config.getMapConfig(mapName);
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
cacheConfig.setInMemoryFormat(inMemoryFormat);
PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
predicateConfig.setSql("__key > -1");
mapConfig.addQueryCacheConfig(cacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, SerializableObject> map = getMap(node, mapName);
map.put(1, new SerializableObject());
QueryCache<Integer, SerializableObject> cache = map.getQueryCache(cacheName);
for (int i = 0; i < 10; i++) {
cache.get(1);
}
assertEquals(expectedDeserializationCount, SerializableObject.deserializationCount.get());
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCachePredicateConfigTest method test_whenSqlIsSet.
@Test
public void test_whenSqlIsSet() {
String mapName = randomString();
String cacheName = randomString();
Config config = new Config();
MapConfig mapConfig = config.getMapConfig(mapName);
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
predicateConfig.setSql("id > 10");
mapConfig.addQueryCacheConfig(cacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Employee> map = getMap(node, mapName);
for (int i = 0; i < 15; i++) {
map.put(i, new Employee(i));
}
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
assertEquals(4, cache.size());
}
Aggregations