use of com.hazelcast.map.QueryCache 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(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);
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, Predicates.sql("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.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheCreateDestroyTest method create_after_destroy_gives_fresh_query_cache_instance.
@Test
public void create_after_destroy_gives_fresh_query_cache_instance() {
final String mapName = "someMap";
final String queryCacheName = "testCache";
HazelcastInstance server = factory.newHazelcastInstance();
HazelcastInstance client = factory.newHazelcastClient(newClientConfigWithQueryCache(mapName, queryCacheName));
// create client-side query-cache
IMap clientMap = client.getMap(mapName);
QueryCache clientQueryCache = clientMap.getQueryCache(queryCacheName);
clientQueryCache.destroy();
QueryCache newQueryCache = clientMap.getQueryCache(queryCacheName);
assertFalse(clientQueryCache == newQueryCache);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheCreateDestroyTest 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 server
HazelcastInstance server = factory.newHazelcastInstance();
server.getMap(mapName);
// start client with query-cache config
HazelcastInstance client = factory.newHazelcastClient(newClientConfigWithQueryCache(mapName, queryCacheName));
// create client-side query-cache
IMap clientMap = client.getMap(mapName);
QueryCache clientQueryCache = clientMap.getQueryCache(queryCacheName);
// shutdown all members, at this point only client is alive
factory.shutdownAllMembers();
// start new server to emulate server re-start
HazelcastInstance newServer = factory.newHazelcastInstance();
IMap newServerMap = newServer.getMap(mapName);
// populate new map on server
for (int i = 0; i < 1000; i++) {
newServerMap.put(i, i);
}
// destroy client query-cache from client-side to re-create it,
// otherwise it stays tied with previous server
clientQueryCache.destroy();
// new client-side query-cache should have all updates from server side
clientQueryCache = clientMap.getQueryCache(queryCacheName);
int queryCacheSize = clientQueryCache.size();
assertEquals(1000, queryCacheSize);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_concurrent_destroy.
@Test
public void event_service_is_empty_after_queryCache_concurrent_destroy() throws InterruptedException {
final HazelcastInstance node1 = factory.newHazelcastInstance();
HazelcastInstance node2 = factory.newHazelcastInstance();
String mapName = "test";
HazelcastInstance client = factory.newHazelcastClient();
final IMap<Integer, Integer> map = client.getMap(mapName);
populateMap(map);
final AtomicBoolean stop = new AtomicBoolean(false);
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < STRESS_TEST_THREAD_COUNT; i++) {
Thread thread = new Thread() {
@Override
public void run() {
while (!stop.get()) {
QueryCache queryCache = map.getQueryCache("a", Predicates.alwaysTrue(), true);
queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {
@Override
public void entryAdded(EntryEvent<Integer, Integer> event) {
}
}, true);
queryCache.destroy();
}
}
};
threads.add(thread);
}
for (Thread thread : threads) {
thread.start();
}
sleepSeconds(STRESS_TEST_RUN_SECONDS);
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertNoUserListenerLeft(node1);
assertNoUserListenerLeft(node2);
assertNoUserListenerLeft(mapName, client);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
String mapName = randomMapName("map");
String queryCacheName = randomMapName("cache");
Config config = getConfig();
config.setProperty(PARTITION_COUNT.getName(), "1");
factory.newHazelcastInstance(config);
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(1111);
queryCacheConfig.setDelaySeconds(3);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> map = client.getMap(mapName);
// set test sequencer to subscriber
int count = 30;
setTestSequencer(map, 9);
final QueryCache queryCache = map.getQueryCache(queryCacheName, Predicates.sql("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);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
});
}
Aggregations