use of com.hazelcast.query.PredicateBuilder 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 = new PredicateBuilder().getEntryObject();
PredicateBuilder predicateBuilder = entryObject.key().equal(1);
Collection values = map.values(predicateBuilder);
assertEquals(1, values.size());
assertEquals(2, values.iterator().next());
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method issue393.
@Test(timeout = 1000 * 60)
public void issue393() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("name", true);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = new PredicateBuilder().getEntryObject().get("name").in("name0", "name2");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0", "name2" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.PredicateBuilder in project hazelcast by hazelcast.
the class QueryBasicTest method testPredicateDateAttribute.
private void testPredicateDateAttribute(IMap<Integer, Date> map) {
Calendar cal = Calendar.getInstance();
cal.set(2012, Calendar.JUNE, 5);
map.put(1, cal.getTime());
cal.set(2011, Calendar.NOVEMBER, 10);
map.put(2, cal.getTime());
cal.set(2011, Calendar.FEBRUARY, 1);
map.put(3, cal.getTime());
cal.set(2010, Calendar.SEPTEMBER, 5);
map.put(4, cal.getTime());
cal.set(2000, Calendar.JUNE, 5);
map.put(5, cal.getTime());
cal.set(2011, Calendar.JANUARY, 1);
assertEquals(3, map.values(new PredicateBuilder().getEntryObject().get("this").greaterThan(cal.getTime())).size());
assertEquals(3, map.values(new SqlPredicate("this > 'Sat Jan 01 11:43:05 EET 2011'")).size());
assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").lessThan(cal.getTime())).size());
assertEquals(2, map.values(new SqlPredicate("this < 'Sat Jan 01 11:43:05 EET 2011'")).size());
cal.set(2003, Calendar.NOVEMBER, 10);
Date d1 = cal.getTime();
cal.set(2012, Calendar.FEBRUARY, 10);
Date d2 = cal.getTime();
assertEquals(3, map.values(new PredicateBuilder().getEntryObject().get("this").between(d1, d2)).size());
assertEquals(3, map.values(new SqlPredicate("this between 'Mon Nov 10 11:43:05 EET 2003'" + " and 'Fri Feb 10 11:43:05 EET 2012'")).size());
}
use of com.hazelcast.query.PredicateBuilder 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 = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("salary").equal(0);
map.executeOnEntries(new AbstractEntryProcessor<Integer, Employee>() {
@Override
public Object process(Map.Entry<Integer, Employee> 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 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 = new PredicateBuilder().getEntryObject();
Predicate<String, Integer> p = e.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();
}
Aggregations