use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheCreateDestroyTest method tryRecover_fails_after_destroy.
@Test
public void tryRecover_fails_after_destroy() {
final String mapName = "someMap";
final String queryCacheName = "testCache";
HazelcastInstance server = factory.newHazelcastInstance(newConfigWithQueryCache(mapName, queryCacheName));
server.getMap(mapName);
IMap map = server.getMap(mapName);
QueryCache queryCache = map.getQueryCache(queryCacheName);
queryCache.destroy();
assertFalse(queryCache.tryRecover());
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class QueryCacheCreateDestroyTest method recreated_queryCache_gets_updates_from_restarted_server.
@Test
public void recreated_queryCache_gets_updates_from_restarted_server() {
final String mapName = "someMap";
final String queryCacheName = "testCache";
// start a server
HazelcastInstance server = factory.newHazelcastInstance();
server.getMap(mapName);
// start a serverWithQueryCache
HazelcastInstance serverWithQueryCache = factory.newHazelcastInstance(newConfigWithQueryCache(mapName, queryCacheName));
// create query-cache
IMap map = serverWithQueryCache.getMap(mapName);
QueryCache queryCache = map.getQueryCache(queryCacheName);
// shutdown other member, at this point only serverWithQueryCache is alive
server.shutdown();
// start new server to emulate server re-start
HazelcastInstance newServer = factory.newHazelcastInstance();
IMap newServerMap = newServer.getMap(mapName);
// populate new map from newServer
for (int i = 0; i < 1000; i++) {
newServerMap.put(i, i);
}
// destroy query-cache from serverWithQueryCache
queryCache.destroy();
// new query-cache should have all updates from server side
queryCache = map.getQueryCache(queryCacheName);
int queryCacheSize = queryCache.size();
assertEquals(1000, queryCacheSize);
}
use of com.hazelcast.map.QueryCache 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