Search in sources :

Example 6 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NestedPredicateTest method nestedAttributeQuery_predicates.

@Test
public void nestedAttributeQuery_predicates() {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = e.get("limb.name").equal("leg");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[0])[0].getName());
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class MapTransactionRegressionTest method test_Issue1076.

@Test
public void test_Issue1076() {
    Config config = getConfig();
    final HazelcastInstance inst = createHazelcastInstance(config);
    IMap map = inst.getMap("default");
    EntryListener<String, Integer> l = new EntryAdapter<String, Integer>() {
    };
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate<String, Integer> p = e.get("this").equal(1);
    map.addEntryListener(l, p, null, false);
    for (Integer i = 0; i < 100; i++) {
        TransactionContext context = inst.newTransactionContext();
        context.beginTransaction();
        TransactionalMap<String, Integer> txnMap = context.getMap("default");
        txnMap.remove(i.toString());
        context.commitTransaction();
    }
    assertEquals(0, map.size());
    inst.shutdown();
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) EntryAdapter(com.hazelcast.core.EntryAdapter) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 8 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.

@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
    int mapSize = 10;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    for (int i = 0; i < mapSize; i++) {
        map.put(i, new Employee(i, "", 0, true, 0D));
    }
    populateNearCache(map, mapSize);
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = e.get("salary").equal(0);
    map.executeOnEntries(entry -> {
        Employee employee = entry.getValue();
        double currentSalary = employee.getSalary();
        double newSalary = currentSalary + 10;
        employee.setSalary(newSalary);
        return newSalary;
    }, predicate);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class EntryProcessorTest method testMapEntryProcessorWithPredicate.

@Test
public void testMapEntryProcessorWithPredicate() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
    nodeFactory.newHazelcastInstance(cfg);
    IMap<Integer, Employee> map = instance1.getMap(MAP_NAME);
    int size = 10;
    for (int i = 0; i < size; i++) {
        map.put(i, new Employee(i, "", 0, false, 0D, SampleTestObjects.State.STATE1));
    }
    ChangeStateEntryProcessor entryProcessor = new ChangeStateEntryProcessor();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate<Integer, Employee> predicate = entryObject.get("id").lessThan(5);
    Map<Integer, Employee> res = map.executeOnEntries(entryProcessor, predicate);
    for (int i = 0; i < 5; i++) {
        assertEquals(SampleTestObjects.State.STATE2, map.get(i).getState());
    }
    for (int i = 5; i < size; i++) {
        assertEquals(SampleTestObjects.State.STATE1, map.get(i).getState());
    }
    for (int i = 0; i < 5; i++) {
        assertEquals(res.get(i).getState(), SampleTestObjects.State.STATE2);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class MapLiteMemberTest method testMapValuesQuery.

public static void testMapValuesQuery(final IMap<Integer, Object> map) {
    map.put(1, 2);
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    PredicateBuilder predicateBuilder = entryObject.key().equal(1);
    Collection values = map.values(predicateBuilder);
    assertEquals(1, values.size());
    assertEquals(2, values.iterator().next());
}
Also used : EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Collection(java.util.Collection)

Aggregations

EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)24 Test (org.junit.Test)18 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Predicate (com.hazelcast.query.Predicate)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Employee (com.hazelcast.query.SampleTestObjects.Employee)7 Config (com.hazelcast.config.Config)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 MapConfig (com.hazelcast.config.MapConfig)4 EvictionConfig (com.hazelcast.config.EvictionConfig)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 IMap (com.hazelcast.map.IMap)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1 EntryView (com.hazelcast.core.EntryView)1