use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheConfigTest method testDifferentQueryCacheInstancesObtained_whenIMapConfiguredWithWildCard.
@Test
public void testDifferentQueryCacheInstancesObtained_whenIMapConfiguredWithWildCard() {
QueryCacheConfig cacheConfig = new QueryCacheConfig();
cacheConfig.setName("cache");
cacheConfig.getPredicateConfig().setSql("__key > 10");
MapConfig mapConfig = new MapConfig();
mapConfig.setName("test*");
mapConfig.addQueryCacheConfig(cacheConfig);
Config config = new Config();
config.addMapConfig(mapConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Integer> map1 = getMap(node, "test1");
IMap<Integer, Integer> map2 = getMap(node, "test2");
QueryCache<Integer, Integer> queryCache1 = map1.getQueryCache("cache");
QueryCache<Integer, Integer> queryCache2 = map2.getQueryCache("cache");
for (int i = 0; i < 20; i++) {
map1.put(i, i);
}
for (int i = 0; i < 30; i++) {
map2.put(i, i);
}
assertQueryCacheSizeEventually(9, queryCache1);
assertQueryCacheSizeEventually(19, queryCache2);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheEventLostListenerTest method testListenerNotified_uponEventLoss.
@Test
public void testListenerNotified_uponEventLoss() {
String mapName = randomString();
String queryCacheName = randomString();
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
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 all nodes
int count = 30;
// expecting one lost event per partition
final CountDownLatch lossCount = new CountDownLatch(1);
final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
lossCount.countDown();
}
}, false);
for (int i = 0; i < count; i++) {
map.put(i, i);
}
assertOpenEventually(lossCount);
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheGuaranteesTest method continuesToReceiveEvents_afterNodeJoins.
@Test
public void continuesToReceiveEvents_afterNodeJoins() {
String mapName = randomString();
String queryCacheName = randomString();
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "271");
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(100);
queryCacheConfig.setDelaySeconds(3);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map = getMap(node, mapName);
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map2 = node2.getMap(mapName);
for (int i = 100; i < 120; i++) {
map2.put(i, i);
}
HazelcastInstance node3 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map3 = node3.getMap(mapName);
for (int i = 150; i < 157; i++) {
map3.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(36, queryCache.size());
}
});
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCacheGuaranteesTest method continuesToReceiveEvents_afterNodeShutdown.
@Test
public void continuesToReceiveEvents_afterNodeShutdown() {
String mapName = randomString();
String queryCacheName = randomString();
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
Config config = new Config();
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(100);
queryCacheConfig.setDelaySeconds(6);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map = (IMap<Integer, Integer>) node.<Integer, Integer>getMap(mapName);
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map2 = node2.getMap(mapName);
for (int i = 200; i < 220; i++) {
map2.put(i, i);
}
HazelcastInstance node3 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map3 = node3.getMap(mapName);
for (int i = 350; i < 357; i++) {
map3.put(i, i);
}
node3.shutdown();
for (int i = 220; i < 227; i++) {
map2.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(43, queryCache.size());
}
});
}
use of com.hazelcast.config.QueryCacheConfig in project hazelcast by hazelcast.
the class QueryCachePredicateConfigTest method test_whenClassNameIsSet.
@Test
public void test_whenClassNameIsSet() {
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.setClassName("com.hazelcast.map.impl.querycache.TestPredicate");
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(0, cache.size());
}
Aggregations