use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheConfigTest method testQueryCacheNameConfiguredWithWildCard.
@Test
public void testQueryCacheNameConfiguredWithWildCard() {
QueryCacheConfig cacheConfig = new QueryCacheConfig();
String mapNamePrefix = "MyMap";
String mapNameNameWithWildcard = mapNamePrefix + "*";
cacheConfig.setName("myCache");
cacheConfig.getPredicateConfig().setSql("__key > 10");
HazelcastInstance hazelcastInstance = createInstanceWithQueryCacheConfig(mapNameNameWithWildcard, cacheConfig);
IMap<Integer, Integer> map1 = getMap(hazelcastInstance, mapNamePrefix + "_1");
QueryCache<Integer, Integer> queryCache1 = map1.getQueryCache("myCache");
assertNotNull(queryCache1);
}
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());
assertEquals(0, SerializableObject.deserializationCount.get());
QueryCache<Integer, SerializableObject> cache = map.getQueryCache(cacheName);
for (int i = 0; i < 10; i++) {
cache.get(1);
int expectedInitialCountInLoop = inMemoryFormat == BINARY ? i + 1 : 1;
assertEquals("Error on iteration " + i, expectedInitialCountInLoop, SerializableObject.deserializationCount.get());
}
assertEquals(expectedDeserializationCount, SerializableObject.deserializationCount.get());
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheMapLoaderTest method getConfig.
private Config getConfig(String mapName, String cacheName) {
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.setInMemoryFormat(inMemoryFormat);
mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(mapLoader);
QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
mapConfig.addQueryCacheConfig(cacheConfig);
return config;
}
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());
}
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());
}
});
}
Aggregations