use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheIndexTest method test_entrySet_withPredicate_whenValuesNotCached.
@Test
public void test_entrySet_withPredicate_whenValuesNotCached() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance client = factory.newHazelcastClient();
IMap<Integer, Employee> map = client.getMap(mapName);
int putCount = 111;
for (int i = 0; i < putCount; i++) {
map.put(i, new Employee(i));
}
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
cache.addIndex(IndexType.SORTED, "id");
for (int i = 17; i < putCount; i++) {
map.remove(i);
}
// just choose arbitrary numbers to prove whether #entrySet with predicate is working
int smallerThan = 17;
int expectedSize = 0;
assertEntrySetSizeEventually(expectedSize, Predicates.sql("id < " + smallerThan), cache);
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListeningKey_withMultipleListener.
@Test
public void shouldReceiveEvent_whenListeningKey_withMultipleListener() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance instance = factory.newHazelcastClient();
IMap<Integer, Employee> map = instance.getMap(mapName);
final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
int keyToListen = 109;
final QueryCacheAdditionListener addListener = new QueryCacheAdditionListener();
cache.addEntryListener(addListener, Predicates.sql("id > 100"), keyToListen, true);
final QueryCacheRemovalListener removeListener = new QueryCacheRemovalListener();
cache.addEntryListener(removeListener, Predicates.sql("id > 100"), keyToListen, true);
// populate map before construction of query cache
int count = 111;
for (int i = 0; i < count; i++) {
map.put(i, new Employee(i));
}
for (int i = 0; i < count; i++) {
map.remove(i);
}
for (int i = 0; i < count; i++) {
map.put(i, new Employee(i));
}
for (int i = 0; i < count; i++) {
map.remove(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
int cacheSize = cache.size();
String message = "Cache size is=" + cacheSize;
assertEquals(message, 0, cacheSize);
assertEquals(message, 2, addListener.getAddedEventCount());
assertEquals(message, 2, removeListener.getRemovedEventCount());
}
});
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListening_withPredicate.
@Test
public void shouldReceiveEvent_whenListening_withPredicate() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance instance = factory.newHazelcastClient();
IMap<Integer, Employee> map = instance.getMap(mapName);
final QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
cache.addEntryListener(listener, Predicates.sql("id > 100"), true);
final int putCount = 111;
for (int i = 0; i < putCount; i++) {
map.put(i, new Employee(i));
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(10, listener.getAddedEventCount());
}
});
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheListenerTest method shouldReceiveEvent_whenListeningKey_withPredicate.
@Test
public void shouldReceiveEvent_whenListeningKey_withPredicate() {
String mapName = randomString();
String cacheName = randomString();
HazelcastInstance instance = factory.newHazelcastClient();
IMap<Integer, Employee> map = instance.getMap(mapName);
QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName, TRUE_PREDICATE, true);
int keyToListen = 109;
final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
cache.addEntryListener(listener, Predicates.sql("id > 100"), keyToListen, true);
int putCount = 111;
for (int i = 0; i < putCount; i++) {
map.put(i, new Employee(i));
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(1, listener.getAddedEventCount());
}
});
}
use of com.hazelcast.map.impl.querycache.utils.Employee in project hazelcast by hazelcast.
the class ClientQueryCacheListenerTest method listenerShouldBeRegistered_whenConfiguredProgrammatically.
@Test
public void listenerShouldBeRegistered_whenConfiguredProgrammatically() {
final int valueCount = 100;
String mapName = randomString();
String qcName = randomString();
final QueryCacheAdditionListener listener = new QueryCacheAdditionListener();
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(qcName).setPredicateConfig(new PredicateConfig(TRUE_PREDICATE)).addEntryListenerConfig(new EntryListenerConfig(listener, true, true));
ClientConfig config = new ClientConfig().addQueryCacheConfig(mapName, queryCacheConfig);
HazelcastInstance instance = factory.newHazelcastClient(config);
IMap<Integer, Employee> map = instance.getMap(mapName);
// trigger creation of the query cache
map.getQueryCache(qcName);
for (int i = 0; i < valueCount; i++) {
map.put(i, new Employee(i));
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(valueCount, listener.getAddedEventCount());
}
});
}
Aggregations