Search in sources :

Example 21 with Employee

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with Employee

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());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with Employee

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());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with Employee

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());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with Employee

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());
        }
    });
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.map.impl.querycache.utils.Employee) PredicateConfig(com.hazelcast.config.PredicateConfig) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Employee (com.hazelcast.map.impl.querycache.utils.Employee)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)35 QuickTest (com.hazelcast.test.annotation.QuickTest)35 Test (org.junit.Test)35 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)11 AssertTask (com.hazelcast.test.AssertTask)11 PredicateConfig (com.hazelcast.config.PredicateConfig)10 Config (com.hazelcast.config.Config)9 IMap (com.hazelcast.map.IMap)6 AttributeConfig (com.hazelcast.config.AttributeConfig)5 MapConfig (com.hazelcast.config.MapConfig)4 EntryAdapter (com.hazelcast.core.EntryAdapter)4 EntryEvent (com.hazelcast.core.EntryEvent)4 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)4 Set (java.util.Set)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)3 IFunction (com.hazelcast.core.IFunction)3