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());
}
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();
}
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());
}
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);
}
}
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());
}
Aggregations