use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testLikePredicate_withAndWithoutIndexOnMap.
@Test
public void testLikePredicate_withAndWithoutIndexOnMap() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
factory.newHazelcastInstance(getConfig());
IMap<Integer, Employee> withIndex = instance.getMap("withIndex");
withIndex.addIndex(IndexType.SORTED, "name");
IMap<Integer, Employee> withoutIndex = instance.getMap("withoutIndex");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int employeeId = i * 3 + j;
String employeeName = String.format("name%d%d", i, j);
Employee employee = new Employee(employeeId, employeeName, "city" + i + j, employeeId, true, employeeId);
withIndex.put(employeeId, employee);
withoutIndex.put(employeeId, employee);
}
}
assertEquals(withIndex.size(), 9);
assertEquals(withoutIndex.size(), 9);
Predicate<Integer, Employee> predicate = Predicates.like("name", "name1%");
Collection<Employee> namesByIndex = withIndex.values(predicate);
Collection<Employee> namesMapLookup = withoutIndex.values(predicate);
assertEquals(namesMapLookup.size(), 3);
assertEquals(namesByIndex.size(), 3);
assertEquals(namesMapLookup, namesByIndex);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testOneMemberWithoutIndex.
@Test
public void testOneMemberWithoutIndex() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employees");
QueryBasicTest.doFunctionalQueryTest(map);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoNodesWithPartialIndexes.
@Test
public void testTwoNodesWithPartialIndexes() {
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");
for (int i = 0; i < 500; i++) {
Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), i);
map.put(String.valueOf(i), employee);
}
assertClusterSize(2, instance1, instance2);
map = instance2.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
Collection<Employee> entries = map.values(Predicates.sql("name='name3' and city='city3' and age > 2"));
assertEquals(5, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
}
entries = map.values(Predicates.sql("name LIKE '%name3' and city like '%city3' and age > 2"));
assertEquals(5, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
assertTrue(employee.getAge() > 2);
}
entries = map.values(Predicates.sql("name LIKE '%name3%' and city like '%city30%'"));
assertEquals(5, entries.size());
for (Employee employee : entries) {
assertTrue(employee.getName().startsWith("name3"));
assertTrue(employee.getCity().startsWith("city3"));
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testOneMemberSQLWithoutIndex.
@Test
public void testOneMemberSQLWithoutIndex() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employees");
QueryBasicTest.doFunctionalSQLQueryTest(map);
Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("active and age>23"));
assertEquals(27, entries.size());
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown2.
@Test
public void testTwoMembersWithIndexesAndShutdown2() {
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());
instance1.getLifecycleService().shutdown();
map = instance2.getMap("employees");
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());
}
}
Aggregations