use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testMultipleOrPredicatesIssue885WithDoubleIndex.
@Test(timeout = 1000 * 60)
public void testMultipleOrPredicatesIssue885WithDoubleIndex() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
factory.newHazelcastInstance(new Config());
IMap<Integer, Employee> map = instance.getMap("default");
map.addIndex("name", true);
map.addIndex("city", true);
testMultipleOrPredicates(map);
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testMultipleOrPredicates.
private void testMultipleOrPredicates(IMap<Integer, Employee> map) {
for (int i = 0; i < 10; i++) {
map.put(i, new Employee(i, "name" + i, "city" + i, i, true, i));
}
Collection<Employee> values;
values = map.values(new SqlPredicate("name = 'name1' OR name = 'name2' OR name LIKE 'name3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR name LIKE 'name3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR name == 'name3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name LIKE '%name1' OR name LIKE 'name2%' OR name LIKE '%name3%'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name == 'name1' OR name == 'name2' OR name = 'name3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name = 'name1' OR name = 'name2' OR city LIKE 'city3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR city LIKE 'city3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name = 'name1' OR name LIKE 'name2%' OR city == 'city3'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name LIKE '%name1' OR name LIKE 'name2%' OR city LIKE '%city3%'"));
assertEquals(3, values.size());
values = map.values(new SqlPredicate("name == 'name1' OR name == 'name2' OR city = 'city3'"));
assertEquals(3, values.size());
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.
@Test(timeout = 1000 * 60)
public void testWithDashInTheNameAndSqlPredicate() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employee");
Employee toto = new Employee("toto", 23, true, 165765.0);
map.put("1", toto);
Employee toto2 = new Employee("toto-super+hero", 23, true, 165765.0);
map.put("2", toto2);
// works well
Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("name='toto-super+hero'"));
assertTrue(entries.size() > 0);
for (Map.Entry<String, Employee> entry : entries) {
Employee e = entry.getValue();
assertEquals(e, toto2);
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class MapStoreTest method testIssue1115EnablingMapstoreMutatingValue.
@Test(timeout = 120000)
public void testIssue1115EnablingMapstoreMutatingValue() throws InterruptedException {
Config config = getConfig();
String mapName = "testIssue1115";
MapStore mapStore = new ProcessingStore();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(mapStore);
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap(mapName);
Random random = new Random();
// testing put with new object
for (int i = 0; i < 10; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with existing object
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.put(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with replace
for (int i = 0; i < 10; i++) {
Employee emp = map.get(i);
emp.setAge(random.nextInt(20) + 20);
map.replace(i, emp);
}
for (int i = 0; i < 10; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
// testing put with putIfAbsent
for (int i = 10; i < 20; i++) {
Employee emp = new Employee();
emp.setAge(random.nextInt(20) + 20);
map.putIfAbsent(i, emp);
}
for (int i = 10; i < 20; i++) {
Employee employee = map.get(i);
assertEquals(employee.getAge() * 1000, employee.getSalary(), 0);
}
}
use of com.hazelcast.query.SampleObjects.Employee in project hazelcast by hazelcast.
the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.
@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap map = node.getMap(mapName);
final Employee emp = new Employee("name", 77, true, 10D);
map.put(1, emp);
node.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
txMap.remove(1);
Collection<Object> coll = txMap.values(new SqlPredicate("age > 70 "));
assertEquals(0, coll.size());
return true;
}
});
node.shutdown();
}
Aggregations