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 = new Config();
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, 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);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
});
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheEventLostListenerTest method testListenerNotified_onEventLoss.
@Test
public void testListenerNotified_onEventLoss() throws Exception {
int count = 30;
String mapName = randomString();
String queryCacheName = randomString();
IMap<Integer, Integer> mapNode = node.getMap(mapName);
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> mapClient = client.getMap(mapName);
setTestSequencer(mapClient, 9);
// expecting one lost event publication per partition.
final CountDownLatch lostEventCount = new CountDownLatch(1);
QueryCache queryCache = mapClient.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
lostEventCount.countDown();
}
}, false);
for (int i = 0; i < count; i++) {
mapNode.put(i, i);
}
assertOpenEventually(lostEventCount);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheCreateDestroyTest method multiple_getQueryCache_calls_returns_same_query_cache_instance.
@Test
public void multiple_getQueryCache_calls_returns_same_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 clientQueryCache1 = clientMap.getQueryCache(queryCacheName);
QueryCache clientQueryCache2 = clientMap.getQueryCache(queryCacheName);
assertTrue(clientQueryCache1 == clientQueryCache2);
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheMemoryLeakTest method stress_user_listener_removal_upon_query_cache_destroy.
@Test
public void stress_user_listener_removal_upon_query_cache_destroy() throws InterruptedException {
final String[] mapNames = new String[] { "mapA", "mapB", "mapC", "mapD" };
Config config = getConfig();
final HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
HazelcastInstance node3 = factory.newHazelcastInstance(config);
final HazelcastInstance client = factory.newHazelcastClient();
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()) {
String name = mapNames[getInt(0, 4)];
final IMap<Integer, Integer> map = client.getMap(name);
int key = getInt(0, Integer.MAX_VALUE);
map.put(key, 1);
QueryCache queryCache = map.getQueryCache(name, Predicates.alwaysTrue(), true);
queryCache.get(key);
queryCache.addEntryListener(new EntryAddedListener<Integer, Integer>() {
@Override
public void entryAdded(EntryEvent<Integer, Integer> event) {
}
}, true);
queryCache.destroy();
map.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(node3);
for (String mapName : mapNames) {
// this is to ensure no user added listener is left on this client side query-cache
assertNoUserListenerLeft(mapName, client);
}
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
for (HazelcastInstance instance : instances) {
// this is to ensure no publisher side resource is left on server side event service
assertServerSideEventServiceCleared(instance);
}
}
use of com.hazelcast.map.QueryCache in project hazelcast by hazelcast.
the class ClientQueryCacheMemoryLeakTest method event_service_is_empty_after_queryCache_destroy.
@Test
public void event_service_is_empty_after_queryCache_destroy() {
String mapName = "test";
HazelcastInstance node1 = factory.newHazelcastInstance();
HazelcastInstance node2 = factory.newHazelcastInstance();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap(mapName);
QueryCache queryCache = map.getQueryCache(mapName, Predicates.alwaysTrue(), true);
queryCache.destroy();
assertNoUserListenerLeft(node1);
assertNoUserListenerLeft(node2);
}
Aggregations