use of com.hazelcast.config.MapConfig 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.MapConfig 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());
}
use of com.hazelcast.config.MapConfig 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.MapConfig in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryPortableObjectWithIndex.
@Test
public void testQueryPortableObjectWithIndex() {
String name = randomMapName();
Config config = getConfig();
config.addMapConfig(new MapConfig(name).addMapIndexConfig(new MapIndexConfig("timestamp", true)));
testQueryUsingPortableObject(config, name);
}
use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryPortableObjectWithIndexAndAlwaysCacheValues.
@Test
public void testQueryPortableObjectWithIndexAndAlwaysCacheValues() {
String name = randomMapName();
Config config = getConfig();
config.addMapConfig(new MapConfig(name).setCacheDeserializedValues(CacheDeserializedValues.ALWAYS).addMapIndexConfig(new MapIndexConfig("timestamp", true)));
testQueryUsingPortableObject(config, name);
}
Aggregations