use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown.
@Test
public void testTwoMembersWithIndexesAndShutdown() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance1.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalQueryTest(map);
assertEquals(101, map.size());
instance2.getLifecycleService().shutdown();
assertEquals(101, map.size());
Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("active and age=23"));
assertEquals(2, entries.size());
for (Map.Entry<String, Employee> entry : entries) {
Employee employee = entry.getValue();
assertEquals(employee.getAge(), 23);
assertTrue(employee.isActive());
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryAfterInitialLoad.
// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
final int size = 100;
String name = "default";
Config config = getConfig();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {
@Override
public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
Map<Integer, Employee> map = new HashMap<>();
for (Integer key : keys) {
Employee emp = new Employee();
emp.setActive(true);
map.put(key, emp);
}
return map;
}
@Override
public Set<Integer> loadAllKeys() {
Set<Integer> set = new HashSet<>();
for (int i = 0; i < size; i++) {
set.add(i);
}
return set;
}
});
config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap(name);
assertTrueEventually(() -> {
Collection values = map.values(Predicates.sql("active = true"));
assertEquals(size, values.size());
});
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.
@Test(timeout = 1000 * 90)
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(Predicates.sql("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.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryNullIndexingTest method queryIndexedDateFieldAsNullValue.
private List<Long> queryIndexedDateFieldAsNullValue(boolean ordered, Predicate<Integer, SampleTestObjects.Employee> pred) {
Config config = getConfig();
config.setProperty(ClusterProperty.INDEX_COPY_BEHAVIOR.getName(), copyBehavior.name());
config.setProperty(QueryEngineImpl.DISABLE_MIGRATION_FALLBACK.getName(), "true");
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, SampleTestObjects.Employee> map = instance.getMap("default");
map.addIndex(ordered ? IndexType.SORTED : IndexType.HASH, "date");
for (int i = 10; i >= 1; i--) {
Employee employee = new Employee(i, "name-" + i, i, true, i * 100);
if (i % 2 == 0) {
employee.setDate(new Timestamp(i * 1000000));
} else {
employee.setDate(null);
}
map.put(i, employee);
}
List<Long> dates = new ArrayList<Long>();
for (SampleTestObjects.Employee employee : map.values(pred)) {
Timestamp date = employee.getDate();
dates.add(date == null ? null : date.getTime());
}
return dates;
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class SqlPredicateTest method testSql_withString.
@Test
public void testSql_withString() {
Employee value = createValue();
Employee nullNameValue = new Employee(null, 34, true, 10D);
assertSqlNotMatching("name = 'null'", nullNameValue);
assertSqlMatching("name = null", nullNameValue);
assertSqlMatching("name = NULL", nullNameValue);
assertSqlMatching("name != null", value);
assertSqlMatching("name != NULL", value);
assertSqlMatching("name <> null", value);
assertSqlMatching("name <> NULL", value);
assertSqlMatching(" (name LIKE 'abc-%') AND (age <= " + 40 + ")", value);
assertSqlMatching(" (name REGEX 'abc-.*') AND (age <= " + 40 + ")", value);
assertSqlMatching("name='abc-123-xvz'", value);
assertSqlMatching("name='abc 123-xvz'", createValue("abc 123-xvz"));
assertSqlMatching("name='abc 123-xvz+(123)'", createValue("abc 123-xvz+(123)"));
assertSqlNotMatching("name='abc 123-xvz+(123)'", createValue("abc123-xvz+(123)"));
assertSqlMatching("name LIKE 'abc-%'", createValue("abc-123"));
assertSqlMatching("name REGEX '^\\w{3}-\\d{3}-\\w{3}$'", value);
assertSqlNotMatching("name REGEX '^[^\\w]{3}-\\d{3}-\\w{3}$'", value);
assertSqlMatching(" (name ILIKE 'ABC-%') AND (age <= " + 40 + ")", value);
}
Aggregations